Skip to content

Commit ca697f2

Browse files
committed
test: implement more real-world testing ability
1 parent f2565d3 commit ca697f2

21 files changed

Lines changed: 303 additions & 13 deletions

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,10 @@ jspm_packages
4545
.idea
4646

4747

48-
# Long paths
48+
# tests specific
4949
tests/simple-long-path/long-src-path
50+
# is linked to the temp dir of the os
51+
e2e/__e2e_workdir_link__
52+
53+
# binaries
54+
*.tgz
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "ts-jest-e2e-tmpl",
3+
"version": "0.0.0-test.0",
4+
"private": true
5+
}

e2e/__cases__/simple/Hello.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export class Hello {
2+
constructor(readonly msg: string) {}
3+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
declare var jest, describe, it, expect;
2+
3+
import { Hello } from '../Hello';
4+
5+
describe('Hello Class', () => {
6+
it('should create a new Hello', () => {
7+
const hello = new Hello('foo');
8+
expect(hello.msg).toBe('foo');
9+
});
10+
});

e2e/__cases__/simple/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"jest": {
3+
"transform": {
4+
"^.+\\.tsx?$": "ts-jest"
5+
},
6+
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
7+
"moduleFileExtensions": ["ts", "js"],
8+
"testEnvironment": "node"
9+
}
10+
}

e2e/__cases__/simple/tsconfig.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
}
5+
}

e2e/__tests__/e2e-simple.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { runE2eTest } from '../../tests/__helpers__/jest-runner';
2+
3+
describe('Simple e2e test', () => {
4+
it('should run the tests with success', () => {
5+
expect('simple').toBeE2eTestWithExitCode(0);
6+
});
7+
});

jest.config.e2e.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const base = require('./jest.config');
2+
3+
module.exports = Object.assign({}, base, {
4+
testRegex: 'e2e/__tests__/.*(?!watch)\\.spec\\.ts$',
5+
});

jest.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
transform: {
3+
'^.+\\.tsx?$': '<rootDir>/dist/index.js',
4+
},
5+
testRegex: '(tests|e2e)/__tests__/.+\\.spec\\.ts$',
6+
testPathIgnorePatterns: ['/node_modules/', '/watch.spec.ts$'],
7+
coverageReporters: ['text'],
8+
coverageDirectory: 'test_coverage_dir',
9+
collectCoverageFrom: ['src/**/*.tsx', 'src/**/*.ts'],
10+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
11+
globals: {
12+
'ts-jest': {
13+
tsConfigFile: 'tsconfig.base.json',
14+
},
15+
},
16+
setupTestFrameworkScriptFile:
17+
'<rootDir>/tests/__helpers__/setup-test-framework.ts',
18+
};

jest.config.tests.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const base = require('./jest.config');
2+
3+
module.exports = Object.assign({}, base, {
4+
testRegex: 'tests/__tests__/.*(?!watch)\\.spec\\.ts$',
5+
});

0 commit comments

Comments
 (0)