Skip to content

Commit

Permalink
feat: add ts env in command (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
whxaxes authored and atian25 committed Apr 18, 2018
1 parent 376bb08 commit 756310e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
1 change: 0 additions & 1 deletion lib/cmd/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
3 changes: 2 additions & 1 deletion lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/example-ts-pkg/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
};
1 change: 1 addition & 0 deletions test/fixtures/example-ts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
};
7 changes: 7 additions & 0 deletions test/ts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
});
Expand All @@ -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();
Expand Down

0 comments on commit 756310e

Please sign in to comment.