Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
require.cache[require.resolve('react-scripts/scripts/utils/createJestConfig')].exports = (
resolve,
rootDir,
isEjecting,
) => {
let config = createJestConfig(resolve, rootDir, isEjecting);
// check for the existence of a tests setup file
// also check for the same path with a .ts ext
if (!fs.existsSync(paths.testsSetup)) {
let hasSetup = false;
const ext = path.extname(paths.testsSetup).toLowerCase();
if (ext !== '.ts') {
const testsSetupTs = `${paths.testsSetup.substr(
0,
paths.testsSetup.length - ext.length,
)}.ts`;
if (fs.existsSync(testsSetupTs)) {
hasSetup = true;
config.setupTestFrameworkScriptFile = testsSetupTs;
}
}
if (!hasSetup) {
config.setupTestFrameworkScriptFile = path.resolve(__dirname, '../config/jest/setup.js');
}
}
config = {
...config,
testURL: 'http://localhost:8080',
transform: {
'^.+\\.(js|jsx)$': isEjecting
function rewireSetupTestFrameworkScriptFile(config: object): object {
// ref: create-react-app/packages/react-scripts/config/paths.js
// > testsSetup: resolveApp('src/setupTests.js'),
const setupTestsFile = [
// Check for TypeScript version of setupTests first.
[
reactScriptsPaths.testsSetup.replace(/\.js$/, ".ts"),
"/src/setupTests.ts"
],
// Use Javascript version if TypeScript version is not present.
[reactScriptsPaths.testsSetup, "/src/setupTests.js"]
].reduce((acc, [filePath, settingsValue]) => {
if (acc) return acc;
return fs.existsSync(filePath) ? settingsValue : undefined;
}, undefined);
return {
...config,
setupTestFrameworkScriptFile: setupTestsFile
};
}
require.cache[require.resolve('react-scripts/scripts/utils/createJestConfig')].exports = (
resolve,
rootDir,
isEjecting,
) => {
let config = createJestConfig(resolve, rootDir, isEjecting);
// check for the existence of a tests setup file
// also check for the same path with a .ts ext
if (!fs.existsSync(paths.testsSetup)) {
let hasSetup = false;
const ext = path.extname(paths.testsSetup).toLowerCase();
if (ext !== '.ts') {
const testsSetupTs = `${paths.testsSetup.substr(
0,
paths.testsSetup.length - ext.length,
)}.ts`;
if (fs.existsSync(testsSetupTs)) {
hasSetup = true;
config.setupTestFrameworkScriptFile = testsSetupTs;
}
}
if (!hasSetup) {
config.setupTestFrameworkScriptFile = path.resolve(__dirname, '../config/jest/setup.js');
}
}
config = {
...config,
transform: {
require.cache[require.resolve('react-scripts/scripts/utils/createJestConfig')].exports = (
resolve,
rootDir,
isEjecting,
) => {
let config = createJestConfig(resolve, rootDir, isEjecting);
// check for the existence of a tests setup file
// also check for the same path with a .ts ext
if (!fs.existsSync(paths.testsSetup)) {
let hasSetup = false;
const ext = path.extname(paths.testsSetup).toLowerCase();
if (ext !== '.ts') {
const testsSetupTs = `${paths.testsSetup.substr(
0,
paths.testsSetup.length - ext.length,
)}.ts`;
if (fs.existsSync(testsSetupTs)) {
hasSetup = true;
config.setupTestFrameworkScriptFile = testsSetupTs;
}
}
if (!hasSetup) {
config.setupTestFrameworkScriptFile = path.resolve(__dirname, '../config/jest/setup.js');
}
}
require.cache[require.resolve('react-scripts/scripts/utils/createJestConfig')].exports = (
resolve,
rootDir,
isEjecting,
) => {
let config = createJestConfig(resolve, rootDir, isEjecting);
// check for the existence of a tests setup file
// also check for the same path with a .ts ext
if (!fs.existsSync(paths.testsSetup)) {
let hasSetup = false;
const ext = path.extname(paths.testsSetup).toLowerCase();
if (ext !== '.ts') {
const testsSetupTs = `${paths.testsSetup.substr(
0,
paths.testsSetup.length - ext.length,
)}.ts`;
if (fs.existsSync(testsSetupTs)) {
hasSetup = true;
config.setupTestFrameworkScriptFile = testsSetupTs;
}
}
if (!hasSetup) {
config.setupTestFrameworkScriptFile = path.resolve(__dirname, '../config/jest/setup.js');
}
}
function rewireSetupTestFrameworkScriptFile(config: object): object {
// ref: create-react-app/packages/react-scripts/config/paths.js
// > testsSetup: resolveApp('src/setupTests.js'),
const setupTestsFile = [
// Check for TypeScript version of setupTests first.
[
reactScriptsPaths.testsSetup.replace(/\.js$/, ".ts"),
"/src/setupTests.ts"
],
// Use Javascript version if TypeScript version is not present.
[reactScriptsPaths.testsSetup, "/src/setupTests.js"]
].reduce((acc, [filePath, settingsValue]) => {
if (acc) return acc;
return fs.existsSync(filePath) ? settingsValue : undefined;
}, undefined);
return {
...config,
setupTestFrameworkScriptFile: setupTestsFile
};
}
const servedUrl = publicUrl ? url.parse(publicUrl).pathname : '/'
return ensureSlash(servedUrl, true)
}
paths.dotenv = existsSync(appDotEnv) ? appDotEnv : paths.dotenv
paths.appPath = appRootPath + '/'
paths.appPublic = appPublic
paths.appHtml = appPublic + '/index.html'
paths.appBuild = appBuild
paths.appPackageJson = appPackage
paths.yarnLockFile = appRootPath + '/yarn.lock'
paths.appSrc = appSrc
paths.appIndexJs = appSrc + '/index.js'
paths.proxySetup = appSrc + '/setupProxy.js'
paths.testsSetup = appSrc + '/setupTests'
paths.appNodeModules = appNodeModules
paths.servedPath = homepage ? getServedPath(homepage) : '/'
paths.publicUrl = homepage || ''
module.exports = paths