From c267288eb1610cd859be66d023d27e4d72671b58 Mon Sep 17 00:00:00 2001 From: killa Date: Tue, 10 Jan 2023 16:11:43 +0800 Subject: [PATCH] fix: use egg-mock/register instead (#205) Co-authored-by: fengmk2 --- lib/cmd/test.js | 10 ++++------ package.json | 7 +++---- test/fixtures/example-ts-ets/config/config.default.ts | 3 +-- test/fixtures/example-ts-ets/node_modules/egg/index.js | 10 ++++------ test/fixtures/test-demo-app/app/router.js | 3 ++- test/fixtures/test-demo-app/test/a.test.js | 2 +- test/lib/cmd/test.test.js | 8 ++++++-- test/ts.test.js | 8 ++++---- 8 files changed, 25 insertions(+), 26 deletions(-) diff --git a/lib/cmd/test.js b/lib/cmd/test.js index f01c8384..a96dd2b2 100644 --- a/lib/cmd/test.js +++ b/lib/cmd/test.js @@ -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')); + } catch (_) { + // ... } // handle mochawesome enable if (!testArgv.reporter && testArgv.mochawesome) { diff --git a/package.json b/package.json index 41f8fd68..a783522e 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "ypkgfiles": "^1.6.0" }, "peerDependencies": { - "egg-mock": "^5.0.2" + "egg-mock": "^5.8.2" }, "peerDependenciesMeta": { "egg-mock": { @@ -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", @@ -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", - "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" diff --git a/test/fixtures/example-ts-ets/config/config.default.ts b/test/fixtures/example-ts-ets/config/config.default.ts index dae5d3be..64b1f570 100644 --- a/test/fixtures/example-ts-ets/config/config.default.ts +++ b/test/fixtures/example-ts-ets/config/config.default.ts @@ -1,6 +1,5 @@ export default function() { - // built-in config - const config: Egg.PowerPartial = {}; + const config = {} as any; config.keys = '123123'; diff --git a/test/fixtures/example-ts-ets/node_modules/egg/index.js b/test/fixtures/example-ts-ets/node_modules/egg/index.js index 05ac38f1..1c1b980c 100644 --- a/test/fixtures/example-ts-ets/node_modules/egg/index.js +++ b/test/fixtures/example-ts-ets/node_modules/egg/index.js @@ -1,8 +1,6 @@ module.exports = require('egg'); -if (process.execArgv.find(argv => argv.includes('egg-ts-helper'))) { - setTimeout(() => { - console.log('exit by master test end'); - process.exit(0); - }, require('os').platform() === 'win32' ? 120000 : 10000); -} +setTimeout(() => { + console.log('exit by master test end'); + process.exit(0); +}, 5000); diff --git a/test/fixtures/test-demo-app/app/router.js b/test/fixtures/test-demo-app/app/router.js index a5729403..d2bcd052 100644 --- a/test/fixtures/test-demo-app/app/router.js +++ b/test/fixtures/test-demo-app/app/router.js @@ -1,9 +1,10 @@ 'use strict'; module.exports = function(app) { - app.get('/', function* () { + app.get('/', async function() { this.body = { fooPlugin: app.fooPlugin, + foo: 'bar', }; }); }; diff --git a/test/fixtures/test-demo-app/test/a.test.js b/test/fixtures/test-demo-app/test/a.test.js index 1fb9aead..30a03a56 100644 --- a/test/fixtures/test-demo-app/test/a.test.js +++ b/test/fixtures/test-demo-app/test/a.test.js @@ -7,6 +7,6 @@ describe('a.test.js', () => { await app.httpRequest() .get('/') .expect(200) - .expect({}); + .expect({ foo: 'bar' }); }); }); diff --git a/test/lib/cmd/test.test.js b/test/lib/cmd/test.test.js index 2b52614c..0c4417f6 100644 --- a/test/lib/cmd/test.test.js +++ b/test/lib/cmd/test.test.js @@ -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) diff --git a/test/ts.test.js b/test/ts.test.js index c5c87cd8..f6a83a47 100644 --- a/test/ts.test.js +++ b/test/ts.test.js @@ -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(); }); });