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: use egg-mock/register instead #205

Merged
merged 10 commits into from
Jan 10, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions lib/cmd/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,10 @@ class TestCommand extends Command {
// 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 (testArgv.parallel && testArgv['auto-agent']) {
try {
requireArr.push(require.resolve('egg-mock/lib/parallel/agent_register'));
} catch (_) {
console.warn('Please install egg-mock, or can not use auto agent');
}
try {
requireArr.push(require.resolve('egg-mock/register'));
fengmk2 marked this conversation as resolved.
Show resolved Hide resolved
} catch (_) {
// ...
fengmk2 marked this conversation as resolved.
Show resolved Hide resolved
}
// handle mochawesome enable
if (!testArgv.reporter && testArgv.mochawesome) {
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"ypkgfiles": "^1.6.0"
},
"peerDependencies": {
"egg-mock": "^5.0.2"
"egg-mock": "^5.8.2"
},
"peerDependenciesMeta": {
"egg-mock": {
Expand All @@ -52,7 +52,7 @@
"coffee": "^5.4.0",
"cross-env": "^3.1.3",
"egg": "^3.9.1",
"egg-mock": "^5.0.2",
"egg-mock": "^5.8.2",
"enzyme": "^2.0.0",
"esbuild-register": "^2.5.0",
"eslint": "^8.16.0",
Expand All @@ -79,8 +79,7 @@
"contributor": "git-contributor",
"lint": "eslint .",
"test": "npm run lint -- --fix && npm run test-local",
"test-local": "node bin/egg-bin.js test -t 120000 --parallel",
fengmk2 marked this conversation as resolved.
Show resolved Hide resolved
"test-single": "node bin/egg-bin.js test -t 120000",
"test-local": "node bin/egg-bin.js test -t 120000",
"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 ci-test-only && npm run test-local"
Expand Down
3 changes: 1 addition & 2 deletions test/fixtures/example-ts-ets/config/config.default.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export default function() {
// built-in config
const config: Egg.PowerPartial<Egg.EggAppConfig> = {};
const config = {} as any;

config.keys = '123123';

Expand Down
10 changes: 4 additions & 6 deletions test/fixtures/example-ts-ets/node_modules/egg/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion test/fixtures/test-demo-app/app/router.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict';

module.exports = function(app) {
app.get('/', function* () {
app.get('/', async function() {
this.body = {
fooPlugin: app.fooPlugin,
foo: 'bar',
};
});
};
2 changes: 1 addition & 1 deletion test/fixtures/test-demo-app/test/a.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ describe('a.test.js', () => {
await app.httpRequest()
.get('/')
.expect(200)
.expect({});
.expect({ foo: 'bar' });
});
});
8 changes: 6 additions & 2 deletions test/lib/cmd/test.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,14 @@ describe('test/lib/cmd/test.test.js', () => {
});
});

// fail on github action ubuntu
it('test parallel', () => {
if (process.platform !== 'darwin') return;
mm(process.env, 'TESTS', 'test/**/*.test.js');
return coffee.fork(eggBin, [ 'test', '--parallel' ], { cwd: path.join(__dirname, '../../fixtures/test-demo-app') })
// .debug()
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)
Expand Down
8 changes: 4 additions & 4 deletions test/ts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,12 @@ describe('test/ts.test.js', () => {

it('should not load egg-ts-helper without flag and egg.declarations', () => {
return coffee.fork(eggBin, [ 'dev' ], { cwd })
// .debug()
.debug()
.expect('stdout', /"typescript":true/)
.notExpect('stdout', /application log/)
.expect('stdout', /application log/)
.notExpect('stdout', /"declarations":true/)
.notExpect('stdout', /started/)
.expect('code', 1)
.expect('stdout', /started/)
.expect('code', 0)
.end();
});
});
Expand Down