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(test): auto add .setup.ts file #147

Merged
merged 2 commits into from
Jan 2, 2020
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
2 changes: 1 addition & 1 deletion lib/cmd/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/setup-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "ts",
"egg": {
"framework": "aliyun-egg"
}
}
6 changes: 6 additions & 0 deletions test/fixtures/setup-ts/test/.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
before(() => {
console.log('this is a before function');
});
afterEach(() => {
console.log('is end!');
})
7 changes: 7 additions & 0 deletions test/fixtures/setup-ts/test/a.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

describe('a.test.ts', () => {
it('test', () => {
console.log('hello egg');
});
});
19 changes: 19 additions & 0 deletions test/fixtures/setup-ts/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
},
}
12 changes: 12 additions & 0 deletions test/lib/cmd/test.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand All @@ -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 })
Expand All @@ -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,
Expand Down