diff --git a/tests/__tests__/rel-config-paths.spec.ts b/tests/__tests__/rel-config-paths.spec.ts new file mode 100644 index 0000000000..eba5218699 --- /dev/null +++ b/tests/__tests__/rel-config-paths.spec.ts @@ -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"', + ); + }); +}); diff --git a/tests/rel-config-paths/config/jest.config.invalid.js b/tests/rel-config-paths/config/jest.config.invalid.js new file mode 100644 index 0000000000..4f0b49dfe3 --- /dev/null +++ b/tests/rel-config-paths/config/jest.config.invalid.js @@ -0,0 +1,14 @@ +module.exports = { + errorOnDeprecated: true, + globals: { + 'ts-jest': { + tsConfigFile: './tsconfig.test.json', + }, + }, + moduleFileExtensions: ['js', 'jsx', 'json', 'ts', 'tsx'], + rootDir: '../', + testMatch: ['/custom-test-dir/**/*.ts'], + transform: { + '^.+\\.tsx?$': 'ts-jest', + }, +}; diff --git a/tests/rel-config-paths/config/jest.config.js b/tests/rel-config-paths/config/jest.config.js new file mode 100644 index 0000000000..790e32b891 --- /dev/null +++ b/tests/rel-config-paths/config/jest.config.js @@ -0,0 +1,14 @@ +module.exports = { + errorOnDeprecated: true, + globals: { + 'ts-jest': { + tsConfigFile: '/config/tsconfig.test.json', + }, + }, + moduleFileExtensions: ['js', 'jsx', 'json', 'ts', 'tsx'], + rootDir: '../', + testMatch: ['/custom-test-dir/**/*.ts'], + transform: { + '^.+\\.tsx?$': 'ts-jest', + }, +}; diff --git a/tests/rel-config-paths/config/tsconfig.base.json b/tests/rel-config-paths/config/tsconfig.base.json new file mode 100644 index 0000000000..3a7fb4da10 --- /dev/null +++ b/tests/rel-config-paths/config/tsconfig.base.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "baseUrl": "../", + "outDir": "../dist" + } +} diff --git a/tests/rel-config-paths/config/tsconfig.test.json b/tests/rel-config-paths/config/tsconfig.test.json new file mode 100644 index 0000000000..8000a52a3a --- /dev/null +++ b/tests/rel-config-paths/config/tsconfig.test.json @@ -0,0 +1,6 @@ +{ + "extends": "./tsconfig.base.json", + "include": [ + "../custom-test-dir" + ] +} diff --git a/tests/rel-config-paths/custom-test-dir/test.ts b/tests/rel-config-paths/custom-test-dir/test.ts new file mode 100644 index 0000000000..e1db5bd814 --- /dev/null +++ b/tests/rel-config-paths/custom-test-dir/test.ts @@ -0,0 +1,9 @@ +declare var jest, describe, it, expect; + +import { hi } from '../src'; + +describe('hi', () => { + it('should say hi', () => { + expect(hi()).toBe('HI!'); + }); +}); diff --git a/tests/rel-config-paths/package.json b/tests/rel-config-paths/package.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/tests/rel-config-paths/package.json @@ -0,0 +1 @@ +{} diff --git a/tests/rel-config-paths/src/index.ts b/tests/rel-config-paths/src/index.ts new file mode 100644 index 0000000000..56966913e9 --- /dev/null +++ b/tests/rel-config-paths/src/index.ts @@ -0,0 +1,3 @@ +export function hi() { + return 'HI!'; +}