This repository has been archived by the owner on Feb 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(runner) Add support for Jest v20 (#16)
Add support for Jest v20.
- Loading branch information
1 parent
7bf2c86
commit ad9c282
Showing
5 changed files
with
88 additions
and
22 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,56 @@ | ||
const runTest = require('jest-cli/build/runTest'); | ||
const Runtime = require('jest-runtime'); | ||
|
||
const Console = require('console').Console; | ||
|
||
import * as log4js from 'log4js'; | ||
const log = log4js.getLogger('JestAdapter'); | ||
|
||
const console = new Console(process.stdout, process.stderr); | ||
|
||
/** | ||
* Interface to decouple the runner from various versions of Jest. | ||
* Since the runner hooks into some implementation modules of Jest, | ||
* we cannot expect the API's to be stable at this time. | ||
*/ | ||
abstract class JestAdapter { | ||
abstract buildHasteContext(options: any): Promise<any>; | ||
abstract runTest(path: string, options: any, resolver: any): Promise<any>; | ||
} | ||
|
||
class JestPre20Adapter extends JestAdapter { | ||
public buildHasteContext(options: any): Promise<any> { | ||
const { maxWorkers } = options; | ||
return Runtime.createHasteContext(options, { console, maxWorkers }); | ||
} | ||
|
||
public runTest(path: string, options: any, resolver: any): Promise<any> { | ||
return runTest(path, options, resolver); | ||
} | ||
} | ||
|
||
class JestPost20Adapter extends JestAdapter { | ||
public buildHasteContext(options: any): Promise<any> { | ||
const { maxWorkers } = options; | ||
return Runtime.createContext(options, { console, maxWorkers }); | ||
} | ||
|
||
public runTest(path: string, options: any, resolver: any): Promise<any> { | ||
const globalConfig = {}; | ||
return runTest(path, globalConfig, options, resolver); | ||
} | ||
} | ||
|
||
const findJestAdapter = () => { | ||
const pre20 = typeof Runtime.createHasteContext !== 'undefined'; | ||
log.info(`Detected Jest ${pre20 ? 'pre' : 'post'} v20.0.0`); | ||
const adapter = pre20 ? new JestPre20Adapter() : new JestPost20Adapter(); | ||
return (adapter as JestAdapter); | ||
}; | ||
|
||
export { | ||
JestAdapter, | ||
JestPre20Adapter, | ||
JestPost20Adapter, | ||
findJestAdapter, | ||
} |