Skip to content

Commit

Permalink
test: add ts test
Browse files Browse the repository at this point in the history
  • Loading branch information
atian25 committed Mar 26, 2018
1 parent 013ecd2 commit 72f4f8b
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 1 deletion.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@
"mz-modules": "^2.1.0",
"pedding": "^1.1.0",
"semver": "^5.5.0",
"supertest": "^3.0.0"
"supertest": "^3.0.0",
"ts-node": "^5.0.1",
"typescript": "^2.7.2"
},
"engines": {
"node": ">= 6.0.0"
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/apps/ts/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

import { Application } from 'egg';

export default (app: Application) => {
console.log(`hi, egg, ${app.config.keys}`);
};
9 changes: 9 additions & 0 deletions test/fixtures/apps/ts/config/config.default.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

import { EggAppConfig } from 'egg';

export default (appInfo: EggAppConfig) => {
const config: any = {};
config.keys = '123456';
return config;
};
3 changes: 3 additions & 0 deletions test/fixtures/apps/ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "ts"
}
41 changes: 41 additions & 0 deletions test/ts.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

const mm = require('egg-mock');
const utils = require('./utils');

describe('test/ts.test.js', () => {
if (process.env.EGG_VERSION && process.env.EGG_VERSION == '1') { // eslint-disable-line eqeqeq
console.log('skip egg@1');
return;
}

let app;

afterEach(mm.restore);
afterEach(() => app.close());

it('support typescript', done => {
mm.env('local');
app = utils.cluster('apps/ts', {
typescript: true,
opt: { execArgv: [ '--require', require.resolve('ts-node/register') ] },
});
// app.debug();
app.expect('stdout', /hi, egg, 123456/)
.expect('stdout', /egg started/)
.notExpect('stdout', /\[master\] agent_worker#1:\d+ start with clusterPort:\d+/)
.expect('code', 0)
.end(done);
});

it('require ts-node register', done => {
mm.env('local');
app = utils.cluster('apps/ts', {
typescript: true,
});
// app.debug();
app.expect('stderr', /`require.extensions` should contains `.ts`/)
.expect('code', 1)
.end(done);
});
});

0 comments on commit 72f4f8b

Please sign in to comment.