-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(typescript): Add support for create-react-app using Typescript (#48
) Add support for create-react-app-ts projects * Add a sample create-react-app-ts project * Add ConfigLoader for CRA (TypeScript) * Update README BREAKING CHANGE: Require Jest 22.x or higher. Support for 20.x and 21.x is dropped.
- Loading branch information
1 parent
e939d25
commit 7cc9b86
Showing
35 changed files
with
12,738 additions
and
170 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
2 changes: 1 addition & 1 deletion
2
packages/stryker-jest-runner/src/configLoaders/ReactScriptsJestConfigLoader.ts
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
35 changes: 35 additions & 0 deletions
35
packages/stryker-jest-runner/src/configLoaders/ReactScriptsTSJestConfigLoader.ts
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,35 @@ | ||
import JestConfigLoader from './JestConfigLoader'; | ||
import { createReactTsJestConfig } from '../utils/createReactJestConfig'; | ||
import * as path from 'path'; | ||
import JestConfiguration from './JestConfiguration'; | ||
|
||
export default class ReactScriptsTSJestConfigLoader implements JestConfigLoader { | ||
private loader: NodeRequire; | ||
private projectRoot: string; | ||
|
||
public constructor(projectRoot: string, loader?: NodeRequire) { | ||
this.loader = loader || /* istanbul ignore next */ require; | ||
this.projectRoot = projectRoot; | ||
} | ||
|
||
public loadConfig(): JestConfiguration { | ||
// Get the location of react-ts script, this is later used to generate the Jest configuration used for React projects. | ||
const reactScriptsTsLocation = path.join(this.loader.resolve('react-scripts-ts/package.json'), '..'); | ||
|
||
// Create the React configuration for Jest | ||
const jestConfiguration = this.createJestConfig(reactScriptsTsLocation); | ||
|
||
// Set test environment to jsdom (otherwise Jest won't run) | ||
jestConfiguration.testEnvironment = 'jsdom'; | ||
|
||
return jestConfiguration; | ||
} | ||
|
||
private createJestConfig(reactScriptsTsLocation: string): any { | ||
return createReactTsJestConfig( | ||
(relativePath: string): string => path.join(reactScriptsTsLocation, relativePath), | ||
this.projectRoot, | ||
false | ||
); | ||
} | ||
} |
23 changes: 0 additions & 23 deletions
23
packages/stryker-jest-runner/src/jestTestAdapters/JestCallbackTestAdapter.ts
This file was deleted.
Oops, something went wrong.
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
12 changes: 7 additions & 5 deletions
12
packages/stryker-jest-runner/src/jestTestAdapters/JestTestAdapterFactory.ts
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
14 changes: 11 additions & 3 deletions
14
packages/stryker-jest-runner/src/utils/createReactJestConfig.ts
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 |
---|---|---|
@@ -1,5 +1,13 @@ | ||
export default function createReactJestConfig(resolve: Function, projectRoot: string, ejected: boolean, loader?: NodeRequire): string { | ||
const resolveCreateJestConfig = (path: string, loader?: NodeRequire): Function => { | ||
loader = loader || /* istanbul ignore next */ require; | ||
|
||
return loader('react-scripts/scripts/utils/createJestConfig')(resolve, projectRoot, ejected); | ||
} | ||
return loader(path); | ||
}; | ||
|
||
export function createReactJestConfig(resolve: Function, projectRoot: string, ejected: boolean, loader?: NodeRequire): string { | ||
return resolveCreateJestConfig('react-scripts/scripts/utils/createJestConfig', loader)(resolve, projectRoot, ejected); | ||
} | ||
|
||
export function createReactTsJestConfig(resolve: Function, projectRoot: string, ejected: boolean, loader?: NodeRequire): string { | ||
return resolveCreateJestConfig('react-scripts-ts/scripts/utils/createJestConfig', loader)(resolve, projectRoot, ejected); | ||
} |
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
Oops, something went wrong.