diff --git a/.buildkite/scripts/pipeline_test.sh b/.buildkite/scripts/pipeline_test.sh index 7fef13e2c04..bad0e5ce24a 100644 --- a/.buildkite/scripts/pipeline_test.sh +++ b/.buildkite/scripts/pipeline_test.sh @@ -13,4 +13,6 @@ docker run \ docker.elastic.co/eui/ci:5.3 \ bash -c "/opt/yarn*/bin/yarn \ && yarn cypress install \ - && NODE_OPTIONS=\"--max-old-space-size=2048\" npm run test-ci" + && yarn lint \ + && yarn test-unit --node-options=--max_old_space_size=2048 \ + && yarn test-cypress --node-options=--max_old_space_size=2048" diff --git a/package.json b/package.json index c69898046a7..45f68696438 100644 --- a/package.json +++ b/package.json @@ -31,12 +31,12 @@ "lint-sass": "yarn stylelint \"**/*.scss\" --quiet-deprecation-warnings", "test": "yarn lint && yarn test-unit", "test-ci": "yarn test && yarn test-cypress", - "test-unit": "cross-env NODE_ENV=test jest --config ./scripts/jest/config.js", + "test-unit": "node ./scripts/test-unit", "test-a11y": "node ./scripts/a11y-testing", "test-staged": "yarn lint && node scripts/test-staged.js", - "test-cypress": "node ./scripts/cypress", - "test-cypress-dev": "node ./scripts/cypress --dev", - "test-cypress-a11y": "node ./scripts/cypress --a11y", + "test-cypress": "node ./scripts/test-cypress", + "test-cypress-dev": "yarn test-cypress --dev", + "test-cypress-a11y": "yarn test-cypress --a11y", "combine-test-coverage": "sh ./scripts/combine-coverage.sh", "start-test-server": "BABEL_MODULES=false NODE_ENV=puppeteer NODE_OPTIONS=--max-old-space-size=4096 webpack-dev-server --config src-docs/webpack.config.js --port 9999", "yo-component": "yo ./generator-eui/app/component.js", diff --git a/scripts/cypress.js b/scripts/test-cypress.js similarity index 95% rename from scripts/cypress.js rename to scripts/test-cypress.js index 04ba81e7673..e0cbde1c7f0 100644 --- a/scripts/cypress.js +++ b/scripts/test-cypress.js @@ -17,6 +17,7 @@ const argv = yargs(hideBin(process.argv)) 'unknown-options-as-args': true, // collect any extra options to pass on to cypress }) .options({ + 'node-options': { type: 'string', default: '' }, 'skip-css': { type: 'boolean' }, dev: { type: 'boolean' }, theme: { type: 'string', default: 'light', choices: ['light', 'dark'] }, @@ -28,6 +29,7 @@ const argv = yargs(hideBin(process.argv)) }, }).argv; +const nodeOptions = argv['node-options']; const isDev = argv.hasOwnProperty('dev'); const isA11y = argv.hasOwnProperty('a11y'); const skipScss = argv.hasOwnProperty('skip-css'); @@ -59,6 +61,7 @@ const cypressCommandParts = [ 'cross-env', // windows support `THEME=${theme}`, // pass the theme 'BABEL_MODULES=false', // let webpack receive ES Module code + `NODE_OPTIONS="${nodeOptions}"`, 'NODE_ENV=cypress_test', // enable code coverage checks `REACT_VERSION=${reactVersion}`, // set react version to test `cypress ${testParams}`, diff --git a/scripts/test-unit.js b/scripts/test-unit.js new file mode 100644 index 00000000000..dd0f63dd979 --- /dev/null +++ b/scripts/test-unit.js @@ -0,0 +1,58 @@ +const { execSync } = require('child_process'); +const yargs = require('yargs/yargs'); +const { hideBin } = require('yargs/helpers'); +const chalk = require('chalk'); + +const { argv } = yargs(hideBin(process.argv)) + .parserConfiguration({ + // @see https://github.com/yargs/yargs-parser#configuration + 'camel-case-expansion': false, + 'unknown-options-as-args': true, + 'halt-at-non-option': true, + }) + .options({ + 'node-options': { type: 'string', default: '' }, + 'react-version': { + type: 'number', + default: 18, + choices: [16, 17, 18], + }, + testMatch: { + type: 'string', + description: + 'Pass in `react` to only test `.tsx` files, or `non-react` for the opposite. Also accepts standard Jest `--testMatch` globs', + coerce: (value) => { + if (value === 'react') { + value = '**/*.test.tsx'; + } else if (value === 'non-react') { + value = '**/*.test.{js,ts}'; + } + return value; + }, + }, + }); +const nodeOptions = argv['node-options']; +const reactVersion = argv['react-version']; +const testMatch = argv['testMatch']; + +const commandParts = [ + 'cross-env', // windows support + `NODE_OPTIONS="${nodeOptions}"`, + 'NODE_ENV=test', + `REACT_VERSION=${reactVersion}`, + `jest --config ./scripts/jest/config.js`, + ...argv._, // pass any extra options given to this script +]; +if (testMatch) { + commandParts.push(`--testMatch '${testMatch}'`); // has to come after any filename patterns +} + +const command = commandParts.join(' '); +console.log(chalk.white(command)); +try { + execSync(command, { stdio: 'inherit' }); +} catch { + // Jest already outputs sufficient error messaging, no need to emit a + // node child process stack trace that just unhelpfully points to this file + process.exit(1); +} diff --git a/src/components/collapsible_nav_beta/__snapshots__/collapsible_nav_beta.test.tsx.snap b/src/components/collapsible_nav_beta/__snapshots__/collapsible_nav_beta.test.tsx.snap index ca97480a43d..e5a804d20f6 100644 --- a/src/components/collapsible_nav_beta/__snapshots__/collapsible_nav_beta.test.tsx.snap +++ b/src/components/collapsible_nav_beta/__snapshots__/collapsible_nav_beta.test.tsx.snap @@ -105,102 +105,3 @@ exports[`EuiCollapsibleNavBeta renders initialIsCollapsed 1`] = `
-+ You are in a dialog. Press Escape, or tap/click outside the dialog to close. +
++ You are in a dialog. Press Escape, or tap/click outside the dialog to close. +
+