Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support cjs and esm both by tshy #1

Merged
merged 2 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions .editorconfig

This file was deleted.

26 changes: 4 additions & 22 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
{
"extends": "airbnb-base/legacy",
"env": {
"node": true,
"mocha": true
},
"parserOptions": {
"ecmaVersion": 6
},
"rules": {
// disabled - disagree with airbnb
"func-names": [0],
"space-before-function-paren": [0],
"consistent-return": [0],

// Disabled but may want to refactor code eventually
"no-use-before-define": [2, "nofunc"],
"no-underscore-dangle": [0],

// IMHO, more sensible overrides to existing airbnb error definitions
"max-len": [2, 100, 4, {"ignoreComments": true, "ignoreUrls": true}],
"no-unused-expressions": [2, { "allowShortCircuit": true, "allowTernary": true }]
}
"extends": [
"eslint-config-egg/typescript",
"eslint-config-egg/lib/rules/enforce-node-prefix"
]
Comment on lines +2 to +5
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Documentation needed for ESLint configuration and TypeScript coding standards

The repository lacks documentation about linting rules and TypeScript coding standards. The evidence shows:

  • Only a brief mention of TypeScript in README.md
  • No CONTRIBUTING.md or other development guide files
  • Active ESLint configuration and TypeScript tooling in package.json
  • Complex ESLint setup with multiple rule sets being used

Consider adding:

  • A CONTRIBUTING.md file explaining the linting setup
  • Documentation about the eslint-config-egg/typescript and enforce-node-prefix rule sets
  • Instructions for running the lint command (npm run lint)
  • TypeScript coding conventions specific to this project
🔗 Analysis chain

Consider documenting the linting rules for contributors.

Since we're transitioning to a new ESLint configuration, it would be helpful to document the key linting rules and expectations in the project's contributing guidelines.

Let's check if documentation exists:


Let me check if there are any other potential documentation files or development guides in the repository.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for existing documentation about linting rules

# Check common documentation locations
echo "Checking for linting documentation..."
for file in README.md CONTRIBUTING.md docs/CONTRIBUTING.md docs/development.md; do
    if [ -f "$file" ]; then
        echo "Checking $file..."
        rg -i "lint|eslint|typescript|coding.?style" "$file"
    fi
done

Length of output: 670


Script:

#!/bin/bash
# Search for any documentation files in the repository
echo "Searching for documentation files..."
fd -e md -e txt --exec echo "Found: {}"

# Check package.json for any lint-related scripts or dependencies
echo -e "\nChecking package.json for lint configurations..."
if [ -f "package.json" ]; then
    jq '.scripts, .devDependencies' package.json
fi

Length of output: 1116

}
35 changes: 0 additions & 35 deletions .github/workflows/node.js.yml

This file was deleted.

16 changes: 16 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
Job:
name: Node.js
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
version: '18.19.0, 18, 20, 22, 23'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
23 changes: 23 additions & 0 deletions .github/workflows/pkg.pr.new.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Publish Any Commit
on: [push, pull_request]
fengmk2 marked this conversation as resolved.
Show resolved Hide resolved

jobs:
build:
runs-on: ubuntu-latest
fengmk2 marked this conversation as resolved.
Show resolved Hide resolved

steps:
- name: Checkout code
uses: actions/checkout@v4

- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
run: npm install

- name: Build
run: npm run prepublishOnly --if-present

- run: npx pkg-pr-new publish
13 changes: 13 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Release

on:
push:
branches: [ master ]
fengmk2 marked this conversation as resolved.
Show resolved Hide resolved

jobs:
release:
name: Node.js
uses: eggjs/github-actions/.github/workflows/node-release.yml@master
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
fengmk2 marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ coverage
# Files #
###################
*.log
.tshy*
.eslintcache
dist
coverage
8 changes: 0 additions & 8 deletions .npmignore

This file was deleted.

1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(The MIT License)

Copyright (c) 2014 TJ Holowaychuk <[email protected]>
Copyright (c) 2024-present eggjs and the contributors.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
59 changes: 34 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
# [SuperTest](https://ladjs.github.io/superagent/)
# @eggjs/supertest

[![NPM version][npm-image]][npm-url]
[![code coverage][coverage-badge]][coverage]
[![Build Status][travis-badge]][travis]
[![Dependencies][dependencies-badge]][dependencies]
[![PRs Welcome][prs-badge]][prs]
[![Node.js CI](https://github.com/eggjs/supertest/actions/workflows/nodejs.yml/badge.svg)](https://github.com/eggjs/supertest/actions/workflows/nodejs.yml)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)
[![MIT License][license-badge]][license]
[![npm download][download-image]][download-url]
[![Node.js Version](https://img.shields.io/node/v/@eggjs/mock.svg?style=flat)](https://nodejs.org/en/download/)

[npm-image]: https://img.shields.io/npm/v/@eggjs/supertest.svg?style=flat-square
[npm-url]: https://npmjs.org/package/@eggjs/supertest
[coverage-badge]: https://img.shields.io/codecov/c/github/eggjs/supertest.svg
[coverage]: https://codecov.io/gh/eggjs/supertest
[license-badge]: https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square
[license]: https://github.com/eggjs/supertest/blob/master/LICENSE
[download-image]: https://img.shields.io/npm/dm/@eggjs/supertest.svg?style=flat-square
[download-url]: https://npmjs.org/package/@eggjs/supertest

> HTTP assertions made easy via [superagent](http://github.com/ladjs/superagent). Maintained for [Forward Email](https://github.com/forwardemail) and [Lad](https://github.com/ladjs).
> Forked for TypeScript friendly

Comment on lines 20 to +21
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Document TypeScript and dual module format support

While the "Forked for TypeScript friendly" note is present, consider adding more detailed information about:

  • TypeScript support
  • Dual module format (CJS/ESM) support
  • Breaking changes regarding Node.js version

Add a new section about TypeScript and module format support:

> Forked for TypeScript friendly
+
+## TypeScript & Module Format Support
+
+This fork provides:
+- Full TypeScript support with type definitions
+- Dual module format support (CommonJS and ESM)
+- Requires Node.js >= 18.19.0
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
> HTTP assertions made easy via [superagent](http://github.com/ladjs/superagent). Maintained for [Forward Email](https://github.com/forwardemail) and [Lad](https://github.com/ladjs).
> Forked for TypeScript friendly
> HTTP assertions made easy via [superagent](http://github.com/ladjs/superagent). Maintained for [Forward Email](https://github.com/forwardemail) and [Lad](https://github.com/ladjs).
> Forked for TypeScript friendly
## TypeScript & Module Format Support
This fork provides:
- Full TypeScript support with type definitions
- Dual module format support (CommonJS and ESM)
- Requires Node.js >= 18.19.0

Document see [SuperTest](https://ladjs.github.io/superagent/)

## About

Expand All @@ -18,7 +32,7 @@ HTTP, while still allowing you to drop down to the [lower-level API](https://lad
Install SuperTest as an npm module and save it to your package.json file as a development dependency:

```bash
npm install supertest --save-dev
npm install @eggjs/supertest --save-dev
```

Once installed it can now be referenced by simply calling ```require('supertest');```
Expand All @@ -33,7 +47,7 @@ SuperTest works with any test framework, here is an example without using any
test framework at all:

```js
const request = require('supertest');
const { request } = require('@eggjs/supertest');
const express = require('express');

const app = express();
Expand All @@ -55,7 +69,7 @@ request(app)
To enable http2 protocol, simply append an options to `request` or `request.agent`:

```js
const request = require('supertest');
const { request } = require('@eggjs/supertest');
const express = require('express');

const app = express();
Expand Down Expand Up @@ -207,21 +221,21 @@ the same host you may simply re-assign the request variable with the
initialization app or url, a new `Test` is created per `request.VERB()` call.

```js
request = request('http://localhost:5555');
t = request('http://localhost:5555');

request.get('/').expect(200, function(err){
t.get('/').expect(200, function(err){
console.log(err);
});

request.get('/').expect('heya', function(err){
t.get('/').expect('heya', function(err){
console.log(err);
});
```

Here's an example with mocha that shows how to persist a request and its cookies:

```js
const request = require('supertest');
const { agent } = require('@eggjs/supertest');
const should = require('should');
const express = require('express');
const cookieParser = require('cookie-parser');
Expand All @@ -240,16 +254,16 @@ describe('request.agent(app)', function() {
else res.send(':(')
});

const agent = request.agent(app);
const testAgent = agent(app);

it('should save cookies', function(done) {
agent
testAgent
.get('/')
.expect('set-cookie', 'cookie=hey; Path=/', done);
});

it('should send cookies', function(done) {
agent
testAgent
.get('/return')
.expect('hey', done);
});
Expand Down Expand Up @@ -324,15 +338,10 @@ Inspired by [api-easy](https://github.com/flatiron/api-easy) minus vows coupling

## License

MIT
[MIT](LICENSE)

[coverage-badge]: https://img.shields.io/codecov/c/github/ladjs/supertest.svg
[coverage]: https://codecov.io/gh/ladjs/supertest
[travis-badge]: https://travis-ci.org/ladjs/supertest.svg?branch=master
[travis]: https://travis-ci.org/ladjs/supertest
[dependencies-badge]: https://david-dm.org/ladjs/supertest/status.svg
[dependencies]: https://david-dm.org/ladjs/supertest
[prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square
[prs]: http://makeapullrequest.com
[license-badge]: https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square
[license]: https://github.com/ladjs/supertest/blob/master/LICENSE
## Contributors

[![Contributors](https://contrib.rocks/image?repo=eggjs/supertest)](https://github.com/eggjs/supertest/graphs/contributors)

Made with [contributors-img](https://contrib.rocks).
22 changes: 0 additions & 22 deletions ci/remove-deps-4-old-node.js

This file was deleted.

65 changes: 0 additions & 65 deletions index.js

This file was deleted.

Loading
Loading