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

fix: ignore eggTsHelper on node-test #186

Merged
merged 8 commits into from Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/cmd/dev.js
@@ -1,5 +1,3 @@
'use strict';

const debug = require('debug')('egg-bin');
const Command = require('../command');
const path = require('path');
Expand All @@ -11,7 +9,7 @@ class DevCommand extends Command {
super(rawArgv);
this.usage = 'Usage: egg-bin dev [dir] [options]';

this.defaultPort = 7001;
this.defaultPort = process.env.EGG_BIN_DEFAULT_PORT || 7001;
this.serverBin = path.join(__dirname, '../start-cluster');

this.options = {
Expand Down
1 change: 0 additions & 1 deletion lib/cmd/node-test-cov.js
Expand Up @@ -113,7 +113,6 @@ class NodeTestCovCommand extends NodeTestCommand {
if (passthroughArgs) {
covArgs = covArgs.concat(passthroughArgs.split(' '));
}
console.log(this[EXCLUDES]);
for (const exclude of this[EXCLUDES]) {
covArgs.push('-x');
covArgs.push(exclude);
Expand Down
1 change: 1 addition & 0 deletions lib/cmd/node-test.js
Expand Up @@ -120,6 +120,7 @@ class NodeTestCommand extends Command {
testArgv.dryRun = undefined;
// not support tscompiler for now
testArgv.tscompiler = undefined;
testArgv.eggTsHelper = undefined;

return this.helper.unparseArgv(testArgv);
}
Expand Down
2 changes: 0 additions & 2 deletions lib/cmd/test.js
@@ -1,5 +1,3 @@
'use strict';

const debug = require('debug')('egg-bin');
const fs = require('fs');
const path = require('path');
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -84,10 +84,10 @@
"lint": "eslint .",
"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 3600000",
"test-local": "node bin/egg-bin.js test -t 120000 --parallel",
"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 cov",
"ci": "npm run lint && npm run pkgfiles -- --check && npm run ci-test-only && npm run test-local",
"autod": "node bin/egg-bin.js autod"
},
"engines": {
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/mocha-test/test/bar.test.js
@@ -0,0 +1,7 @@
const assert = require('assert');

describe('mocha-test bar.test.js', () => {
it('should work', () => {
assert(true);
});
});
4 changes: 1 addition & 3 deletions test/fixtures/mocha-test/test/foo.test.js
@@ -1,8 +1,6 @@
'use strict';

const assert = require('assert');

describe('mocha-test', () => {
describe('mocha-test foo.test.js', () => {
it('should work', () => {
assert(true);
});
Expand Down
2 changes: 0 additions & 2 deletions test/fixtures/node-test/test/success.test.js
@@ -1,5 +1,3 @@
'use strict';

let test;
try {
test = require('node:test');
Expand Down
42 changes: 13 additions & 29 deletions test/lib/cmd/debug.test.js
@@ -1,10 +1,9 @@
'use strict';

const path = require('path');
const coffee = require('coffee');
const mm = require('egg-mock');
const net = require('net');
const semver = require('semver');
const detect = require('detect-port');

describe('test/lib/cmd/debug.test.js', () => {
const eggBin = require.resolve('../../../bin/egg-bin.js');
Expand Down Expand Up @@ -47,18 +46,25 @@ describe('test/lib/cmd/debug.test.js', () => {

describe('auto detect available port', () => {
let server;
before(done => {
let serverPort;
before(async () => {
serverPort = await detect(7001);
server = net.createServer();
server.listen(7001, done);
await new Promise(resolve => {
server.listen(serverPort, resolve);
});
});

after(() => server.close());

it('should auto detect available port', () => {
return coffee.fork(eggBin, [ 'debug' ], { cwd })
// .debug()
return coffee.fork(eggBin, [ 'debug' ], {
cwd,
env: { ...process.env, EGG_BIN_DEFAULT_PORT: serverPort },
})
// .debug()
.expect('stdout', /,"workers":1/)
.expect('stderr', /\[egg-bin] server port 7001 is in use/)
.expect('stderr', /\[egg-bin] server port \d+ is in use/)
.expect('code', 0)
.end();
});
Expand Down Expand Up @@ -100,27 +106,5 @@ describe('test/lib/cmd/debug.test.js', () => {
.expect('code', 0)
.end();
});

it('should not print devtools at webstorm', () => {
mm(process.env, 'NODE_DEBUG_OPTION', '--debug-port=5555');
const app = coffee.fork(eggBin, [ 'debug' ], { cwd });
// app.debug();
return app.expect('stderr', /Debugger listening/)
.notExpect('stdout', /Debug Proxy online, now you could attach to 9999/)
.notExpect('stdout', /DevTools → devtools:.*:9999/)
.expect('code', 0)
.end();
});

it.skip('should not print devtools at webstorm 2019', () => {
mm(process.env, 'JB_DEBUG_FILE', __filename);
const app = coffee.fork(eggBin, [ 'debug' ], { cwd });
// app.debug();
return app.expect('stderr', /Debugger listening/)
.notExpect('stdout', /Debug Proxy online, now you could attach to 9999/)
.notExpect('stdout', /DevTools → devtools:.*:9999/)
.expect('code', 0)
.end();
});
});
});
20 changes: 13 additions & 7 deletions test/lib/cmd/dev.test.js
@@ -1,9 +1,8 @@
'use strict';

const path = require('path');
const coffee = require('coffee');
const net = require('net');
const mm = require('mm');
const detect = require('detect-port');

describe('test/lib/cmd/dev.test.js', () => {
const eggBin = require.resolve('../../../bin/egg-bin.js');
Expand Down Expand Up @@ -125,17 +124,24 @@ describe('test/lib/cmd/dev.test.js', () => {

describe('auto detect available port', () => {
let server;
before(done => {
let serverPort;
before(async () => {
serverPort = await detect(7001);
server = net.createServer();
server.listen(7001, done);
await new Promise(resolve => {
server.listen(serverPort, resolve);
});
});

after(() => server.close());

it('should auto detect available port', done => {
coffee.fork(eggBin, [ 'dev' ], { cwd })
// .debug()
.expect('stderr', /\[egg-bin] server port 7001 is in use, now using port \d+/)
coffee.fork(eggBin, [ 'dev' ], {
cwd,
env: { ...process.env, EGG_BIN_DEFAULT_PORT: serverPort },
})
// .debug()
.expect('stderr', /\[egg-bin] server port \d+ is in use, now using port \d+/)
.expect('code', 0)
.end(done);
});
Expand Down
9 changes: 4 additions & 5 deletions test/lib/cmd/test.test.js
@@ -1,5 +1,3 @@
'use strict';

const path = require('path');
const coffee = require('coffee');
const mm = require('mm');
Expand Down Expand Up @@ -334,13 +332,14 @@ describe('test/lib/cmd/test.test.js', () => {
});
});

it('test parallel', done => {
it('test parallel', () => {
if (process.platform === 'win32') return;
mm(process.env, 'TESTS', 'test/**/*.test.js');
coffee.fork(eggBin, [ 'test', '--parallel' ], { cwd: path.join(__dirname, '../../fixtures/test-demo-app') })
return coffee.fork(eggBin, [ 'test', '--parallel' ], { cwd: path.join(__dirname, '../../fixtures/test-demo-app') })
// .debug()
.expect('stdout', /should work/)
.expect('stdout', /a\.test\.js/)
.expect('code', 0)
.end(done);
.end();
});
});
12 changes: 9 additions & 3 deletions test/mocha-bin.test.js
@@ -1,5 +1,3 @@
'use strict';

const path = require('path');
const coffee = require('coffee');

Expand All @@ -10,7 +8,15 @@ describe('test/mocha-bin.test.js', () => {
it('should test with mocha', () => {
return coffee.fork(mochaBin, [ 'test/*.test.js' ], { cwd })
.debug()
.expect('stdout', /1 passing/)
.expect('stdout', /2 passing/)
.expect('code', 0)
.end();
});

it('should test with mocha --parallel', () => {
return coffee.fork(mochaBin, [ 'test/*.test.js', '--parallel' ], { cwd })
.debug()
.expect('stdout', /2 passing/)
.expect('code', 0)
.end();
});
Expand Down
8 changes: 5 additions & 3 deletions test/node-test-cov.test.js
@@ -1,15 +1,17 @@
'use strict';

const path = require('path');
const coffee = require('coffee');

describe('test/node-test-cov.test.js', () => {
// https://github.com/bcoe/c8/issues/422#issuecomment-1291572456
// skip temp on Node.js
if (process.version.startsWith('v18.')) return;

const eggBin = require.resolve('../bin/egg-bin.js');
const cwd = path.join(__dirname, 'fixtures/node-test');

it('should run with node-test mode work', () => {
return coffee.fork(eggBin, [ 'node-test-cov' ], { cwd })
// .debug()
.debug()
.expect('stdout', /# tests 2/)
.expect('stdout', /# pass 1/)
.expect('stdout', /# fail 1/)
Expand Down
8 changes: 5 additions & 3 deletions test/node-test.test.js
@@ -1,15 +1,17 @@
'use strict';

const path = require('path');
const coffee = require('coffee');

describe('test/node-test.test.js', () => {
// https://github.com/bcoe/c8/issues/422#issuecomment-1291572456
// skip temp on Node.js
if (process.version.startsWith('v18.')) return;

const eggBin = require.resolve('../bin/egg-bin.js');
const cwd = path.join(__dirname, 'fixtures/node-test');

it('should run with node-test mode work', () => {
return coffee.fork(eggBin, [ 'node-test' ], { cwd })
// .debug()
.debug()
.expect('stdout', /# tests 2/)
.expect('stdout', /# pass 1/)
.expect('stdout', /# fail 1/)
Expand Down
6 changes: 2 additions & 4 deletions test/ts.test.js
@@ -1,5 +1,3 @@
'use strict';

const path = require('path');
const coffee = require('coffee');
const mm = require('mm');
Expand Down Expand Up @@ -199,7 +197,7 @@ describe('test/ts.test.js', () => {

it('should start app', () => {
return coffee.fork(eggBin, [ 'dev' ], { cwd })
// .debug()
.debug()
.expect('stdout', /hi, egg, 12345/)
.expect('stdout', /ts env: true/)
.expect('stdout', /started/)
Expand All @@ -219,7 +217,7 @@ describe('test/ts.test.js', () => {
it('should start app with flags in app without eggInfo', async () => {
const cwd = path.join(__dirname, './fixtures/example-ts-simple');
await coffee.fork(eggBin, [ 'dev', '--ts' ], { cwd })
// .debug()
.debug()
.expect('stdout', /started/)
.expect('code', 0)
.end();
Expand Down