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: support typescript #89

Merged
merged 20 commits into from
Mar 28, 2018
Merged
Show file tree
Hide file tree
Changes from 12 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
23 changes: 0 additions & 23 deletions lib/ts-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,4 @@

require('ts-node').register({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这些配置和 tsconfig 啥关系

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里提供默认值,应用层 tsconfig.json 可以覆盖

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那最好只读 tsconfig.json,这个默认配置和 ts-node 的有差异?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的配置是针对 Node 应用的,ts-node 会考虑到前端应用,所以默认值不一样。

Copy link
Member Author

@atian25 atian25 Mar 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最新的已经去掉默认值了。开发者自己配置

typeCheck: true,
compilerOptions: {
target: 'es2017',
module: 'commonjs',
strict: true,
moduleResolution: 'node',
noImplicitAny: false,
experimentalDecorators: true,
emitDecoratorMetadata: true,
charset: 'utf8',
allowJs: false,
pretty: true,
noEmitOnError: false,
noUnusedLocals: true,
noUnusedParameters: true,
allowUnreachableCode: false,
allowUnusedLabels: false,
strictPropertyInitialization: false,
noFallthroughCasesInSwitch: true,
skipLibCheck: true,
skipDefaultLibCheck: true,
inlineSourceMap: true,
importHelpers: true,
},
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"react": "^0.14.7",
"react-addons-test-utils": "^0.14.7",
"react-dom": "^0.14.7",
"semver": "^5.4.1"
"semver": "^5.4.1",
"typescript": "^2.7.2"
},
"repository": {
"type": "git",
Expand Down
21 changes: 21 additions & 0 deletions test/fixtures/example-ts/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

import { Application, Context } from 'egg';
import { default as mock, MockOption, BaseMockApplication } from 'egg-mock';
import * as path from 'path';

describe('test/index.test.ts', () => {
let app: BaseMockApplication<Application, Context>;
before(() => {
app = mock.app({ typescript: true } as MockOption);
return app.ready();
});
after(() => app.close());
it('should work', async () => {
await app
.httpRequest()
.get('/')
.expect('hi, egg')
.expect(200);
});
});
25 changes: 25 additions & 0 deletions test/fixtures/example-ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"strict": true,
"moduleResolution": "node",
"noImplicitAny": false,
"experimentalDecorators": true,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里有没有一些可以精简掉

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已经精简了,将跟默认值一样的值去掉了

"emitDecoratorMetadata": true,
"charset": "utf8",
"allowJs": false,
"pretty": true,
"noEmitOnError": false,
"noUnusedLocals": true,
"noUnusedParameters": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"strictPropertyInitialization": false,
"noFallthroughCasesInSwitch": true,
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"inlineSourceMap": true,
"importHelpers": true
},
}
25 changes: 25 additions & 0 deletions test/fixtures/ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"strict": true,
"moduleResolution": "node",
"noImplicitAny": false,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"charset": "utf8",
"allowJs": false,
"pretty": true,
"noEmitOnError": false,
"noUnusedLocals": true,
"noUnusedParameters": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"strictPropertyInitialization": false,
"noFallthroughCasesInSwitch": true,
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"inlineSourceMap": true,
"importHelpers": true
},
}
18 changes: 16 additions & 2 deletions test/ts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('test/ts.test.js', () => {
.debug()
.expect('stdout', /### egg from ts/)
.expect('stdout', /options.typescript=true/)
.expect('stdout', /egg started/)
.expect('stdout', /started/)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个判断为啥干掉

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在 Egg version 2 里,好像不会输出 egg stared 的内容,只会输出 application stared 等

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

所以单测一直跪在 egg@2 ,改成 stared 就正常了

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sleep 的时间不够吧

.expect('code', 0)
.end();
});
Expand All @@ -43,7 +43,21 @@ describe('test/ts.test.js', () => {
return coffee.fork(eggBin, [ 'dev', '--ts' ], { cwd })
.debug()
.expect('stdout', /hi, egg, 12345/)
.expect('stdout', /egg started/)
.expect('stdout', /started/)
.expect('code', 0)
.end();
});

it('should test app', () => {
if (process.env.EGG_VERSION && process.env.EGG_VERSION === '1') {
console.log('skip egg@1');
return;
}
cwd = path.join(__dirname, './fixtures/example-ts');
return coffee.fork(eggBin, [ 'test', '--ts' ], { cwd })
.debug()
.expect('stdout', /hi, egg, 123456/)
.expect('stdout', /should work/)
.expect('code', 0)
.end();
});
Expand Down