forked from kulshekhar/ts-jest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue kulshekhar#8 fix. Test and dependencies refactoring.
- Loading branch information
Showing
14 changed files
with
208 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
const path = require.requireActual('path'); | ||
const mockePath = jest.genMockFromModule('path'); | ||
|
||
// This is a custom function that our tests can use during setup to specify | ||
// what the files on the "mock" filesystem should look like when any of the | ||
// `fs` APIs are used. | ||
let baseDir = ''; | ||
function __setBaseDir(newBaseDir) { | ||
baseDir = newBaseDir; | ||
} | ||
|
||
// A custom version of `readdirSync` that reads from the special mocked out | ||
// file list set via __setMockFiles | ||
function resolve(args) { | ||
return path.resolve(baseDir, args) | ||
} | ||
|
||
mockePath.__setBaseDir = __setBaseDir; | ||
mockePath.resolve = resolve; | ||
|
||
module.exports = mockePath; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
const runJest = require('../__helpers__/runJest'); | ||
|
||
describe('hello_world', () => { | ||
|
||
it('should run successfully', () => { | ||
|
||
const result = runJest('../simple', ['--no-cache']); | ||
|
||
const stderr = result.stderr.toString(); | ||
const output = result.output.toString(); | ||
|
||
expect(result.status).toBe(1); | ||
expect(output).toContain('1 failed, 1 total'); | ||
expect(stderr).toContain('Hello Class'); | ||
expect(stderr).toContain('should throw an error on line 11'); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
|
||
jest.mock('path'); | ||
|
||
describe('hello_world', () => { | ||
|
||
beforeEach(() => { | ||
// Set up some mocked out file info before each test | ||
require('path').__setBaseDir('./tests/tsconfig-default'); | ||
}); | ||
|
||
it('should run successfully', () => { | ||
const {getTSConfig} = require('../../utils'); | ||
const result = getTSConfig(); | ||
|
||
expect(result).toEqual ({ | ||
"sourceMap": false, | ||
"declaration": false, | ||
"target": 2, | ||
"module": 1, | ||
"moduleResolution": 2, | ||
"noEmitOnError": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitAny": false, | ||
"noImplicitReturns": true, | ||
"removeComments": true, | ||
"strictNullChecks": true, | ||
"jsx": 2, | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"allowSyntheticDefaultImports": false | ||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict'; | ||
|
||
jest.mock('path'); | ||
|
||
describe('hello_world', () => { | ||
|
||
beforeEach(() => { | ||
// Set up some mocked out file info before each test | ||
require('path').__setBaseDir('./tests/tsconfig-string'); | ||
}); | ||
|
||
it('should run successfully', () => { | ||
const {getTSConfig} = require('../../utils'); | ||
const result = getTSConfig({ | ||
"__TS_CONFIG__": "my-tsconfig.json" | ||
}); | ||
|
||
expect(result).toEqual ({ | ||
"sourceMap": false, | ||
"declaration": false, | ||
"target": 2, | ||
"module": 1, | ||
"moduleResolution": 2, | ||
"noEmitOnError": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitAny": false, | ||
"noImplicitReturns": true, | ||
"removeComments": true, | ||
"strictNullChecks": true, | ||
"jsx": 2, | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"allowSyntheticDefaultImports": false | ||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
const runJest = require('../__helpers__/runJest'); | ||
|
||
describe('button', () => { | ||
|
||
it('should run successfully', () => { | ||
|
||
const result = runJest('../button', ['--no-cache', '-u']); | ||
|
||
const stderr = result.stderr.toString(); | ||
const output = result.output.toString(); | ||
|
||
expect(result.status).toBe(1); | ||
expect(output).toContain('1 failed, 1 passed, 2 total'); | ||
expect(stderr).toContain('Button renders correctly'); | ||
expect(stderr).toContain('BadButton should throw an error on line 18'); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"compilerOptions": { | ||
"sourceMap": false, | ||
"declaration": false, | ||
"target": "ES6", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"noEmitOnError": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitAny": false, | ||
"noImplicitReturns": true, | ||
"removeComments": true, | ||
"strictNullChecks": true, | ||
"jsx": "react", | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"allowSyntheticDefaultImports": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"compilerOptions": { | ||
"sourceMap": false, | ||
"declaration": false, | ||
"target": "ES6", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"noEmitOnError": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitAny": false, | ||
"noImplicitReturns": true, | ||
"removeComments": true, | ||
"strictNullChecks": true, | ||
"jsx": "react", | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"allowSyntheticDefaultImports": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const tsc = require('typescript'); | ||
const path = require('path'); | ||
|
||
function getTSConfig(globals) { | ||
let config = globals && globals.__TS_CONFIG__; | ||
if (config === undefined) { | ||
config = require(path.resolve('tsconfig.json')).compilerOptions; | ||
} | ||
if (typeof config === 'string') { | ||
config = require(path.resolve(config)).compilerOptions; | ||
} | ||
config.module = config.module || tsc.ModuleKind.CommonJS; | ||
config.jsx = config.jsx || tsc.JsxEmit.React; | ||
|
||
return tsc.convertCompilerOptionsFromJson(config).options; | ||
} | ||
|
||
module.exports = { | ||
getTSConfig | ||
} |