-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a4ba2a2
commit 2b1644e
Showing
10 changed files
with
889 additions
and
1 deletion.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.js | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Controller } from 'egg'; | ||
|
||
// add user controller and service | ||
declare module 'egg' { | ||
interface IController { | ||
foo: FooController; | ||
} | ||
} | ||
|
||
// controller | ||
export default class FooController extends Controller { | ||
async getData() { | ||
this.ctx.body = await this.ctx.service.foo.bar(); | ||
} | ||
async getBar() { | ||
this.ctx.body = await this.service.foo.bar(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Application } from 'egg'; | ||
|
||
export default (app: Application) => { | ||
const controller = app.controller; | ||
app.get('/foo', controller.foo.getData); | ||
app.post('/', controller.foo.getData); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Service } from 'egg'; | ||
|
||
// add user controller and service | ||
declare module 'egg' { | ||
interface IService { | ||
foo: FooService; | ||
} | ||
} | ||
|
||
export default class FooService extends Service { | ||
async bar() { | ||
return { env: this.config.env }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default { | ||
keys: 'foo', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "app-ts", | ||
"version": "1.0.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es6", | ||
"baseUrl": ".", | ||
"paths": { | ||
"egg": ["../../../../index"] | ||
}, | ||
"module": "commonjs", | ||
"lib": ["es7"], | ||
"strict": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
|
||
const request = require('supertest'); | ||
const mm = require('egg-mock'); | ||
const runscript = require('runscript'); | ||
const path = require('path'); | ||
const utils = require('../utils'); | ||
const baseDir = path.join(__dirname, '../fixtures/apps/app-ts'); | ||
|
||
describe('test/ts/index.test.js', () => { | ||
before(function* () { | ||
if (process.env.CI) { | ||
yield runscript('tsc && npmlink ../../../../', { cwd: baseDir }); | ||
} else { | ||
yield runscript('tsc && npm link ../../../../', { cwd: baseDir }); | ||
} | ||
}); | ||
|
||
describe('compiler code', () => { | ||
|
||
afterEach(mm.restore); | ||
let app; | ||
before(function* () { | ||
app = utils.app('apps/app-ts'); | ||
yield app.ready(); | ||
}); | ||
after(function* () { | ||
yield app.close(); | ||
}); | ||
|
||
it('controller run ok', done => { | ||
request(app.callback()) | ||
.get('/foo') | ||
.expect(200) | ||
.expect({ env: 'unittest' }) | ||
.end(done); | ||
}); | ||
}); | ||
|
||
}); | ||
|