Skip to content

Commit

Permalink
chore(test): add tests for newly added codes
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnpnl committed Dec 30, 2019
1 parent 50685db commit 5ee0805
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/__mocks__/.babelrc-foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
2 changes: 2 additions & 0 deletions src/__mocks__/babel-foo.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module.exports = {
}
42 changes: 42 additions & 0 deletions src/config/__snapshots__/config-set.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,48 @@ Object {
}
`;

exports[`tsJest babelConfig should be correct for given javascript file path 1`] = `
Object {
"babelrc": false,
"configFile": false,
"cwd": "/Users/ahn/ts-jest",
"envName": "test",
"filename": undefined,
"passPerPreset": false,
"plugins": Array [],
"presets": Array [],
"root": "/Users/ahn/ts-jest",
}
`;

exports[`tsJest babelConfig should be correct for given non javascript file path 1`] = `
Object {
"babelrc": false,
"configFile": false,
"cwd": "/Users/ahn/ts-jest",
"envName": "test",
"filename": undefined,
"passPerPreset": false,
"plugins": Array [],
"presets": Array [],
"root": "/Users/ahn/ts-jest",
}
`;

exports[`tsJest babelConfig should be correct for imported javascript file 1`] = `
Object {
"babelrc": false,
"configFile": false,
"cwd": "/Users/ahn/ts-jest/src",
"envName": "test",
"filename": undefined,
"passPerPreset": false,
"plugins": Array [],
"presets": Array [],
"root": "/Users/ahn/ts-jest/src",
}
`;

exports[`tsJest should return correct defaults 1`] = `
Object {
"babelConfig": undefined,
Expand Down
46 changes: 39 additions & 7 deletions src/config/config-set.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ describe('tsJest', () => {
expect(get().babelConfig).toBeUndefined()
expect(get({ babelConfig: false }).babelConfig).toBeUndefined()
})

it('should be correct for true', () => {
const EXPECTED = {
kind: 'file',
Expand All @@ -146,13 +147,44 @@ describe('tsJest', () => {
expect(get({ babelConfig: true }).babelConfig).toEqual(EXPECTED)
})

it('should be correct for given file', () => {
const FILE = 'bar/.babelrc-foo'
const EXPECTED = {
kind: 'file',
value: defaultResolve(FILE),
}
expect(get({ babelConfig: FILE }).babelConfig).toEqual(EXPECTED)
it('should be correct for given non javascript file path', () => {
const FILE = 'src/__mocks__/.babelrc-foo'
const cs = createConfigSet({
tsJestConfig: {
babelConfig: FILE,
},
resolve: null,
})
expect(cs.tsJest.babelConfig!.kind).toEqual('file')
expect(cs.tsJest.babelConfig!.value).toContain(FILE)
expect(cs.babel).toMatchSnapshot()
})

it('should be correct for given javascript file path', () => {
const FILE = 'src/__mocks__/babel-foo.config.js'
const cs = createConfigSet({
tsJestConfig: {
babelConfig: FILE,
},
resolve: null,
})
expect(cs.tsJest.babelConfig!.kind).toEqual('file')
expect(cs.tsJest.babelConfig!.value).toContain(FILE)
expect(cs.babel).toMatchSnapshot()
})

it('should be correct for imported javascript file', () => {
const FILE = '__mocks__/babel-foo.config.js'
const cs = createConfigSet({
jestConfig: { rootDir: 'src', cwd: 'src' } as any,
tsJestConfig: {
babelConfig: FILE,
},
resolve: null,
})
expect(cs.tsJest.babelConfig!.kind).toEqual('file')
expect(cs.tsJest.babelConfig!.value).toContain(FILE)
expect(cs.babel).toMatchSnapshot()
})

it('should be correct for inline config', () => {
Expand Down

0 comments on commit 5ee0805

Please sign in to comment.