Skip to content

Commit

Permalink
test: adds a failing test for #636
Browse files Browse the repository at this point in the history
  • Loading branch information
huafu committed Jul 26, 2018
1 parent 68f8cb3 commit a4d000b
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/__tests__/rel-config-paths.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import runJest from '../__helpers__/runJest';

describe('Use jest config from config dir', () => {
it('Should run all tests resolving tsconfig extends', () => {
const result = runJest('../rel-config-paths', [
'--no-cache',
'--config=./config/jest.config.js',
]);

expect(result.status).toBe(0);
});

it('Should fail resolving tsconfig with wrong relative path', () => {
const result = runJest('../rel-config-paths', [
'--no-cache',
'--config=./config/jest.config.invalid.js',
]);

expect(result.status).toBe(1);
expect(result.stderr).toContain(
'Unable to find tsconfig file given "./tsconfig.test.json"',
);
});
});
14 changes: 14 additions & 0 deletions tests/rel-config-paths/config/jest.config.invalid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
errorOnDeprecated: true,
globals: {
'ts-jest': {
tsConfigFile: './tsconfig.test.json',
},
},
moduleFileExtensions: ['js', 'jsx', 'json', 'ts', 'tsx'],
rootDir: '../',
testMatch: ['<rootDir>/custom-test-dir/**/*.ts'],
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
};
14 changes: 14 additions & 0 deletions tests/rel-config-paths/config/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
errorOnDeprecated: true,
globals: {
'ts-jest': {
tsConfigFile: '<rootDir>/config/tsconfig.test.json',
},
},
moduleFileExtensions: ['js', 'jsx', 'json', 'ts', 'tsx'],
rootDir: '../',
testMatch: ['<rootDir>/custom-test-dir/**/*.ts'],
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
};
6 changes: 6 additions & 0 deletions tests/rel-config-paths/config/tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"baseUrl": "../",
"outDir": "../dist"
}
}
6 changes: 6 additions & 0 deletions tests/rel-config-paths/config/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig.base.json",
"include": [
"../custom-test-dir"
]
}
9 changes: 9 additions & 0 deletions tests/rel-config-paths/custom-test-dir/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare var jest, describe, it, expect;

import { hi } from '../src';

describe('hi', () => {
it('should say hi', () => {
expect(hi()).toBe('HI!');
});
});
1 change: 1 addition & 0 deletions tests/rel-config-paths/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 3 additions & 0 deletions tests/rel-config-paths/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function hi() {
return 'HI!';
}

0 comments on commit a4d000b

Please sign in to comment.