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.
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
017139d
commit 7fa6e85
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
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,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 | ||
); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -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.