diff --git a/lib/cmd/test.js b/lib/cmd/test.js index 294443d1..33317d79 100644 --- a/lib/cmd/test.js +++ b/lib/cmd/test.js @@ -40,7 +40,6 @@ class TestCommand extends Command { const opt = { env: Object.assign({ NODE_ENV: 'test', - EGG_TYPESCRIPT: context.argv.typescript, }, context.env), execArgv: context.execArgv, }; diff --git a/lib/command.js b/lib/command.js index 544e32b7..9bcb1e4b 100644 --- a/lib/command.js +++ b/lib/command.js @@ -26,7 +26,7 @@ class Command extends BaseCommand { get context() { const context = super.context; - const { argv, debugPort, execArgvObj, cwd } = context; + const { argv, debugPort, execArgvObj, cwd, env } = context; // compatible if (debugPort) context.debug = debugPort; @@ -51,6 +51,7 @@ class Command extends BaseCommand { if (argv.typescript) { execArgvObj.require = execArgvObj.require || []; execArgvObj.require.push(path.join(__dirname, './ts-helper.js')); + env.EGG_TYPESCRIPT = true; } return context; diff --git a/test/fixtures/example-ts-pkg/app.ts b/test/fixtures/example-ts-pkg/app.ts index a063672b..b9d7d67c 100644 --- a/test/fixtures/example-ts-pkg/app.ts +++ b/test/fixtures/example-ts-pkg/app.ts @@ -4,4 +4,5 @@ import { Application } from 'egg'; export default (app: Application) => { console.log(`hi, egg, ${app.config.keys}`); + console.log(`ts env: ${process.env.EGG_TYPESCRIPT}`); }; diff --git a/test/fixtures/example-ts/app.ts b/test/fixtures/example-ts/app.ts index a063672b..b9d7d67c 100644 --- a/test/fixtures/example-ts/app.ts +++ b/test/fixtures/example-ts/app.ts @@ -4,4 +4,5 @@ import { Application } from 'egg'; export default (app: Application) => { console.log(`hi, egg, ${app.config.keys}`); + console.log(`ts env: ${process.env.EGG_TYPESCRIPT}`); }; diff --git a/test/ts.test.js b/test/ts.test.js index bff49e3d..e914bd80 100644 --- a/test/ts.test.js +++ b/test/ts.test.js @@ -47,6 +47,7 @@ describe('test/ts.test.js', () => { return coffee.fork(eggBin, [ 'dev', '--ts' ], { cwd }) // .debug() .expect('stdout', /hi, egg, 12345/) + .expect('stdout', /ts env: true/) .expect('stdout', /started/) .expect('code', 0) .end(); @@ -56,6 +57,7 @@ describe('test/ts.test.js', () => { return coffee.fork(eggBin, [ 'test', '--ts' ], { cwd }) // .debug() .expect('stdout', /hi, egg, 123456/) + .expect('stdout', /ts env: true/) .expect('stdout', /should work/) .expect('code', 0) .end(); @@ -65,6 +67,7 @@ describe('test/ts.test.js', () => { return coffee.fork(eggBin, [ 'cov', '--ts' ], { cwd }) // .debug() .expect('stdout', /hi, egg, 123456/) + .expect('stdout', /ts env: true/) .expect('stdout', process.env.NYC_ROOT_ID ? /Coverage summary/ : /Statements.*100%/) .expect('code', 0) .end(); @@ -85,6 +88,7 @@ describe('test/ts.test.js', () => { return coffee.fork(eggBin, [ 'dev' ], { cwd }) // .debug() .expect('stdout', /hi, egg, 12345/) + .expect('stdout', /ts env: true/) .expect('stdout', /started/) .expect('code', 0) .end(); @@ -103,6 +107,7 @@ describe('test/ts.test.js', () => { return coffee.fork(eggBin, [ 'dev', './example-ts-pkg' ], { cwd: path.dirname(cwd) }) // .debug() .expect('stdout', /hi, egg, 12345/) + .expect('stdout', /ts env: true/) .expect('stdout', /started/) .expect('code', 0) .end(); @@ -112,6 +117,7 @@ describe('test/ts.test.js', () => { return coffee.fork(eggBin, [ 'test' ], { cwd }) // .debug() .expect('stdout', /hi, egg, 123456/) + .expect('stdout', /ts env: true/) .expect('code', 0) .end(); }); @@ -120,6 +126,7 @@ describe('test/ts.test.js', () => { return coffee.fork(eggBin, [ 'cov' ], { cwd }) .debug() .expect('stdout', /hi, egg, 123456/) + .expect('stdout', /ts env: true/) .expect('stdout', process.env.NYC_ROOT_ID ? /Coverage summary/ : /Statements.*100%/) .expect('code', 0) .end();