Skip to content
Permalink
Browse files

fix: nyc shim (#138)

  • Loading branch information
ahungrynoob authored and atian25 committed Sep 27, 2019
1 parent 188c29c commit 3b370ef998b65e1a5f0390a7aa5f0fb4d2e96a7d
@@ -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/
@@ -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:
@@ -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;
@@ -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}`);
};
@@ -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;
}
}
@@ -0,0 +1,7 @@
'use strict';

import { Application } from 'egg';

export default (app: Application) => {
app.router.get('/', app.controller.home.index);
};
@@ -0,0 +1,7 @@
'use strict';

export default () => {
const config = {} as any;
config.keys = '123456';
return config;
};

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

@@ -0,0 +1,6 @@
{
"name": "example-ts",
"egg": {
"typescript": true
}
}
@@ -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);
});
});
@@ -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
},
}
@@ -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;
}
}
@@ -0,0 +1,3 @@
interface PlainObject extends Object {
[key: string]: any;
}
@@ -0,0 +1,7 @@
import { Context } from 'egg';

// extend egg
declare module 'egg' {
interface Context {
}
}
@@ -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', () => {

0 comments on commit 3b370ef

Please sign in to comment.
You can’t perform that action at this time.