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: disable espower by default #196

Merged
merged 3 commits into from
Dec 18, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
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.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
21 changes: 7 additions & 14 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,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%/)
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