Skip to content

Commit

Permalink
feat: support cjs and esm both by tshy (#1)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: drop Node.js < 18.19.0 support

part of eggjs/egg#3644

eggjs/egg#5257

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Introduced a new `TestAgent` class for enhanced HTTP and HTTP/2
requests.
	- Added a new `Request` class to facilitate server requests.
	- Implemented a new `AssertError` class for improved error handling.
	- Created new GitHub Actions workflows for CI and package publishing.

- **Documentation**
- Updated the `README.md` to reflect rebranding to `@eggjs/supertest`
and revised installation instructions.

- **Bug Fixes**
	- Enhanced error handling and type safety in tests.

- **Chores**
	- Removed outdated configuration files and unnecessary dependencies.
	- Updated TypeScript configuration for stricter type checking.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
fengmk2 authored Dec 21, 2024
1 parent 2ae1c36 commit 09fb755
Show file tree
Hide file tree
Showing 24 changed files with 834 additions and 823 deletions.
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"
]
}
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]

jobs:
build:
runs-on: ubuntu-latest

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 ]

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 }}
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
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

0 comments on commit 09fb755

Please sign in to comment.