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(config): set default outDir when allowJs is true and no outDir in tsconfig #1502

Merged
merged 1 commit into from Apr 4, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions e2e/__cases__/allow-js/without-outDir/bar.spec.ts
@@ -0,0 +1,10 @@
import * as foo from './foo'
import bar = require('./bar')

test('foo', () => {
expect(foo).toBe('FOO!')
})

test('bar', () => {
expect(bar).toBe('BAR!')
})
1 change: 1 addition & 0 deletions e2e/__cases__/allow-js/without-outDir/bar.ts
@@ -0,0 +1 @@
export = 'BAR!'
5 changes: 5 additions & 0 deletions e2e/__cases__/allow-js/without-outDir/esm.spec.js
@@ -0,0 +1,5 @@
import * as bar from './bar'

test('esm', () => {
expect(bar).toBe('BAR!')
})
1 change: 1 addition & 0 deletions e2e/__cases__/allow-js/without-outDir/foo.js
@@ -0,0 +1 @@
module.exports = 'FOO!'
10 changes: 10 additions & 0 deletions e2e/__cases__/allow-js/without-outDir/foo.spec.js
@@ -0,0 +1,10 @@
const foo = require('./foo')
const bar = require('./bar')

test('foo', () => {
expect(foo).toBe('FOO!')
})

test('bar', () => {
expect(bar).toBe('BAR!')
})
6 changes: 6 additions & 0 deletions e2e/__cases__/allow-js/without-outDir/tsconfig.json
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"target": "es5",
"allowJs": true
}
}
76 changes: 72 additions & 4 deletions e2e/__tests__/__snapshots__/allow-js.test.ts.snap
Expand Up @@ -68,7 +68,7 @@ exports[`using babel-jest for js files should pass using template "with-typescri
================================================================================
`;

exports[`using ts-jest for js files should pass using template "default" 1`] = `
exports[`using ts-jest for js files with outDir should pass using template "default" 1`] = `
√ jest
↳ exit code: 0
===[ STDOUT ]===================================================================
Expand All @@ -85,7 +85,7 @@ exports[`using ts-jest for js files should pass using template "default" 1`] = `
================================================================================
`;

exports[`using ts-jest for js files should pass using template "with-babel-7" 1`] = `
exports[`using ts-jest for js files with outDir should pass using template "with-babel-7" 1`] = `
√ jest
↳ exit code: 0
===[ STDOUT ]===================================================================
Expand All @@ -102,7 +102,7 @@ exports[`using ts-jest for js files should pass using template "with-babel-7" 1`
================================================================================
`;

exports[`using ts-jest for js files should pass using template "with-babel-7-string-config" 1`] = `
exports[`using ts-jest for js files with outDir should pass using template "with-babel-7-string-config" 1`] = `
√ jest
↳ exit code: 0
===[ STDOUT ]===================================================================
Expand All @@ -119,7 +119,75 @@ exports[`using ts-jest for js files should pass using template "with-babel-7-str
================================================================================
`;

exports[`using ts-jest for js files should pass using template "with-typescript-2-7" 1`] = `
exports[`using ts-jest for js files with outDir should pass using template "with-typescript-2-7" 1`] = `
√ jest
↳ exit code: 0
===[ STDOUT ]===================================================================

===[ STDERR ]===================================================================
PASS ./esm.spec.js
√ esm

Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: XXs
Ran all test suites.
================================================================================
`;

exports[`using ts-jest for js files without outDir should pass using template "default" 1`] = `
√ jest
↳ exit code: 0
===[ STDOUT ]===================================================================

===[ STDERR ]===================================================================
PASS ./esm.spec.js
√ esm

Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: XXs
Ran all test suites.
================================================================================
`;

exports[`using ts-jest for js files without outDir should pass using template "with-babel-7" 1`] = `
√ jest
↳ exit code: 0
===[ STDOUT ]===================================================================

===[ STDERR ]===================================================================
PASS ./esm.spec.js
√ esm

Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: XXs
Ran all test suites.
================================================================================
`;

exports[`using ts-jest for js files without outDir should pass using template "with-babel-7-string-config" 1`] = `
√ jest
↳ exit code: 0
===[ STDOUT ]===================================================================

===[ STDERR ]===================================================================
PASS ./esm.spec.js
√ esm

Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: XXs
Ran all test suites.
================================================================================
`;

exports[`using ts-jest for js files without outDir should pass using template "with-typescript-2-7" 1`] = `
√ jest
↳ exit code: 0
===[ STDOUT ]===================================================================
Expand Down
24 changes: 21 additions & 3 deletions e2e/__tests__/allow-js.test.ts
Expand Up @@ -2,7 +2,7 @@ import { allPackageSetsWithPreset, allValidPackageSets } from '../__helpers__/te
import { configureTestCase } from '../__helpers__/test-case'

describe('using babel-jest for js files', () => {
const testCase = configureTestCase('allow-js', {
const testCase = configureTestCase('allow-js/with-outDir', {
jestConfig: { testMatch: null, testRegex: '(foo|bar)\\.spec\\.[jt]s$' },
})

Expand All @@ -15,8 +15,26 @@ describe('using babel-jest for js files', () => {
})
})

describe('using ts-jest for js files', () => {
const testCase = configureTestCase('allow-js', {
describe('using ts-jest for js files with outDir', () => {
const testCase = configureTestCase('allow-js/with-outDir', {
jestConfig: {
preset: 'ts-jest/presets/js-with-ts',
testMatch: null,
testRegex: 'esm\\.spec\\.[jt]s$',
},
})

testCase.runWithTemplates(allPackageSetsWithPreset, 0, (runTest, { testLabel }) => {
it(testLabel, () => {
const result = runTest()
expect(result.status).toBe(0)
expect(result).toMatchSnapshot()
})
})
})

describe('using ts-jest for js files without outDir', () => {
const testCase = configureTestCase('allow-js/without-outDir', {
jestConfig: {
preset: 'ts-jest/presets/js-with-ts',
testMatch: null,
Expand Down
28 changes: 23 additions & 5 deletions src/compiler/__snapshots__/language-service.spec.ts.snap
@@ -1,17 +1,35 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`language service should compile js file for allowJs true 1`] = `
===[ FILE: test-allow-js.js ]===================================================
exports[`language service should compile js file for allowJs true with outDir 1`] = `
===[ FILE: test-allow-js-with-outDir.js ]=======================================
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = 42;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJmaWxlIjoidGVzdC1hbGxvdy1qcy5qcyIsIm1hcHBpbmdzIjoiOztBQUFBLGtCQUFlLEVBQUUsQ0FBQSIsIm5hbWVzIjpbXSwic291cmNlcyI6WyJ0ZXN0LWFsbG93LWpzLmpzIl0sInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCBkZWZhdWx0IDQyIl0sInZlcnNpb24iOjN9
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJmaWxlIjoidGVzdC1hbGxvdy1qcy13aXRoLW91dERpci5qcyIsIm1hcHBpbmdzIjoiOztBQUFBLGtCQUFlLEVBQUUsQ0FBQSIsIm5hbWVzIjpbXSwic291cmNlcyI6WyJ0ZXN0LWFsbG93LWpzLXdpdGgtb3V0RGlyLmpzIl0sInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCBkZWZhdWx0IDQyIl0sInZlcnNpb24iOjN9
===[ INLINE SOURCE MAPS ]=======================================================
file: test-allow-js.js
file: test-allow-js-with-outDir.js
mappings: ';;AAAA,kBAAe,EAAE,CAAA'
names: []
sources:
- test-allow-js.js
- test-allow-js-with-outDir.js
sourcesContent:
- export default 42
version: 3
================================================================================
`;

exports[`language service should compile js file for allowJs true without outDir 1`] = `
===[ FILE: test-allow-js-no-outDir.js ]=========================================
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = 42;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJmaWxlIjoidGVzdC1hbGxvdy1qcy1uby1vdXREaXIuanMiLCJtYXBwaW5ncyI6Ijs7QUFBQSxrQkFBZSxFQUFFLENBQUEiLCJuYW1lcyI6W10sInNvdXJjZXMiOlsidGVzdC1hbGxvdy1qcy1uby1vdXREaXIuanMiXSwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IGRlZmF1bHQgNDIiXSwidmVyc2lvbiI6M30=
===[ INLINE SOURCE MAPS ]=======================================================
file: test-allow-js-no-outDir.js
mappings: ';;AAAA,kBAAe,EAAE,CAAA'
names: []
sources:
- test-allow-js-no-outDir.js
sourcesContent:
- export default 42
version: 3
Expand Down
56 changes: 46 additions & 10 deletions src/compiler/__snapshots__/program.spec.ts.snap
@@ -1,35 +1,71 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`allowJs should compile js file for allowJs true with incremental program 1`] = `
===[ FILE: test-allowJs.test.js ]===============================================
exports[`allowJs with incremental program should compile js file for allowJs true with outDir 1`] = `
===[ FILE: test-allowJs-incremental-outDir.test.js ]============================
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = 42;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJmaWxlIjoidGVzdC1hbGxvd0pzLnRlc3QuanMiLCJtYXBwaW5ncyI6Ijs7QUFBQSxrQkFBZSxFQUFFLENBQUEiLCJuYW1lcyI6W10sInNvdXJjZXMiOlsidGVzdC1hbGxvd0pzLnRlc3QuanMiXSwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IGRlZmF1bHQgNDIiXSwidmVyc2lvbiI6M30=
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJmaWxlIjoidGVzdC1hbGxvd0pzLWluY3JlbWVudGFsLW91dERpci50ZXN0LmpzIiwibWFwcGluZ3MiOiI7O0FBQUEsa0JBQWUsRUFBRSxDQUFBIiwibmFtZXMiOltdLCJzb3VyY2VzIjpbInRlc3QtYWxsb3dKcy1pbmNyZW1lbnRhbC1vdXREaXIudGVzdC5qcyJdLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgZGVmYXVsdCA0MiJdLCJ2ZXJzaW9uIjozfQ==
===[ INLINE SOURCE MAPS ]=======================================================
file: test-allowJs.test.js
file: test-allowJs-incremental-outDir.test.js
mappings: ';;AAAA,kBAAe,EAAE,CAAA'
names: []
sources:
- test-allowJs.test.js
- test-allowJs-incremental-outDir.test.js
sourcesContent:
- export default 42
version: 3
================================================================================
`;

exports[`allowJs should compile js file for allowJs true with normal program 1`] = `
===[ FILE: test-allowJs.test.js ]===============================================
exports[`allowJs with incremental program should compile js file for allowJs true without outDir 1`] = `
===[ FILE: test-allowJs-incremental-no-outDir.test.js ]=========================
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = 42;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJmaWxlIjoidGVzdC1hbGxvd0pzLnRlc3QuanMiLCJtYXBwaW5ncyI6Ijs7QUFBQSxrQkFBZSxFQUFFLENBQUEiLCJuYW1lcyI6W10sInNvdXJjZXMiOlsidGVzdC1hbGxvd0pzLnRlc3QuanMiXSwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IGRlZmF1bHQgNDIiXSwidmVyc2lvbiI6M30=
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJmaWxlIjoidGVzdC1hbGxvd0pzLWluY3JlbWVudGFsLW5vLW91dERpci50ZXN0LmpzIiwibWFwcGluZ3MiOiI7O0FBQUEsa0JBQWUsRUFBRSxDQUFBIiwibmFtZXMiOltdLCJzb3VyY2VzIjpbInRlc3QtYWxsb3dKcy1pbmNyZW1lbnRhbC1uby1vdXREaXIudGVzdC5qcyJdLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgZGVmYXVsdCA0MiJdLCJ2ZXJzaW9uIjozfQ==
===[ INLINE SOURCE MAPS ]=======================================================
file: test-allowJs.test.js
file: test-allowJs-incremental-no-outDir.test.js
mappings: ';;AAAA,kBAAe,EAAE,CAAA'
names: []
sources:
- test-allowJs.test.js
- test-allowJs-incremental-no-outDir.test.js
sourcesContent:
- export default 42
version: 3
================================================================================
`;

exports[`allowJs with program should compile js file for allowJs true with outDir 1`] = `
===[ FILE: test-allowJs-program-outDir.test.js ]================================
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = 42;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJmaWxlIjoidGVzdC1hbGxvd0pzLXByb2dyYW0tb3V0RGlyLnRlc3QuanMiLCJtYXBwaW5ncyI6Ijs7QUFBQSxrQkFBZSxFQUFFLENBQUEiLCJuYW1lcyI6W10sInNvdXJjZXMiOlsidGVzdC1hbGxvd0pzLXByb2dyYW0tb3V0RGlyLnRlc3QuanMiXSwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IGRlZmF1bHQgNDIiXSwidmVyc2lvbiI6M30=
===[ INLINE SOURCE MAPS ]=======================================================
file: test-allowJs-program-outDir.test.js
mappings: ';;AAAA,kBAAe,EAAE,CAAA'
names: []
sources:
- test-allowJs-program-outDir.test.js
sourcesContent:
- export default 42
version: 3
================================================================================
`;

exports[`allowJs with program should compile js file for allowJs true without outDir 1`] = `
===[ FILE: test-allowJs-program-no-outDir.test.js ]=============================
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = 42;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJmaWxlIjoidGVzdC1hbGxvd0pzLXByb2dyYW0tbm8tb3V0RGlyLnRlc3QuanMiLCJtYXBwaW5ncyI6Ijs7QUFBQSxrQkFBZSxFQUFFLENBQUEiLCJuYW1lcyI6W10sInNvdXJjZXMiOlsidGVzdC1hbGxvd0pzLXByb2dyYW0tbm8tb3V0RGlyLnRlc3QuanMiXSwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IGRlZmF1bHQgNDIiXSwidmVyc2lvbiI6M30=
===[ INLINE SOURCE MAPS ]=======================================================
file: test-allowJs-program-no-outDir.test.js
mappings: ';;AAAA,kBAAe,EAAE,CAAA'
names: []
sources:
- test-allowJs-program-no-outDir.test.js
sourcesContent:
- export default 42
version: 3
Expand Down
21 changes: 18 additions & 3 deletions src/compiler/language-service.spec.ts
Expand Up @@ -60,10 +60,25 @@ describe('language service', () => {
removeSync(fileName)
})

it('should compile js file for allowJs true', () => {
const fileName = `test-allow-js.js`
it('should compile js file for allowJs true with outDir', () => {
const fileName = `test-allow-js-with-outDir.js`
const compiler = makeCompiler({
tsJestConfig: { tsConfig: { allowJs: true, outDir: '$$ts-jest$$' } },
tsJestConfig: { tsConfig: { allowJs: true, outDir: '$$foo$$' } },
})
const source = 'export default 42'

writeFileSync(fileName, source, 'utf8')
const compiled = compiler.compile(source, fileName)

expect(new ProcessedSource(compiled, fileName)).toMatchSnapshot()

removeSync(fileName)
})

it('should compile js file for allowJs true without outDir', () => {
const fileName = `test-allow-js-no-outDir.js`
const compiler = makeCompiler({
tsJestConfig: { tsConfig: { allowJs: true } },
})
const source = 'export default 42'

Expand Down