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 typescript support #61

Merged
merged 2 commits into from
Mar 27, 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: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ startCluster(options, () => {
| sticky | `Boolean` | sticky mode server |
| port | `Number` | port |
| https | `Object` | start a https server, note: `key` / `cert` should be full path to file |
| typescript | `Boolean` | enable loader's typescript support |

## License

Expand Down
1 change: 1 addition & 0 deletions lib/utils/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = function(options) {
https: false,
key: '',
cert: '',
typescript: false,
Copy link
Member

Choose a reason for hiding this comment

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

加个用例?看能否开启 egg-core

Copy link
Member Author

Choose a reason for hiding this comment

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

加了

};
options = extend(defaults, options);
if (!options.workers) {
Expand Down
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') {
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);
});
});