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

feat: add ts env in command #98

Merged
merged 4 commits into from
Apr 18, 2018
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
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