-
Notifications
You must be signed in to change notification settings - Fork 55
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
Changes from 12 commits
dd4302e
ed4453d
975ba18
e5a37cb
645a364
4222b74
a670ca6
4606640
ed00eb0
ef2b479
8f46c16
9de39aa
d4475ac
2f806f3
d2cd77e
1c88d0c
711264e
4d9d882
fff57c3
6505b96
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||
}); | ||
}); |
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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里有没有一些可以精简掉 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
}, | ||
} |
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 | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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/) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个判断为啥干掉 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 在 Egg version 2 里,好像不会输出 egg stared 的内容,只会输出 application stared 等 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 所以单测一直跪在 egg@2 ,改成 stared 就正常了 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sleep 的时间不够吧 |
||
.expect('code', 0) | ||
.end(); | ||
}); | ||
|
@@ -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(); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这些配置和 tsconfig 啥关系
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里提供默认值,应用层
tsconfig.json
可以覆盖There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那最好只读 tsconfig.json,这个默认配置和 ts-node 的有差异?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的配置是针对 Node 应用的,ts-node 会考虑到前端应用,所以默认值不一样。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最新的已经去掉默认值了。开发者自己配置