diff --git a/.autod.conf b/.autod.conf deleted file mode 100644 index 1f79c8c6..00000000 --- a/.autod.conf +++ /dev/null @@ -1,26 +0,0 @@ -'ues strict'; - -module.exports = { - write: true, - prefix: '^', - devprefix: '^', - exclude: [ - 'test/fixtures', - ], - dep: [ - 'mocha', - 'intelli-espower-loader', - 'power-assert', - 'espower-typescript', - 'ypkgfiles', - ], - devdep: [ - 'egg', - 'autod', - 'eslint-config-egg', - ], - keep: [ - ], - semver: [ - ], -}; diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 3eb06691..594d1fe3 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -2,13 +2,10 @@ name: CI on: push: - branches: [ master, main ] + branches: [ master, 5.x ] pull_request: - branches: [ master, main, next, beta, '*.x' ] - - schedule: - - cron: '0 2 * * *' + branches: [ master, 5.x ] workflow_dispatch: {} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 25f22d79..1be0e55c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,10 +1,8 @@ name: Release on: - # 合并后自动发布 push: - branches: [ master ] + branches: [ master, 5.x ] - # 手动发布 workflow_dispatch: {} jobs: @@ -16,4 +14,3 @@ jobs: GIT_TOKEN: ${{ secrets.GIT_TOKEN }} with: checkTest: false - # dryRun: true diff --git a/README.md b/README.md index eb97d158..750f9515 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ Start dev cluster on `local` env, it will start a master, an agent and a worker. egg-bin dev ``` -##### options +#### dev options - `--framework` egg web framework root path. - `--baseDir` application's root path, default to `process.cwd()`. @@ -93,7 +93,7 @@ if running without `VSCode` or `WebStorm`, we will use [inspector-proxy](https:/ egg-bin debug --debug-port=9229 --proxy=9999 ``` -##### options +#### debug options - all `egg-bin dev` options is accepted. - `--proxy=9999` worker debug proxy port. @@ -102,8 +102,6 @@ egg-bin debug --debug-port=9229 --proxy=9999 Using [mocha] to run test. -[power-assert] is the default `assert` library, and [intelli-espower-loader] will be auto required. - ```bash egg-bin test [files] [options] ``` @@ -121,7 +119,7 @@ test └── foo.test.js ``` -#### options +#### test options You can pass any mocha argv. @@ -132,14 +130,13 @@ You can pass any mocha argv. - `--typescript` / `--ts` enable typescript support, default to `false`. - `--changed` / `-c` only test changed test files(test files means files that match `${pwd}/test/**/*.test.(js|ts)`) - `--dry-run` / `-d` whether dry-run the test command, just show the command -- `--espower` / `-e` whether auto require intelli-espower-loader(js) or espower-typescript(ts) for power-assert, default to `false`. - `--parallel` enable mocha parallel mode, default to `false`. - `--auto-agent` auto start agent in mocha master agent. - `--jobs` number of jobs to run in parallel, default to `os.cpus().length - 1`. - `--mochawesome` enable [mochawesome](https://github.com/adamgruber/mochawesome) reporter, default to `false`. - see more at -#### environment +#### test environment Environment is also support, will use it if options not provide. @@ -165,8 +162,6 @@ TEST_TIMEOUT=2000 egg-bin test Using [node:test] to run test. -[power-assert] is the default `assert` library, and [intelli-espower-loader] will be auto required. - ```bash egg-bin node-test [files] [options] ``` @@ -180,7 +175,7 @@ egg-bin node-test [files] [options] TBD: TypeScript not support yet -#### environment +#### node-test environment Environment is also support, will use it if options not provide. @@ -371,9 +366,6 @@ This project follows the git-contributor [spec](https://github.com/xudafeng/git- [node:test]: https://nodejs.org/api/test.html [glob]: https://github.com/isaacs/node-glob [nsp]: https://npmjs.com/nsp -[iron-node]: https://github.com/s-a/iron-node -[intelli-espower-loader]: https://github.com/power-assert-js/intelli-espower-loader -[power-assert]: https://github.com/power-assert-js/power-assert [ypkgfiles]: https://github.com/popomore/ypkgfiles [common-bin]: https://github.com/node-modules/common-bin [autod]: https://github.com/node-modules/autod diff --git a/lib/cmd/test.js b/lib/cmd/test.js index 73f63668..cca13fa2 100644 --- a/lib/cmd/test.js +++ b/lib/cmd/test.js @@ -39,12 +39,6 @@ class TestCommand extends Command { description: 'whether show test command, no test will be executed', alias: 'd', }, - espower: { - type: 'boolean', - description: 'whether require intelli-espower-loader(js) or espower-typescript(ts) for power-assert', - default: false, - alias: 'e', - }, parallel: { type: 'boolean', description: 'mocha parallel mode', @@ -106,10 +100,11 @@ class TestCommand extends Command { * @param {Object} context - { cwd, argv, ...} * @param {Object} context.argv test arguments * @param {Object} context.debugOptions debug options + * @param {Object} context.execArgvObj exec argv object * @return {Array} [ '--require=xxx', 'xx.test.js' ] * @protected */ - async formatTestArgs({ argv, debugOptions }) { + async formatTestArgs({ argv, debugOptions, execArgvObj }) { const testArgv = Object.assign({}, argv); /* istanbul ignore next */ @@ -127,24 +122,11 @@ class TestCommand extends Command { } // collect require - let requireArr = testArgv.require || testArgv.r || []; - /* istanbul ignore next */ - if (!Array.isArray(requireArr)) requireArr = [ requireArr ]; + const requireArr = execArgvObj.require; // clean mocha stack, inspired by https://github.com/rstacruz/mocha-clean // [mocha built-in](https://github.com/mochajs/mocha/blob/master/lib/utils.js#L738) don't work with `[npminstall](https://github.com/cnpm/npminstall)`, so we will override it. if (!testArgv.fullTrace) requireArr.unshift(require.resolve('../mocha-clean')); - - if (requireArr.includes('intelli-espower-loader')) { - console.warn('[egg-bin] don\'t need to manually require `intelli-espower-loader` anymore'); - } else if (testArgv.espower) { - if (testArgv.typescript) { - // espower-typescript must append after ts-node - requireArr.push(testArgv.tscompiler, require.resolve('../espower-typescript')); - } else { - requireArr.push(require.resolve('intelli-espower-loader')); - } - } if (testArgv.parallel && testArgv['auto-agent']) { try { requireArr.push(require.resolve('egg-mock/lib/parallel/agent_register')); diff --git a/lib/espower-typescript.js b/lib/espower-typescript.js deleted file mode 100644 index 5515e622..00000000 --- a/lib/espower-typescript.js +++ /dev/null @@ -1,41 +0,0 @@ -'use strict'; - -const path = require('path'); -const espowerSource = require('espower-source'); -const minimatch = require('minimatch'); -const sourceMapSupport = require('source-map-support'); -const sourceCache = {}; -const cwd = process.cwd(); - -espowerTypeScript({ - pattern: path.resolve(cwd, 'test/**/*.@(js|jsx|ts|tsx)'), - extensions: [ 'js', 'jsx', 'ts', 'tsx' ], -}); - -function espowerTypeScript(options) { - // install source-map-support again to correct the source-map - sourceMapSupport.install({ - environment: 'node', - retrieveFile: p => sourceCache[p], - }); - - options.extensions.forEach(ext => { - espowerTsRegister(`.${ext}`, options); - }); -} - -function espowerTsRegister(ext, options) { - const originalExtension = require.extensions[ext]; - require.extensions[ext] = (module, filepath) => { - if (!minimatch(filepath, options.pattern)) { - return originalExtension(module, filepath); - } - const originalCompile = module._compile; - module._compile = function(code, filepath) { - const newSource = espowerSource(code, filepath, options); - sourceCache[filepath] = newSource; - return originalCompile.call(this, newSource, filepath); - }; - return originalExtension(module, filepath); - }; -} diff --git a/lib/mocha-clean.js b/lib/mocha-clean.js index e83a4df4..4a9f77a3 100644 --- a/lib/mocha-clean.js +++ b/lib/mocha-clean.js @@ -15,7 +15,6 @@ const internal = [ 'at Promise ()', 'at next (native)', '__mocha_internal__', - /node_modules\/.*empower-core\//, /node_modules\/.*mocha\//, /node_modules\/.*co\//, /node_modules\/.*supertest\//, diff --git a/package.json b/package.json index cac9b058..66ee1ef4 100644 --- a/package.json +++ b/package.json @@ -23,16 +23,12 @@ "detect-port": "^1.3.0", "egg-ts-helper": "^1.30.3", "egg-utils": "^2.4.1", - "espower-source": "^2.3.0", - "espower-typescript": "^10.0.0", "globby": "^11.1.0", "inspector-proxy": "^1.2.2", - "intelli-espower-loader": "^1.1.0", "jest-changed-files": "^28.0.2", "minimatch": "^5.1.0", "mocha": "^10.0.0", "mochawesome": "^7.1.3", - "power-assert": "^1.6.1", "semver": "^7.3.7", "source-map-support": "^0.5.21", "test": "^3.0.0", @@ -56,7 +52,7 @@ "coffee": "^5.4.0", "cpy": "^8.1.2", "cross-env": "^3.1.3", - "egg": "^2.35.0", + "egg": "^3.9.1", "egg-mock": "^5.0.2", "enzyme": "^2.0.0", "esbuild-register": "^2.5.0", @@ -89,8 +85,7 @@ "test-mochawesome": "npm run test-local -- --mochawesome", "cov": "c8 -r lcov -r text-summary npm run test-local", "ci-test-only": "npm run test-local -- test/lib/cmd/cov.test.js", - "ci": "npm run lint && npm run pkgfiles -- --check && npm run ci-test-only && npm run test-local", - "autod": "node bin/egg-bin.js autod" + "ci": "npm run lint && npm run pkgfiles -- --check && npm run ci-test-only && npm run test-local" }, "engines": { "node": ">= 14.0.0" diff --git a/test/fixtures/example-ts/tsconfig.json b/test/fixtures/example-ts/tsconfig.json index 4f10abf7..18023ce2 100644 --- a/test/fixtures/example-ts/tsconfig.json +++ b/test/fixtures/example-ts/tsconfig.json @@ -1,19 +1,9 @@ { + "extends": "@eggjs/tsconfig", "compilerOptions": { - "target": "es2017", - "module": "commonjs", - "strict": true, - "noImplicitAny": false, - "moduleResolution": "node", - "experimentalDecorators": true, - "emitDecoratorMetadata": true, - "pretty": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true, - "skipLibCheck": true, - "skipDefaultLibCheck": true, - "inlineSourceMap": true, - "importHelpers": true - }, -} \ No newline at end of file + "declaration": false, + "resolveJsonModule": true, + "baseUrl": ".", + "useUnknownInCatchVariables": false + } +} diff --git a/test/fixtures/test-files-c8-report-only/test/power-assert-fail.js b/test/fixtures/test-files-c8-report-only/test/power-assert-fail.js deleted file mode 100644 index 6dfccb32..00000000 --- a/test/fixtures/test-files-c8-report-only/test/power-assert-fail.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; - -const assert = require('power-assert'); - -describe('power-assert-fail.js', () => { - it('should fail', () => { - assert(1 === 2); - }); -}); diff --git a/test/fixtures/test-files-c8/test/power-assert-fail.js b/test/fixtures/test-files-c8/test/power-assert-fail.js deleted file mode 100644 index 6dfccb32..00000000 --- a/test/fixtures/test-files-c8/test/power-assert-fail.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; - -const assert = require('power-assert'); - -describe('power-assert-fail.js', () => { - it('should fail', () => { - assert(1 === 2); - }); -}); diff --git a/test/fixtures/test-files/test/power-assert-fail.js b/test/fixtures/test-files/test/power-assert-fail.js deleted file mode 100644 index 6dfccb32..00000000 --- a/test/fixtures/test-files/test/power-assert-fail.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; - -const assert = require('power-assert'); - -describe('power-assert-fail.js', () => { - it('should fail', () => { - assert(1 === 2); - }); -}); diff --git a/test/lib/cmd/cov-c8-report.test.js b/test/lib/cmd/cov-c8-report.test.js index da6ac65a..bfce8cf0 100644 --- a/test/lib/cmd/cov-c8-report.test.js +++ b/test/lib/cmd/cov-c8-report.test.js @@ -114,29 +114,6 @@ describe('test/lib/cmd/cov-c8-report.test.js', () => { .end(); }); - it('should fail when test fail with power-assert', () => { - mm(process.env, 'TESTS', 'test/power-assert-fail.js'); - return coffee.fork(eggBin, [ 'cov', '--c8-report=true', '--espower=true' ], { cwd }) - // .debug() - .expect('stdout', /1\) should fail/) - .expect('stdout', /1 failing/) - .expect('stdout', /assert\(1 === 2\)/) - .expect('code', 1) - .end(); - }); - - it('should warn when require intelli-espower-loader', () => { - mm(process.env, 'TESTS', 'test/power-assert-fail.js'); - return coffee.fork(eggBin, [ 'cov', '--c8-report=true', '-r', 'intelli-espower-loader' ], { cwd }) - // .debug() - .expect('stderr', /manually require `intelli-espower-loader`/) - .expect('stdout', /1\) should fail/) - .expect('stdout', /1 failing/) - .expect('stdout', /assert\(1 === 2\)/) - .expect('code', 1) - .end(); - }); - it('should run cov when no test files', () => { mm(process.env, 'TESTS', 'noexist.js'); const cwd = path.join(__dirname, '../../fixtures/prerequire'); diff --git a/test/lib/cmd/cov.test.js b/test/lib/cmd/cov.test.js index de9e5ac5..56662608 100644 --- a/test/lib/cmd/cov.test.js +++ b/test/lib/cmd/cov.test.js @@ -143,29 +143,6 @@ describe('test/lib/cmd/cov.test.js', () => { .end(); }); - it('should fail when test fail with power-assert', () => { - mm(process.env, 'TESTS', 'test/power-assert-fail.js'); - return coffee.fork(eggBin, [ 'cov', '--espower=true' ], { cwd }) - // .debug() - .expect('stdout', /1\) should fail/) - .expect('stdout', /1 failing/) - .expect('stdout', /assert\(1 === 2\)/) - .expect('code', 1) - .end(); - }); - - it('should warn when require intelli-espower-loader', () => { - mm(process.env, 'TESTS', 'test/power-assert-fail.js'); - return coffee.fork(eggBin, [ 'cov', '-r', 'intelli-espower-loader' ], { cwd }) - // .debug() - .expect('stderr', /manually require `intelli-espower-loader`/) - .expect('stdout', /1\) should fail/) - .expect('stdout', /1 failing/) - .expect('stdout', /assert\(1 === 2\)/) - .expect('code', 1) - .end(); - }); - it('should run cov when no test files', () => { mm(process.env, 'TESTS', 'noexist.js'); const cwd = path.join(__dirname, '../../fixtures/prerequire'); diff --git a/test/lib/cmd/test.test.js b/test/lib/cmd/test.test.js index 14580086..1275ce6f 100644 --- a/test/lib/cmd/test.test.js +++ b/test/lib/cmd/test.test.js @@ -107,18 +107,6 @@ describe('test/lib/cmd/test.test.js', () => { .end(done); }); - it('should fail when test fail with power-assert', done => { - mm(process.env, 'TESTS', 'test/power-assert-fail.js'); - coffee.fork(eggBin, [ 'test', '--espower=true' ], { cwd }) - // .coverage(false) - // .debug() - .expect('stdout', /1\) should fail/) - .expect('stdout', /assert\(1 === 2\)/) - .expect('stdout', /1 failing/) - .expect('code', 1) - .end(done); - }); - it('should auto require test/.setup.js', () => { // example: https://github.com/lelandrichardson/enzyme-example-mocha mm(process.env, 'TESTS', 'test/Foo.test.js'); diff --git a/test/ts.test.js b/test/ts.test.js index 884994b3..5a68f2c2 100644 --- a/test/ts.test.js +++ b/test/ts.test.js @@ -37,18 +37,13 @@ describe('test/ts.test.js', () => { }); describe('real application', () => { - if (process.env.EGG_VERSION && process.env.EGG_VERSION === '1') { - console.log('skip egg@1'); - return; - } - before(() => { cwd = path.join(__dirname, './fixtures/example-ts'); }); it('should start app', () => { return coffee.fork(eggBin, [ 'dev', '--ts' ], { cwd }) - // .debug() + .debug() .expect('stdout', /hi, egg, 12345/) .expect('stdout', /ts env: true/) .expect('stdout', /started/) @@ -57,8 +52,8 @@ describe('test/ts.test.js', () => { }); it('should test app', () => { - return coffee.fork(eggBin, [ 'test', '--ts' ], { cwd }) - // .debug() + return coffee.fork(eggBin, [ 'test' ], { cwd }) + .debug() .expect('stdout', /hi, egg, 123456/) .expect('stdout', /ts env: true/) .expect('stdout', /should work/) @@ -67,16 +62,16 @@ describe('test/ts.test.js', () => { }); it('should cov app', () => { - return coffee.fork(eggBin, [ 'cov', '--ts', '--espower=true' ], { cwd }) + return coffee.fork(eggBin, [ 'cov' ], { cwd }) .debug() .expect('stdout', /hi, egg, 123456/) .expect('stdout', /ts env: true/) - .expect('stdout', os.platform() === 'win32' ? /Coverage summary/ : /Statements.*100%/) + .expect('stdout', /should work/) .expect('code', 0) .end(); }); - it.skip('should cov app in cluster mod', () => { + it('should cov app in cluster mod', () => { // skip on darwin // https://github.com/eggjs/egg-bin/runs/6735190362?check_suite_focus=true // [agent_worker] receive disconnect event on child_process fork mode, exiting with code:110 @@ -342,11 +337,10 @@ describe('test/ts.test.js', () => { }); it('should cov app', () => { - return coffee.fork(eggBin, [ 'cov', '--espower=true' ], { cwd }) + return coffee.fork(eggBin, [ 'cov' ], { cwd }) .debug() .expect('stdout', /hi, egg, 123456/) .expect('stdout', /ts env: true/) - .expect('stdout', process.env.NYC_ROOT_ID ? /Coverage summary/ : /Statements.*100%/) .expect('code', 0) .end(); });