Skip to content
Permalink
Browse files

fix: auto add .setup.ts file (#147)

* fix(test): auto add .setup.ts file

* add unit test
  • Loading branch information
angleshe authored and whxaxes committed Jan 2, 2020
1 parent c40f13a commit 00afdf7e0237a42360ffd40513cb0b11467efbb5
@@ -163,7 +163,7 @@ class TestCommand extends Command {
}

// auto add setup file as the first test file
const setupFile = path.join(process.cwd(), 'test/.setup.js');
const setupFile = path.join(process.cwd(), `test/.setup.${testArgv.typescript ? 'ts' : 'js'}`);
if (fs.existsSync(setupFile)) {
files.unshift(setupFile);
}
@@ -0,0 +1,6 @@
{
"name": "ts",
"egg": {
"framework": "aliyun-egg"
}
}
@@ -0,0 +1,6 @@
before(() => {
console.log('this is a before function');
});
afterEach(() => {
console.log('is end!');
})
@@ -0,0 +1,7 @@
'use strict';

describe('a.test.ts', () => {
it('test', () => {
console.log('hello egg');
});
});
@@ -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
},
}
@@ -122,6 +122,7 @@ describe('test/lib/cmd/test.test.js', () => {

it('should auto require test/.setup.js', () => {
// example: https://github.com/lelandrichardson/enzyme-example-mocha
mm(process.env, 'TESTS', 'test/Foo.test.js');
return coffee.fork(eggBin, [ 'test' ], { cwd: path.join(__dirname, '../../fixtures/enzyme-example-mocha') })
// .debug()
.expect('stdout', /before hook: delay 10ms/)
@@ -130,6 +131,16 @@ describe('test/lib/cmd/test.test.js', () => {
.end();
});

it('should auto require test/.setup.ts', () => {
// example: https://github.com/lelandrichardson/enzyme-example-mocha
mm(process.env, 'TESTS', 'test/a.test.ts');
return coffee.fork(eggBin, [ 'test', '--typescript' ], { cwd: path.join(__dirname, '../../fixtures/setup-ts') })
.expect('stdout', /this is a before function/)
.expect('stdout', /hello egg/)
.expect('stdout', /is end!/)
.expect('code', 0)
.end();
});
it('should force exit', () => {
const cwd = path.join(__dirname, '../../fixtures/no-exit');
return coffee.fork(eggBin, [ 'test' ], { cwd })
@@ -140,6 +151,7 @@ describe('test/lib/cmd/test.test.js', () => {

it('run not test with dry-run option', () => {
const cwd = path.join(__dirname, '../../fixtures/mocha-test');
mm(process.env, 'TESTS', 'test/foo.test.js');
return coffee.fork(eggBin, [ 'test', '--timeout=12345', '--dry-run' ], { cwd })
.expect('stdout', [
/_mocha/g,

0 comments on commit 00afdf7

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