How to use the react-scripts/config/paths.testsSetup function in react-scripts

To help you get started, we’ve selected a few react-scripts examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fabric8-ui / fabric8-ui / packages / scripts / lib / rewire-scripts.js View on Github external
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
github strothj / react-app-rewire-typescript-babel-preset / packages / rewire / rewireJest.ts View on Github external
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
  };
}
github fabric8-ui / fabric8-ui / talamer / packages / scripts / lib / rewire-scripts.js View on Github external
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: {
github fabric8-ui / fabric8-ui / packages / scripts / lib / rewire-scripts.js View on Github external
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');
      }
    }
github fabric8-ui / fabric8-ui / talamer / packages / scripts / lib / rewire-scripts.js View on Github external
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');
      }
    }
github strothj / react-app-rewire-typescript-babel-preset / packages / rewire / rewireJest.ts View on Github external
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
  };
}
github ghondar / crassa / react-scripts-wrapper-paths.js View on Github external
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