Skip to content

Commit

Permalink
feat: disable espower by default (#196)
Browse files Browse the repository at this point in the history
@eggjs/tsconfig compile to es2020 by default and espower-source don't support it
  • Loading branch information
fengmk2 authored Dec 18, 2022
1 parent 158d919 commit 5e35438
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 111 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion lib/cmd/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
20 changes: 2 additions & 18 deletions test/fixtures/example-ts-pkg/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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
},
}
"extends": "@eggjs/tsconfig"
}
10 changes: 8 additions & 2 deletions test/fixtures/ts/test/sub.ts
Original file line number Diff line number Diff line change
@@ -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());
}
20 changes: 2 additions & 18 deletions test/fixtures/ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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
},
}
"extends": "@eggjs/tsconfig"
}
2 changes: 1 addition & 1 deletion test/lib/cmd/cov-c8-report.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down
2 changes: 1 addition & 1 deletion test/lib/cmd/cov.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down
55 changes: 1 addition & 54 deletions test/lib/cmd/test.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand All @@ -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');
Expand Down Expand Up @@ -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/)
Expand Down
23 changes: 8 additions & 15 deletions test/ts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down Expand Up @@ -69,16 +67,16 @@ 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%/)
.expect('code', 0)
.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
Expand Down Expand Up @@ -123,23 +121,20 @@ describe('test/ts.test.js', () => {
.expect('stdout', /| {3}| {3}|/)
.expect('stdout', /| {3}| {3}false/)
.expect('stdout', /| {3}"111"/)
.expect('stdout', /Object\{key:"111"}/)
.end();
});

it('should correct error stack line number in testing app with other tscompiler', () => {
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();
});

Expand All @@ -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();
});

Expand All @@ -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();
});
});
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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%/)
Expand Down

0 comments on commit 5e35438

Please sign in to comment.