Skip to content

Commit

Permalink
test(preset): e2e test for added presets
Browse files Browse the repository at this point in the history
  • Loading branch information
huafu committed Sep 24, 2018
1 parent 9f3d759 commit ad8f6d1
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 8 deletions.
5 changes: 5 additions & 0 deletions e2e/__cases__/allow-js/esm.spec.js
@@ -0,0 +1,5 @@
import * as bar from './bar'

test('esm', () => {
expect(bar).toBe('BAR!')
})
5 changes: 5 additions & 0 deletions e2e/__cases__/preset-with-babel/.babelrc
@@ -0,0 +1,5 @@
{
"presets": [
"@babel/preset-env"
]
}
3 changes: 3 additions & 0 deletions e2e/__cases__/preset-with-babel/main.spec.js
@@ -0,0 +1,3 @@
test('spread', () => {
expect({ ...{ bar: 'foo' }, foo: 'bar' }).toEqual({ foo: 'bar', bar: 'foo' })
})
6 changes: 6 additions & 0 deletions e2e/__helpers__/templates.ts
Expand Up @@ -14,3 +14,9 @@ export const allValidPackageSets = [
PackageSets.jest22,
PackageSets.typescript2_7,
]
export const allPackageSetsWithPreset = [
PackageSets.default,
PackageSets.babel6,
PackageSets.babel7,
PackageSets.typescript2_7,
]
78 changes: 73 additions & 5 deletions 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 ]===================================================================
Expand All @@ -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 ]===================================================================
Expand All @@ -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 ]===================================================================
Expand All @@ -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 ]===================================================================
Expand All @@ -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 ]===================================================================
Expand All @@ -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.
================================================================================
`;
26 changes: 23 additions & 3 deletions 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, () => {
Expand All @@ -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()
})
})
})
18 changes: 18 additions & 0 deletions 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["']/)
})
})
})

0 comments on commit ad8f6d1

Please sign in to comment.