Skip to content

Commit

Permalink
fix: nyc shim (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahungrynoob authored and atian25 committed Sep 27, 2019
1 parent 188c29c commit 3b370ef
Show file tree
Hide file tree
Showing 16 changed files with 136 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -11,6 +11,7 @@ test/fixtures/ts/node_modules/aliyun-egg/
!test/fixtures/test-files-glob/**
!test/fixtures/test-files-stack/node_modules/
!test/fixtures/example/node_modules/
!test/fixtures/example-ts-cluster/node_modules/
!test/fixtures/example-ts-error-stack/node_modules/
!test/fixtures/egg-require/node_modules/
test/fixtures/example-ts-ets/typings/
Expand Down
13 changes: 7 additions & 6 deletions .travis.yml
@@ -1,18 +1,19 @@
sudo: false
language: node_js
node_js:
- '6'
- '8'
- '10'
- "6"
- "8"
- "10"
env:
- EGG_VERSION=1
- EGG_VERSION=2
matrix:
exclude:
- node_js: '6'
env: EGG_VERSION=2
- node_js: "6"
env: EGG_VERSION=2
before_install:
- npm install npminstall -g
install:
- npm i npminstall
- sed -i.bak '/"egg":/d' package.json
- npminstall -d
script:
Expand Down
5 changes: 5 additions & 0 deletions lib/cmd/cov.js
Expand Up @@ -83,6 +83,11 @@ class CovCommand extends Command {
}, env),
};

// https://github.com/eggjs/egg/issues/3930
if (context.argv.typescript) {
opt.env.SPAWN_WRAP_SHIM_ROOT = path.join(cwd, 'node_modules');
}

// save coverage-xxxx.json to $PWD/coverage
const covArgs = yield this.getCovArgs(context);
if (!covArgs) return;
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/example-ts-cluster/app.ts
@@ -0,0 +1,8 @@
'use strict';

import { Application } from 'egg';

export default (app: Application) => {
console.log(`hi, egg, ${app.config.keys}`);
console.log(`ts env: ${process.env.EGG_TYPESCRIPT}`);
};
11 changes: 11 additions & 0 deletions test/fixtures/example-ts-cluster/app/controller/home.ts
@@ -0,0 +1,11 @@
'use strict';

import { Controller } from 'egg';

export default class HomeController extends Controller {
public async index() {
const obj: PlainObject = {};
obj.text = 'hi, egg';
this.ctx.body = obj.text;
}
}
7 changes: 7 additions & 0 deletions test/fixtures/example-ts-cluster/app/router.ts
@@ -0,0 +1,7 @@
'use strict';

import { Application } from 'egg';

export default (app: Application) => {
app.router.get('/', app.controller.home.index);
};
7 changes: 7 additions & 0 deletions test/fixtures/example-ts-cluster/config/config.default.ts
@@ -0,0 +1,7 @@
'use strict';

export default () => {
const config = {} as any;
config.keys = '123456';
return config;
};
8 changes: 8 additions & 0 deletions test/fixtures/example-ts-cluster/node_modules/egg/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test/fixtures/example-ts-cluster/package.json
@@ -0,0 +1,6 @@
{
"name": "example-ts",
"egg": {
"typescript": true
}
}
25 changes: 25 additions & 0 deletions test/fixtures/example-ts-cluster/test/index.test.ts
@@ -0,0 +1,25 @@
"use strict";

import mm, { MockOption } from "egg-mock";
import request = require("supertest");

describe("test/index.test.ts", () => {
let app: any;
before(() => {
app = mm.cluster({
opt: {
execArgv: ["--require", require.resolve("ts-node/register")]
}
} as MockOption);
return app.ready();
});

after(() => app.close());
it("should work", async () => {
const req = request(`http://127.0.0.1:${app.port}`);
return req
.get("/")
.expect("hi, egg")
.expect(200);
});
});
19 changes: 19 additions & 0 deletions test/fixtures/example-ts-cluster/tsconfig.json
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"strict": true,
"noImplicitAny": false,
"moduleResolution": "node",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"pretty": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"inlineSourceMap": true,
"importHelpers": true
},
}
10 changes: 10 additions & 0 deletions test/fixtures/example-ts-cluster/typings/app/controller/index.d.ts
@@ -0,0 +1,10 @@
// This file was auto created by egg-ts-helper
// Do not modify this file!!!!!!!!!

import Home from '../../../app/controller/home';

declare module 'egg' {
interface IController {
home: Home;
}
}
3 changes: 3 additions & 0 deletions test/fixtures/example-ts-cluster/typings/global.d.ts
@@ -0,0 +1,3 @@
interface PlainObject extends Object {
[key: string]: any;
}
7 changes: 7 additions & 0 deletions test/fixtures/example-ts-cluster/typings/index.d.ts
@@ -0,0 +1,7 @@
import { Context } from 'egg';

// extend egg
declare module 'egg' {
interface Context {
}
}
9 changes: 9 additions & 0 deletions test/ts.test.js
Expand Up @@ -74,6 +74,15 @@ describe('test/ts.test.js', () => {
.expect('code', 0)
.end();
});

it('should cov app in cluster mod', () => {
cwd = path.join(__dirname, './fixtures/example-ts-cluster');
return coffee.fork(eggBin, [ 'cov', '--ts' ], { cwd })
// .debug()
.expect('stdout', process.env.NYC_ROOT_ID ? /Coverage summary/ : /Statements.*100%/)
.expect('code', 0)
.end();
});
});

describe('error stacks', () => {
Expand Down

0 comments on commit 3b370ef

Please sign in to comment.