diff --git a/lib/cmd/test.js b/lib/cmd/test.js index c14b1efd..92629c3a 100644 --- a/lib/cmd/test.js +++ b/lib/cmd/test.js @@ -38,7 +38,10 @@ class TestCommand extends Command { * run(context) { const opt = { - env: Object.assign({ NODE_ENV: 'test' }, context.env), + env: Object.assign({ + NODE_ENV: 'test', + EGG_TYPESCRIPT: context.argv.typescript, + }, context.env), execArgv: context.execArgv, }; const mochaFile = require.resolve('mocha/bin/_mocha'); @@ -53,7 +56,7 @@ class TestCommand extends Command { * @return {Array} [ '--require=xxx', 'xx.test.js' ] * @protected */ - formatTestArgs({ argv, debug }) { + formatTestArgs({ argv, debug, env }) { const testArgv = Object.assign({}, argv); /* istanbul ignore next */ diff --git a/test/fixtures/example-ts/test/index.test.ts b/test/fixtures/example-ts/test/index.test.ts index 25c83639..a5b29892 100644 --- a/test/fixtures/example-ts/test/index.test.ts +++ b/test/fixtures/example-ts/test/index.test.ts @@ -1,16 +1,8 @@ 'use strict'; -import { Application, Context } from 'egg'; -import { default as mock, MockOption, BaseMockApplication } from 'egg-mock'; -import * as path from 'path'; +import { app } from 'egg-mock/bootstrap'; describe('test/index.test.ts', () => { - let app: BaseMockApplication; - before(() => { - app = mock.app({ typescript: true } as MockOption); - return app.ready(); - }); - after(() => app.close()); it('should work', async () => { await app .httpRequest() diff --git a/test/fixtures/ts/app.js b/test/fixtures/ts/app.ts similarity index 100% rename from test/fixtures/ts/app.js rename to test/fixtures/ts/app.ts diff --git a/test/ts.test.js b/test/ts.test.js index 3993cd02..2038b91c 100644 --- a/test/ts.test.js +++ b/test/ts.test.js @@ -14,7 +14,7 @@ describe('test/ts.test.js', () => { cwd = path.join(__dirname, './fixtures/ts'); mm(process.env, 'NODE_ENV', 'development'); return coffee.fork(eggBin, [ 'dev', '--typescript' ], { cwd }) - .debug() + // .debug() .expect('stdout', /### egg from ts/) .expect('stdout', /options.typescript=true/) .expect('stdout', /started/) @@ -26,7 +26,7 @@ describe('test/ts.test.js', () => { cwd = path.join(__dirname, './fixtures/ts'); mm(process.env, 'NODE_ENV', 'development'); return coffee.fork(eggBin, [ 'test', '--typescript' ], { cwd }) - .debug() + // .debug() .notExpect('stdout', /false == true/) .notExpect('stdout', /should not load js files/) .expect('stdout', /--- \[string\] 'wrong assert ts'/) @@ -41,7 +41,7 @@ describe('test/ts.test.js', () => { } cwd = path.join(__dirname, './fixtures/example-ts'); return coffee.fork(eggBin, [ 'dev', '--ts' ], { cwd }) - .debug() + // .debug() .expect('stdout', /hi, egg, 12345/) .expect('stdout', /started/) .expect('code', 0) @@ -55,7 +55,7 @@ describe('test/ts.test.js', () => { } cwd = path.join(__dirname, './fixtures/example-ts'); return coffee.fork(eggBin, [ 'test', '--ts' ], { cwd }) - .debug() + // .debug() .expect('stdout', /hi, egg, 123456/) .expect('stdout', /should work/) .expect('code', 0)