diff --git a/README.md b/README.md index 0b414965..eb97d158 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,7 @@ 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 `true`. +- `--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`. diff --git a/lib/cmd/test.js b/lib/cmd/test.js index 1c5808cc..73f63668 100644 --- a/lib/cmd/test.js +++ b/lib/cmd/test.js @@ -42,7 +42,7 @@ class TestCommand extends Command { espower: { type: 'boolean', description: 'whether require intelli-espower-loader(js) or espower-typescript(ts) for power-assert', - default: true, + default: false, alias: 'e', }, parallel: { diff --git a/package.json b/package.json index 7a0a4437..68fae633 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ } }, "devDependencies": { + "@eggjs/tsconfig": "^1.2.0", "@types/mocha": "^9.1.1", "babel": "^6.3.26", "babel-preset-airbnb": "^1.0.1", @@ -84,6 +85,7 @@ "pkgfiles": "node bin/egg-bin.js pkgfiles", "test": "npm run lint -- --fix && npm run test-local", "test-local": "node bin/egg-bin.js test -t 120000 --parallel", + "test-single": "node bin/egg-bin.js test -t 120000", "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", diff --git a/test/fixtures/example-ts-pkg/tsconfig.json b/test/fixtures/example-ts-pkg/tsconfig.json index 4f10abf7..376b9024 100644 --- a/test/fixtures/example-ts-pkg/tsconfig.json +++ b/test/fixtures/example-ts-pkg/tsconfig.json @@ -1,19 +1,3 @@ { - "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 + "extends": "@eggjs/tsconfig" +} diff --git a/test/fixtures/ts/test/sub.ts b/test/fixtures/ts/test/sub.ts index 61519692..f188cdfa 100644 --- a/test/fixtures/ts/test/sub.ts +++ b/test/fixtures/ts/test/sub.ts @@ -1,3 +1,9 @@ -'use strict'; - export default { name: 'egg from ts' }; + +function foo(bar?: string) { + return bar ?? ''; +} + +if (process.env.NOT_EXISTS) { + console.log(foo()); +} diff --git a/test/fixtures/ts/tsconfig.json b/test/fixtures/ts/tsconfig.json index 4f10abf7..376b9024 100644 --- a/test/fixtures/ts/tsconfig.json +++ b/test/fixtures/ts/tsconfig.json @@ -1,19 +1,3 @@ { - "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 + "extends": "@eggjs/tsconfig" +} diff --git a/test/lib/cmd/cov-c8-report.test.js b/test/lib/cmd/cov-c8-report.test.js index 5d0562d4..da6ac65a 100644 --- a/test/lib/cmd/cov-c8-report.test.js +++ b/test/lib/cmd/cov-c8-report.test.js @@ -116,7 +116,7 @@ describe('test/lib/cmd/cov-c8-report.test.js', () => { 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' ], { cwd }) + return coffee.fork(eggBin, [ 'cov', '--c8-report=true', '--espower=true' ], { cwd }) // .debug() .expect('stdout', /1\) should fail/) .expect('stdout', /1 failing/) diff --git a/test/lib/cmd/cov.test.js b/test/lib/cmd/cov.test.js index 682e9c98..de9e5ac5 100644 --- a/test/lib/cmd/cov.test.js +++ b/test/lib/cmd/cov.test.js @@ -145,7 +145,7 @@ describe('test/lib/cmd/cov.test.js', () => { it('should fail when test fail with power-assert', () => { mm(process.env, 'TESTS', 'test/power-assert-fail.js'); - return coffee.fork(eggBin, [ 'cov' ], { cwd }) + return coffee.fork(eggBin, [ 'cov', '--espower=true' ], { cwd }) // .debug() .expect('stdout', /1\) should fail/) .expect('stdout', /1 failing/) diff --git a/test/lib/cmd/test.test.js b/test/lib/cmd/test.test.js index 155cfc5e..14580086 100644 --- a/test/lib/cmd/test.test.js +++ b/test/lib/cmd/test.test.js @@ -109,7 +109,7 @@ describe('test/lib/cmd/test.test.js', () => { it('should fail when test fail with power-assert', done => { mm(process.env, 'TESTS', 'test/power-assert-fail.js'); - coffee.fork(eggBin, [ 'test' ], { cwd }) + coffee.fork(eggBin, [ 'test', '--espower=true' ], { cwd }) // .coverage(false) // .debug() .expect('stdout', /1\) should fail/) @@ -119,58 +119,6 @@ describe('test/lib/cmd/test.test.js', () => { .end(done); }); - describe('intelli-espower-loader', () => { - it('should warn when require intelli-espower-loader', () => { - mm(process.env, 'TESTS', 'test/power-assert-fail.js'); - return coffee.fork(eggBin, [ 'test', '-r', 'intelli-espower-loader' ], { cwd }) - // .coverage(false) - // .debug() - .expect('stderr', /manually require `intelli-espower-loader`/) - .expect('stdout', /1\) should fail/) - .expect('stdout', /assert\(1 === 2\)/) - .expect('stdout', /1 failing/) - .expect('code', 1) - .end(); - }); - - it('should default require intelli-espower-loader', () => { - mm(process.env, 'TESTS', 'test/power-assert-fail.js'); - return coffee.fork(eggBin, [ 'test', '--dry-run' ], { cwd }) - // .coverage(false) - // .debug() - .expect('stdout', /--require=.*intelli-espower-loader\.js/) - .end(); - }); - - it('should not require intelli-espower-loader with --espower=false', () => { - mm(process.env, 'TESTS', 'test/power-assert-fail.js'); - return coffee.fork(eggBin, [ 'test', '--espower=false', '--dry-run' ], { cwd }) - // .coverage(false) - // .debug() - .notExpect('stdout', /--require=.*intelli-espower-loader\.js/) - .end(); - }); - - it('should default require espower-typescript when typescript', () => { - mm(process.env, 'TESTS', 'test/power-assert-fail.js'); - return coffee.fork(eggBin, [ 'test', '--typescript', '--dry-run' ], { cwd }) - // .coverage(false) - // .debug() - .expect('stdout', /--require=.*espower-typescript\.js/) - .end(); - }); - - it('should not require ntelli-espower-loader/espower-typescript when typescript with --espower=false', () => { - mm(process.env, 'TESTS', 'test/power-assert-fail.js'); - return coffee.fork(eggBin, [ 'test', '--typescript', '--espower=false', '--dry-run' ], { cwd }) - // .coverage(false) - // .debug() - .notExpect('stdout', /--require=.*intelli-espower-loader\.js/) - .notExpect('stdout', /--require=.*espower-typescript\.js/) - .end(); - }); - }); - it('should auto require test/.setup.js', () => { // example: https://github.com/lelandrichardson/enzyme-example-mocha mm(process.env, 'TESTS', 'test/Foo.test.js'); @@ -209,7 +157,6 @@ describe('test/lib/cmd/test.test.js', () => { /--timeout=12345/, /--exit/, /--require=.*mocha-clean\.js/, - /--require=.*intelli-espower-loader\.js/, /foo\.test\.js/, ]) .notExpect('stdout', /--dry-run/) diff --git a/test/ts.test.js b/test/ts.test.js index 4ce688d5..884994b3 100644 --- a/test/ts.test.js +++ b/test/ts.test.js @@ -31,9 +31,7 @@ describe('test/ts.test.js', () => { mm(process.env, 'NODE_ENV', 'development'); return coffee.fork(eggBin, [ 'test', '--typescript' ], { cwd }) // .debug() - .notExpect('stdout', /false == true/) - .notExpect('stdout', /should not load js files/) - .expect('stdout', /--- \[string\] 'wrong assert ts'/) + .expect('stdout', /The expression evaluated to a falsy value/) .expect('code', 1) .end(); }); @@ -69,8 +67,8 @@ describe('test/ts.test.js', () => { }); it('should cov app', () => { - return coffee.fork(eggBin, [ 'cov', '--ts' ], { cwd }) - // .debug() + return coffee.fork(eggBin, [ 'cov', '--ts', '--espower=true' ], { cwd }) + .debug() .expect('stdout', /hi, egg, 123456/) .expect('stdout', /ts env: true/) .expect('stdout', os.platform() === 'win32' ? /Coverage summary/ : /Statements.*100%/) @@ -78,7 +76,7 @@ describe('test/ts.test.js', () => { .end(); }); - it('should cov app in cluster mod', () => { + it.skip('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 @@ -123,7 +121,6 @@ describe('test/ts.test.js', () => { .expect('stdout', /| {3}| {3}|/) .expect('stdout', /| {3}| {3}false/) .expect('stdout', /| {3}"111"/) - .expect('stdout', /Object\{key:"111"}/) .end(); }); @@ -131,15 +128,13 @@ describe('test/ts.test.js', () => { if (process.platform === 'win32') return; return coffee.fork(eggBin, [ 'test', '--tscompiler=esbuild-register' ], { cwd }) - // .debug() + .debug() .expect('stdout', /error/) .expect('stdout', /test[\/\\]{1}index\.test\.ts:8:11\)/) .expect('stdout', /test[\/\\]{1}index\.test\.ts:14:5\)/) - .expect('stdout', /assert\(obj\.key === "222"\)/) .expect('stdout', /| {3}| {3}|/) .expect('stdout', /| {3}| {3}false/) .expect('stdout', /| {3}"111"/) - .expect('stdout', /Object\{key:"111"}/) .end(); }); @@ -155,7 +150,6 @@ describe('test/ts.test.js', () => { .expect('stdout', /| {3}| {3}|/) .expect('stdout', /| {3}| {3}false/) .expect('stdout', /| {3}"111"/) - .expect('stdout', /Object\{key:"111"}/) .end(); }); @@ -173,7 +167,6 @@ describe('test/ts.test.js', () => { .expect('stdout', /| {3}| {3}|/) .expect('stdout', /| {3}| {3}false/) .expect('stdout', /| {3}"111"/) - .expect('stdout', /Object\{key:"111"}/) .end(); }); }); @@ -320,7 +313,7 @@ describe('test/ts.test.js', () => { it('should test app', () => { return coffee.fork(eggBin, [ 'test' ], { cwd }) - // .debug() + .debug() .expect('stdout', /hi, egg, 123456/) .expect('stdout', /ts env: true/) .expect('code', 0) @@ -349,8 +342,8 @@ describe('test/ts.test.js', () => { }); it('should cov app', () => { - return coffee.fork(eggBin, [ 'cov' ], { cwd }) - // .debug() + return coffee.fork(eggBin, [ 'cov', '--espower=true' ], { cwd }) + .debug() .expect('stdout', /hi, egg, 123456/) .expect('stdout', /ts env: true/) .expect('stdout', process.env.NYC_ROOT_ID ? /Coverage summary/ : /Statements.*100%/)