Skip to content

Commit 3b370ef

Browse files
ahungrynoobatian25
authored andcommitted
fix: nyc shim (#138)
1 parent 188c29c commit 3b370ef

File tree

16 files changed

+136
-6
lines changed

16 files changed

+136
-6
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ test/fixtures/ts/node_modules/aliyun-egg/
1111
!test/fixtures/test-files-glob/**
1212
!test/fixtures/test-files-stack/node_modules/
1313
!test/fixtures/example/node_modules/
14+
!test/fixtures/example-ts-cluster/node_modules/
1415
!test/fixtures/example-ts-error-stack/node_modules/
1516
!test/fixtures/egg-require/node_modules/
1617
test/fixtures/example-ts-ets/typings/

.travis.yml

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
sudo: false
22
language: node_js
33
node_js:
4-
- '6'
5-
- '8'
6-
- '10'
4+
- "6"
5+
- "8"
6+
- "10"
77
env:
88
- EGG_VERSION=1
99
- EGG_VERSION=2
1010
matrix:
1111
exclude:
12-
- node_js: '6'
13-
env: EGG_VERSION=2
12+
- node_js: "6"
13+
env: EGG_VERSION=2
14+
before_install:
15+
- npm install npminstall -g
1416
install:
15-
- npm i npminstall
1617
- sed -i.bak '/"egg":/d' package.json
1718
- npminstall -d
1819
script:

lib/cmd/cov.js

+5
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ class CovCommand extends Command {
8383
}, env),
8484
};
8585

86+
// https://github.com/eggjs/egg/issues/3930
87+
if (context.argv.typescript) {
88+
opt.env.SPAWN_WRAP_SHIM_ROOT = path.join(cwd, 'node_modules');
89+
}
90+
8691
// save coverage-xxxx.json to $PWD/coverage
8792
const covArgs = yield this.getCovArgs(context);
8893
if (!covArgs) return;
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
import { Application } from 'egg';
4+
5+
export default (app: Application) => {
6+
console.log(`hi, egg, ${app.config.keys}`);
7+
console.log(`ts env: ${process.env.EGG_TYPESCRIPT}`);
8+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
import { Controller } from 'egg';
4+
5+
export default class HomeController extends Controller {
6+
public async index() {
7+
const obj: PlainObject = {};
8+
obj.text = 'hi, egg';
9+
this.ctx.body = obj.text;
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
import { Application } from 'egg';
4+
5+
export default (app: Application) => {
6+
app.router.get('/', app.controller.home.index);
7+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
export default () => {
4+
const config = {} as any;
5+
config.keys = '123456';
6+
return config;
7+
};

test/fixtures/example-ts-cluster/node_modules/egg/index.js

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/example-ts-cluster/node_modules/egg/package.json

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "example-ts",
3+
"egg": {
4+
"typescript": true
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"use strict";
2+
3+
import mm, { MockOption } from "egg-mock";
4+
import request = require("supertest");
5+
6+
describe("test/index.test.ts", () => {
7+
let app: any;
8+
before(() => {
9+
app = mm.cluster({
10+
opt: {
11+
execArgv: ["--require", require.resolve("ts-node/register")]
12+
}
13+
} as MockOption);
14+
return app.ready();
15+
});
16+
17+
after(() => app.close());
18+
it("should work", async () => {
19+
const req = request(`http://127.0.0.1:${app.port}`);
20+
return req
21+
.get("/")
22+
.expect("hi, egg")
23+
.expect(200);
24+
});
25+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2017",
4+
"module": "commonjs",
5+
"strict": true,
6+
"noImplicitAny": false,
7+
"moduleResolution": "node",
8+
"experimentalDecorators": true,
9+
"emitDecoratorMetadata": true,
10+
"pretty": true,
11+
"noUnusedLocals": true,
12+
"noUnusedParameters": true,
13+
"noFallthroughCasesInSwitch": true,
14+
"skipLibCheck": true,
15+
"skipDefaultLibCheck": true,
16+
"inlineSourceMap": true,
17+
"importHelpers": true
18+
},
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// This file was auto created by egg-ts-helper
2+
// Do not modify this file!!!!!!!!!
3+
4+
import Home from '../../../app/controller/home';
5+
6+
declare module 'egg' {
7+
interface IController {
8+
home: Home;
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
interface PlainObject extends Object {
2+
[key: string]: any;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Context } from 'egg';
2+
3+
// extend egg
4+
declare module 'egg' {
5+
interface Context {
6+
}
7+
}

test/ts.test.js

+9
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ describe('test/ts.test.js', () => {
7474
.expect('code', 0)
7575
.end();
7676
});
77+
78+
it('should cov app in cluster mod', () => {
79+
cwd = path.join(__dirname, './fixtures/example-ts-cluster');
80+
return coffee.fork(eggBin, [ 'cov', '--ts' ], { cwd })
81+
// .debug()
82+
.expect('stdout', process.env.NYC_ROOT_ID ? /Coverage summary/ : /Statements.*100%/)
83+
.expect('code', 0)
84+
.end();
85+
});
7786
});
7887

7988
describe('error stacks', () => {

0 commit comments

Comments
 (0)