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

fix: nyc shim #138

Merged
merged 7 commits into from
Sep 27, 2019
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 .gitignore
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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