From ad8f6d104a79d450289df0ce41ec63589a869d15 Mon Sep 17 00:00:00 2001 From: Huafu Gandon Date: Mon, 24 Sep 2018 23:13:58 +0200 Subject: [PATCH] test(preset): e2e test for added presets --- e2e/__cases__/allow-js/esm.spec.js | 5 ++ e2e/__cases__/preset-with-babel/.babelrc | 5 ++ e2e/__cases__/preset-with-babel/main.spec.js | 3 + e2e/__helpers__/templates.ts | 6 ++ .../__snapshots__/allow-js.test.ts.snap | 78 +++++++++++++++++-- e2e/__tests__/allow-js.test.ts | 26 ++++++- e2e/__tests__/jest-presets.test.ts | 18 +++++ 7 files changed, 133 insertions(+), 8 deletions(-) create mode 100644 e2e/__cases__/allow-js/esm.spec.js create mode 100644 e2e/__cases__/preset-with-babel/.babelrc create mode 100644 e2e/__cases__/preset-with-babel/main.spec.js create mode 100644 e2e/__tests__/jest-presets.test.ts diff --git a/e2e/__cases__/allow-js/esm.spec.js b/e2e/__cases__/allow-js/esm.spec.js new file mode 100644 index 0000000000..4672def549 --- /dev/null +++ b/e2e/__cases__/allow-js/esm.spec.js @@ -0,0 +1,5 @@ +import * as bar from './bar' + +test('esm', () => { + expect(bar).toBe('BAR!') +}) diff --git a/e2e/__cases__/preset-with-babel/.babelrc b/e2e/__cases__/preset-with-babel/.babelrc new file mode 100644 index 0000000000..a29ac9986c --- /dev/null +++ b/e2e/__cases__/preset-with-babel/.babelrc @@ -0,0 +1,5 @@ +{ + "presets": [ + "@babel/preset-env" + ] +} diff --git a/e2e/__cases__/preset-with-babel/main.spec.js b/e2e/__cases__/preset-with-babel/main.spec.js new file mode 100644 index 0000000000..b804480001 --- /dev/null +++ b/e2e/__cases__/preset-with-babel/main.spec.js @@ -0,0 +1,3 @@ +test('spread', () => { + expect({ ...{ bar: 'foo' }, foo: 'bar' }).toEqual({ foo: 'bar', bar: 'foo' }) +}) diff --git a/e2e/__helpers__/templates.ts b/e2e/__helpers__/templates.ts index e367b63ef6..d1caae73f6 100644 --- a/e2e/__helpers__/templates.ts +++ b/e2e/__helpers__/templates.ts @@ -14,3 +14,9 @@ export const allValidPackageSets = [ PackageSets.jest22, PackageSets.typescript2_7, ] +export const allPackageSetsWithPreset = [ + PackageSets.default, + PackageSets.babel6, + PackageSets.babel7, + PackageSets.typescript2_7, +] diff --git a/e2e/__tests__/__snapshots__/allow-js.test.ts.snap b/e2e/__tests__/__snapshots__/allow-js.test.ts.snap index 33e8f288c0..d5369d6861 100644 --- a/e2e/__tests__/__snapshots__/allow-js.test.ts.snap +++ b/e2e/__tests__/__snapshots__/allow-js.test.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Allow JS test should pass using template "default" 1`] = ` +exports[`using babel-jest for js files should pass using template "default" 1`] = ` √ jest ↳ exit code: 0 ===[ STDOUT ]=================================================================== @@ -17,7 +17,7 @@ exports[`Allow JS test should pass using template "default" 1`] = ` ================================================================================ `; -exports[`Allow JS test should pass using template "with-babel-6" 1`] = ` +exports[`using babel-jest for js files should pass using template "with-babel-6" 1`] = ` √ jest ↳ exit code: 0 ===[ STDOUT ]=================================================================== @@ -34,7 +34,7 @@ exports[`Allow JS test should pass using template "with-babel-6" 1`] = ` ================================================================================ `; -exports[`Allow JS test should pass using template "with-babel-7" 1`] = ` +exports[`using babel-jest for js files should pass using template "with-babel-7" 1`] = ` √ jest ↳ exit code: 0 ===[ STDOUT ]=================================================================== @@ -51,7 +51,7 @@ exports[`Allow JS test should pass using template "with-babel-7" 1`] = ` ================================================================================ `; -exports[`Allow JS test should pass using template "with-jest-22" 1`] = ` +exports[`using babel-jest for js files should pass using template "with-jest-22" 1`] = ` √ jest ↳ exit code: 0 ===[ STDOUT ]=================================================================== @@ -68,7 +68,7 @@ exports[`Allow JS test should pass using template "with-jest-22" 1`] = ` ================================================================================ `; -exports[`Allow JS test should pass using template "with-typescript-2-7" 1`] = ` +exports[`using babel-jest for js files should pass using template "with-typescript-2-7" 1`] = ` √ jest ↳ exit code: 0 ===[ STDOUT ]=================================================================== @@ -84,3 +84,71 @@ exports[`Allow JS test should pass using template "with-typescript-2-7" 1`] = ` Ran all test suites. ================================================================================ `; + +exports[`using ts-jest for js files 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 should pass using template "with-babel-6" 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 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 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. + ================================================================================ +`; diff --git a/e2e/__tests__/allow-js.test.ts b/e2e/__tests__/allow-js.test.ts index b3a121b1a8..069aa58552 100644 --- a/e2e/__tests__/allow-js.test.ts +++ b/e2e/__tests__/allow-js.test.ts @@ -1,8 +1,10 @@ -import { allValidPackageSets } from '../__helpers__/templates' +import { allPackageSetsWithPreset, allValidPackageSets } from '../__helpers__/templates' import { configureTestCase } from '../__helpers__/test-case' -describe('Allow JS test', () => { - const testCase = configureTestCase('allow-js') +describe('using babel-jest for js files', () => { + const testCase = configureTestCase('allow-js', { + jestConfig: { testMatch: null, testRegex: '(foo|bar)\\.spec\\.[jt]s$' }, + }) testCase.runWithTemplates(allValidPackageSets, 0, (runTest, { testLabel }) => { it(testLabel, () => { @@ -12,3 +14,21 @@ describe('Allow JS test', () => { }) }) }) + +describe('using ts-jest for js files', () => { + const testCase = configureTestCase('allow-js', { + 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() + }) + }) +}) diff --git a/e2e/__tests__/jest-presets.test.ts b/e2e/__tests__/jest-presets.test.ts new file mode 100644 index 0000000000..730c6f0cf7 --- /dev/null +++ b/e2e/__tests__/jest-presets.test.ts @@ -0,0 +1,18 @@ +import { allPackageSetsWithPreset } from '../__helpers__/templates' +import { configureTestCase } from '../__helpers__/test-case' + +// 'ts-jest' is tested in almost all test cases +// 'ts-jest/presets/default' is an alias of the above +// 'ts-jest/presets/js-with-ts' is tested in allow-js.test.ts + +describe('ts-jest/presets/js-with-babel', () => { + const testCase = configureTestCase('preset-with-babel', { jestConfig: { preset: 'ts-jest/presets/js-with-babel' } }) + + testCase.runWithTemplates(allPackageSetsWithPreset, 1, (runTest, { testLabel }) => { + it(testLabel, () => { + const result = runTest() + expect(result.status).toBe(1) + expect(result.stderr).toMatch(/(Couldn't|Cannot) find (preset|module) ["']@babel\/preset-env["']/) + }) + }) +})