From 3e62ce87188f412d54d4c77d9f19344a641e4c90 Mon Sep 17 00:00:00 2001 From: Yaroslav Serhieiev Date: Fri, 2 Jul 2021 13:33:53 +0300 Subject: [PATCH 1/4] feat(config): skipLegacyWorkersInjection --- detox/index.d.ts | 6 ++ detox/local-cli/test.js | 37 +++++----- detox/local-cli/utils/jestInternals.js | 70 +++++++++++++++++++ detox/local-cli/utils/splitArgv.js | 45 +----------- detox/local-cli/utils/testCommandArgs.js | 1 - .../src/configuration/composeRunnerConfig.js | 1 + detox/test/e2e/config.js | 1 + detox/test/e2e/detox.config.js | 2 + .../types/detox-jest-circus-setup-tests.ts | 1 + 9 files changed, 102 insertions(+), 62 deletions(-) create mode 100644 detox/local-cli/utils/jestInternals.js diff --git a/detox/index.d.ts b/detox/index.d.ts index 8db8c372c0..caf66cf2a5 100644 --- a/detox/index.d.ts +++ b/detox/index.d.ts @@ -46,6 +46,12 @@ declare global { * @example testRunner: 'mocha' */ testRunner?: string; + /** + * Stops passing default `--maxWorkers 1` to the test runner, + * presuming that from now on you have that already configured + * in your test runner config as a default. + */ + skipLegacyWorkersInjection?: boolean; /** * @example runnerConfig: 'e2e/config.js' */ diff --git a/detox/local-cli/test.js b/detox/local-cli/test.js index 3062f1479d..c0c7779a2e 100644 --- a/detox/local-cli/test.js +++ b/detox/local-cli/test.js @@ -13,6 +13,7 @@ const { loadLastFailedTests, resetLastFailedTests } = require('../src/utils/last const log = require('../src/utils/logger').child({ __filename }); const { parse, quote } = require('../src/utils/shellQuote'); +const { readJestConfig } = require('./utils/jestInternals'); const { getPlatformSpecificString, printEnvironmentVariables } = require('./utils/misc'); const { prependNodeModulesBinToPATH } = require('./utils/misc'); const splitArgv = require('./utils/splitArgv'); @@ -33,7 +34,7 @@ module.exports.handler = async function test(argv) { detoxArgs, }); - const forwardedArgs = prepareArgs({ + const forwardedArgs = await prepareArgs({ cliConfig, runnerConfig, runnerArgs, @@ -75,7 +76,7 @@ module.exports.middlewares = [ function choosePrepareArgs({ cliConfig, detoxArgs, runner }) { if (runner === 'mocha') { - if (hasMultipleWorkers(cliConfig)) { + if (cliConfig.workers) { log.warn('Cannot use -w, --workers. Parallel test execution is only supported with Jest'); } @@ -155,19 +156,25 @@ function prepareMochaArgs({ cliConfig, runnerArgs, runnerConfig, platform }) { }; } -function prepareJestArgs({ cliConfig, runnerArgs, runnerConfig, platform }) { +async function prepareJestArgs({ cliConfig, runnerArgs, runnerConfig, platform }) { const { specs, passthrough } = splitArgv.jest(runnerArgs); const platformFilter = getPlatformSpecificString(platform); - return { - argv: { - color: !cliConfig.noColor && undefined, - config: runnerConfig.runnerConfig /* istanbul ignore next */ || undefined, - testNamePattern: platformFilter ? `^((?!${platformFilter}).)*$` : undefined, - maxWorkers: cliConfig.workers, + const argv = _.omitBy({ + color: !cliConfig.noColor && undefined, + config: runnerConfig.runnerConfig /* istanbul ignore next */ || undefined, + testNamePattern: platformFilter ? `^((?!${platformFilter}).)*$` : undefined, + maxWorkers: cliConfig.workers || (runnerConfig.skipLegacyWorkersInjection ? undefined : 1), - ...passthrough, - }, + ...passthrough, + }, _.isUndefined); + + const hasMultipleWorkers = runnerConfig.skipLegacyWorkersInjection + ? (await readJestConfig(argv)).globalConfig.maxWorkers > 1 + : cliConfig.workers > 1; + + return { + argv, env: _.omitBy({ DETOX_APP_LAUNCH_ARGS: cliConfig.appLaunchArgs, @@ -183,13 +190,13 @@ function prepareJestArgs({ cliConfig, runnerArgs, runnerConfig, platform }) { DETOX_GPU: cliConfig.gpu, DETOX_HEADLESS: cliConfig.headless, DETOX_LOGLEVEL: cliConfig.loglevel, - DETOX_READ_ONLY_EMU: platform === 'android' ? hasMultipleWorkers(cliConfig) : undefined, + DETOX_READ_ONLY_EMU: platform === 'android' ? hasMultipleWorkers : undefined, DETOX_RECORD_LOGS: cliConfig.recordLogs, DETOX_RECORD_PERFORMANCE: cliConfig.recordPerformance, DETOX_RECORD_TIMELINE: cliConfig.recordTimeline, DETOX_RECORD_VIDEOS: cliConfig.recordVideos, DETOX_REPORT_SPECS: _.isUndefined(cliConfig.jestReportSpecs) - ? !hasMultipleWorkers(cliConfig) + ? !hasMultipleWorkers : `${cliConfig.jestReportSpecs}` === 'true', DETOX_REUSE: cliConfig.reuse, DETOX_START_TIMESTAMP: Date.now(), @@ -233,10 +240,6 @@ function launchTestRunner({ argv, env, specs }) { }); } -function hasMultipleWorkers(cliConfig) { - return cliConfig.workers != 1; -} - async function runTestRunnerWithRetries(forwardedArgs, { keepLockFile, platform, retries }) { let runsLeft = 1 + retries; let launchError; diff --git a/detox/local-cli/utils/jestInternals.js b/detox/local-cli/utils/jestInternals.js new file mode 100644 index 0000000000..639abf6b8e --- /dev/null +++ b/detox/local-cli/utils/jestInternals.js @@ -0,0 +1,70 @@ +const Module = require('module'); +const path = require('path'); + +const resolveFrom = require('resolve-from'); + +const DetoxRuntimeError = require('../../src/errors/DetoxRuntimeError'); + +const getNodeModulePaths = (dir) => Module._nodeModulePaths(dir); + +function getJestLocation() { + const cwd = process.cwd(); + + if (!resolveFrom.silent(cwd, 'jest')) { + throw new DetoxRuntimeError({ + message: 'Could not resolve "jest" package from the current working directory.\n\n' + + 'This means that Detox could not find it in any of the following locations:\n' + + getNodeModulePaths(cwd).map(p => `* ${p}`).join('\n'), + hint: `Try installing "jest": npm install jest --save-dev`, + }); + } + + return path.dirname(resolveFrom(cwd, 'jest/package.json')); +} + +function resolveJestDependency(jestLocation, dependencyName) { + const result = resolveFrom.silent(jestLocation, dependencyName); + if (!result) { + throw new DetoxRuntimeError({ + message: `Could not resolve "${dependencyName}" package from the "jest" npm package directory.\n\n` + + 'This means that Detox could not find it in any of the following locations:\n' + + getNodeModulePaths(jestLocation).map(p => `* ${p}`).join('\n'), + hint: 'Consider reporting this as an issue at: https://github.com/wix/Detox/issues' + }); + } + + return result; +} + +function requireJestDependency(jestLocation, dependencyName) { + return require(resolveJestDependency(jestLocation, dependencyName)); +} + +function resolveJestCliArgs() { + const jestLocation = getJestLocation(); + resolveJestDependency(jestLocation, 'jest-cli'); + + try { + const jestCliManifest = resolveJestDependency(jestLocation, 'jest-cli/package.json'); + const argsJsFile = path.join(path.dirname(jestCliManifest), 'build/cli/args.js'); + + return require(argsJsFile); + } catch (e) { + throw new DetoxRuntimeError({ + message: 'Could not parse CLI arguments supported by "jest-cli" package, see the error below.', + hint: 'Consider reporting this as an issue at: https://github.com/wix/Detox/issues', + debugInfo: e, + }); + } +} + +async function readJestConfig(argv) { + const jestLocation = getJestLocation(); + const { readConfig } = requireJestDependency(jestLocation, 'jest-config'); + return readConfig(argv, process.cwd(), false); +} + +module.exports = { + resolveJestCliArgs, + readJestConfig, +}; diff --git a/detox/local-cli/utils/splitArgv.js b/detox/local-cli/utils/splitArgv.js index b82d5d36ed..c83a01cef5 100644 --- a/detox/local-cli/utils/splitArgv.js +++ b/detox/local-cli/utils/splitArgv.js @@ -1,11 +1,6 @@ -const Module = require('module'); -const path = require('path'); - const _ = require('lodash'); -const resolveFrom = require('resolve-from'); - -const DetoxRuntimeError = require('../../src/errors/DetoxRuntimeError'); +const { resolveJestCliArgs } = require('./jestInternals'); const testCommandArgs = require('./testCommandArgs'); function extractKnownKeys(yargsBuilder) { @@ -72,44 +67,6 @@ function getMochaBooleanArgs() { .value(); } -function resolveJestCliArgs() { - const cwd = process.cwd(); - const getNodeModulePaths = (dir) => Module._nodeModulePaths(dir); - - if (!resolveFrom.silent(cwd, 'jest')) { - throw new DetoxRuntimeError({ - message: 'Could not resolve "jest" package from the current working directory.\n\n' + - 'This means that Detox could not find it in any of the following locations:\n' + - getNodeModulePaths(cwd).map(p => `* ${p}`).join('\n'), - hint: `Try installing "jest": npm install jest --save-dev`, - }); - } - - const jestLocation = path.dirname(resolveFrom(cwd, 'jest/package.json')); - - if (!resolveFrom.silent(jestLocation, 'jest-cli')) { - throw new DetoxRuntimeError({ - message: 'Could not resolve "jest-cli" package from the "jest" npm package directory.\n\n' + - 'This means that Detox could not find it in any of the following locations:\n' + - getNodeModulePaths(jestLocation).map(p => `* ${p}`).join('\n'), - hint: 'Consider reporting this as an issue at: https://github.com/wix/Detox/issues' - }); - } - - try { - const jestCliManifest = resolveFrom(jestLocation, 'jest-cli/package.json'); - const argsJsFile = path.join(path.dirname(jestCliManifest), 'build/cli/args.js'); - - return require(argsJsFile); - } catch (e) { - throw new DetoxRuntimeError({ - message: 'Could not parse CLI arguments supported by "jest-cli" package, see the error below.', - hint: 'Consider reporting this as an issue at: https://github.com/wix/Detox/issues', - debugInfo: e, - }); - } -} - function splitDetoxArgv(argv) { const aliases = extractKnownKeys(testCommandArgs); const isDetoxArg = (_value, key) => aliases.has(key); diff --git a/detox/local-cli/utils/testCommandArgs.js b/detox/local-cli/utils/testCommandArgs.js index cf1cfb0ed8..b87d562867 100644 --- a/detox/local-cli/utils/testCommandArgs.js +++ b/detox/local-cli/utils/testCommandArgs.js @@ -106,7 +106,6 @@ module.exports = { group: 'Execution:', describe: 'Specifies the number of workers the test runner should spawn. Requires a test runner with parallel execution support (e.g. Jest)', number: true, - default: 1, }, 'jest-report-specs': { group: 'Execution:', diff --git a/detox/src/configuration/composeRunnerConfig.js b/detox/src/configuration/composeRunnerConfig.js index b13e3cda65..f559295aab 100644 --- a/detox/src/configuration/composeRunnerConfig.js +++ b/detox/src/configuration/composeRunnerConfig.js @@ -11,6 +11,7 @@ function composeRunnerConfig({ globalConfig, cliConfig }) { testRunner, runnerConfig: customRunnerConfig || defaultRunnerConfig, specs: globalConfig.specs || 'e2e', + skipLegacyWorkersInjection: Boolean(globalConfig.skipLegacyWorkersInjection), }; } diff --git a/detox/test/e2e/config.js b/detox/test/e2e/config.js index 9c9ac001e5..d20b01b389 100644 --- a/detox/test/e2e/config.js +++ b/detox/test/e2e/config.js @@ -11,6 +11,7 @@ module.exports = { : ['/runners/jest/streamlineReporter', '/test/node_modules/jest-junit'], 'verbose': true, 'bail': false, + 'maxWorkers': 1, 'collectCoverageFrom': [ 'src/**/*.js', '!**/__test/**', diff --git a/detox/test/e2e/detox.config.js b/detox/test/e2e/detox.config.js index a8ea2e583b..215c13a0e5 100644 --- a/detox/test/e2e/detox.config.js +++ b/detox/test/e2e/detox.config.js @@ -9,6 +9,8 @@ const config = { testRunner: 'nyc jest', runnerConfig: 'e2e/config.js', specs: 'e2e/*.test.js', + skipLegacyWorkersInjection: true, + behavior: { init: { exposeGlobals: true diff --git a/detox/test/types/detox-jest-circus-setup-tests.ts b/detox/test/types/detox-jest-circus-setup-tests.ts index c7913901a9..c713bc5bc8 100644 --- a/detox/test/types/detox-jest-circus-setup-tests.ts +++ b/detox/test/types/detox-jest-circus-setup-tests.ts @@ -24,6 +24,7 @@ beforeAll(async () => { testRunner: "nyc jest", runnerConfig: "e2e/config.js", specs: "e2e/*.test.js", + skipLegacyWorkersInjection: true, behavior: { init: { reinstallApp: true, From 46f249d6669ea31ae8b6b209c32ff50f868729c4 Mon Sep 17 00:00:00 2001 From: wixmobile Date: Fri, 9 Jul 2021 12:18:07 -0400 Subject: [PATCH 2/4] Publish 18.19.0-smoke.0 [ci skip] --- detox/package.json | 2 +- detox/test/package.json | 4 ++-- examples/demo-native-android/package.json | 4 ++-- examples/demo-native-ios/package.json | 4 ++-- examples/demo-react-native-detox-instruments/package.json | 4 ++-- examples/demo-react-native-jest/package.json | 4 ++-- examples/demo-react-native/package.json | 4 ++-- lerna.json | 2 +- package.json | 2 +- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/detox/package.json b/detox/package.json index e0dfea7cf7..f884f04d2a 100644 --- a/detox/package.json +++ b/detox/package.json @@ -1,7 +1,7 @@ { "name": "detox", "description": "E2E tests and automation for mobile", - "version": "18.18.2-smoke.0", + "version": "18.19.0-smoke.0", "bin": { "detox": "local-cli/cli.js" }, diff --git a/detox/test/package.json b/detox/test/package.json index e3b98bfc09..0d9bd90549 100644 --- a/detox/test/package.json +++ b/detox/test/package.json @@ -1,6 +1,6 @@ { "name": "detox-test", - "version": "18.18.2-smoke.0", + "version": "18.19.0-smoke.0", "private": true, "engines": { "node": ">=8.3.0" @@ -40,7 +40,7 @@ "@babel/core": "^7.12.9", "@babel/runtime": "^7.12.5", "@types/node": "^14.14.20", - "detox": "^18.18.2-smoke.0", + "detox": "^18.19.0-smoke.0", "dtslint": "^4.0.6", "express": "^4.15.3", "jest": "^27.0.0", diff --git a/examples/demo-native-android/package.json b/examples/demo-native-android/package.json index d12b57a859..4e4c1fd99c 100644 --- a/examples/demo-native-android/package.json +++ b/examples/demo-native-android/package.json @@ -1,6 +1,6 @@ { "name": "detox-demo-native-android", - "version": "18.18.2-smoke.0", + "version": "18.19.0-smoke.0", "private": true, "scripts": { "packager": "react-native start", @@ -8,7 +8,7 @@ "e2e": "mocha e2e --opts ./e2e/mocha.opts" }, "devDependencies": { - "detox": "^18.18.2-smoke.0", + "detox": "^18.19.0-smoke.0", "mocha": "^6.1.3" }, "detox": {} diff --git a/examples/demo-native-ios/package.json b/examples/demo-native-ios/package.json index 7796adb8c4..159110d55b 100644 --- a/examples/demo-native-ios/package.json +++ b/examples/demo-native-ios/package.json @@ -1,9 +1,9 @@ { "name": "detox-demo-native-ios", - "version": "18.18.2-smoke.0", + "version": "18.19.0-smoke.0", "private": true, "devDependencies": { - "detox": "^18.18.2-smoke.0", + "detox": "^18.19.0-smoke.0", "mocha": "^6.1.3" }, "detox": { diff --git a/examples/demo-react-native-detox-instruments/package.json b/examples/demo-react-native-detox-instruments/package.json index 14dd9becda..6af27b0944 100644 --- a/examples/demo-react-native-detox-instruments/package.json +++ b/examples/demo-react-native-detox-instruments/package.json @@ -1,10 +1,10 @@ { "name": "demo-react-native-detox-instruments", - "version": "18.18.2-smoke.0", + "version": "18.19.0-smoke.0", "private": true, "scripts": {}, "devDependencies": { - "detox": "^18.18.2-smoke.0", + "detox": "^18.19.0-smoke.0", "mocha": "6.x.x" }, "detox": { diff --git a/examples/demo-react-native-jest/package.json b/examples/demo-react-native-jest/package.json index f15721c81a..9f0e5454b5 100644 --- a/examples/demo-react-native-jest/package.json +++ b/examples/demo-react-native-jest/package.json @@ -1,6 +1,6 @@ { "name": "demo-react-native-jest", - "version": "18.18.2-smoke.0", + "version": "18.19.0-smoke.0", "private": true, "scripts": { "test:ios-release": "detox test --configuration ios.sim.release -l verbose", @@ -12,7 +12,7 @@ }, "devDependencies": { "@types/jest": "^26.0.19", - "detox": "^18.18.2-smoke.0", + "detox": "^18.19.0-smoke.0", "jest": "^26.5.0", "jest-circus": "^26.5.2", "sanitize-filename": "^1.6.1", diff --git a/examples/demo-react-native/package.json b/examples/demo-react-native/package.json index d585422fe3..bf69c475c6 100644 --- a/examples/demo-react-native/package.json +++ b/examples/demo-react-native/package.json @@ -1,6 +1,6 @@ { "name": "example", - "version": "18.18.2-smoke.0", + "version": "18.19.0-smoke.0", "private": true, "scripts": { "start": "react-native start", @@ -26,7 +26,7 @@ }, "devDependencies": { "@types/mocha": "^8.2.0", - "detox": "^18.18.2-smoke.0", + "detox": "^18.19.0-smoke.0", "mocha": "^6.1.3", "ts-node": "^9.1.1", "typescript": "^4.1.3" diff --git a/lerna.json b/lerna.json index 07be9f7d8f..1bf1b38efe 100644 --- a/lerna.json +++ b/lerna.json @@ -13,7 +13,7 @@ "generation", "." ], - "version": "18.18.2-smoke.0", + "version": "18.19.0-smoke.0", "npmClient": "npm", "command": { "publish": { diff --git a/package.json b/package.json index 93c80d8ffe..5ae8637860 100644 --- a/package.json +++ b/package.json @@ -19,5 +19,5 @@ "semver": "5.x.x", "shell-utils": "1.x.x" }, - "version": "18.18.2-smoke.0" + "version": "18.19.0-smoke.0" } From 3a44a50c5da8c413c8f567dca685f75aacd487ee Mon Sep 17 00:00:00 2001 From: Yaroslav Serhieiev Date: Fri, 9 Jul 2021 19:12:11 +0300 Subject: [PATCH 3/4] build: update docs and example projects --- detox/local-cli/init.js | 1 + detox/local-cli/templates/jest.js | 1 + docs/Guide.Jest.md | 3 +++ examples/demo-react-native-jest/e2e/config.json | 1 + examples/demo-react-native-jest/package.json | 7 +++---- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/detox/local-cli/init.js b/detox/local-cli/init.js index cddd1e06a2..84b36efeae 100644 --- a/detox/local-cli/init.js +++ b/detox/local-cli/init.js @@ -102,6 +102,7 @@ function createJestFolderE2E() { createFile('.detoxrc.json', JSON.stringify({ testRunner: 'jest', runnerConfig: 'e2e/config.json', + skipLegacyWorkersInjection: true, ...createDefaultConfigurations(), }, null, 2)); } diff --git a/detox/local-cli/templates/jest.js b/detox/local-cli/templates/jest.js index 54d1656eed..a777340ffc 100644 --- a/detox/local-cli/templates/jest.js +++ b/detox/local-cli/templates/jest.js @@ -1,6 +1,7 @@ const firstTestContent = require('./firstTestContent'); const runnerConfig = `{ + "maxWorkers": 1, "testEnvironment": "./environment", "testRunner": "jest-circus/runner", "testTimeout": 120000, diff --git a/docs/Guide.Jest.md b/docs/Guide.Jest.md index 9aa046dd51..aca000d8ff 100644 --- a/docs/Guide.Jest.md +++ b/docs/Guide.Jest.md @@ -56,6 +56,7 @@ Even if `detox init` passes well, and everything is green, we still recommend go | ---------------------- | ---------------------------------------------- | ------------------------------------------------------------ | | `testRunner` | `"jest"` | *Required.* Should be `"jest"` for the proper `detox test` CLI functioning. | | `runnerConfig ` | (optional path to Jest config file) | *Optional.* This field tells `detox test` CLI where to look for Jest's config file. If omitted, the default value is `e2e/config.json`. | +| `skipLegacyWorkersInjection ` | `false` or `true` | *Optional.* This field tells `detox test` to stop appending `--maxWorkers 1` argument to `jest ...` command by default. Since `detox@18.19.0`, the control over `maxWorkers` count has been transfered to Jest config files, and that allows you to set any other value as a default `maxWorkers` count. | A typical Detox configuration in `.detoxrc.json` file looks like: @@ -63,6 +64,7 @@ A typical Detox configuration in `.detoxrc.json` file looks like: { "testRunner": "jest", "runnerConfig": "e2e/config.json", + "skipLegacyWorkersInjection": true, "devices": { "simulator": { "type": "ios.simulator", @@ -91,6 +93,7 @@ A typical Detox configuration in `.detoxrc.json` file looks like: | Property | Value | Description | | ---------------------- | ---------------------------------------------- | ------------------------------------------------------------ | +| `maxWorkers ` | `1` | *Recommended.* When being used with `skipLegacyWorkersInjection: true` in Detox config, it prevents overallocation of mobile devices in the light of Jest's default logic (`= cpusCount — 1`), when you do not pass any specific worker count. To override it, [use CLI arguments](APIRef.DetoxCLI.md#test), or see [Jest documentation](https://jestjs.io/docs/configuration#maxworkers-number--string) if you plan to change the default value in the config. | | `testEnvironment ` | `"./environment"` | *Required.* Needed for the proper functioning of Jest and Detox. See [Jest documentation](https://jestjs.io/docs/en/configuration#testenvironment-string) for more details. | | `testRunner ` | `"jest-circus/runner"` | *Required.* Needed for the proper functioning of Jest and Detox. See [Jest documentation](https://jestjs.io/docs/en/configuration#testrunner-string) for more details. | | `testTimeout ` | `120000` | *Required*. Overrides the default timeout (5 seconds), which is usually too short to complete a single end-to-end test. | diff --git a/examples/demo-react-native-jest/e2e/config.json b/examples/demo-react-native-jest/e2e/config.json index c23861a8d0..11d109fcec 100644 --- a/examples/demo-react-native-jest/e2e/config.json +++ b/examples/demo-react-native-jest/e2e/config.json @@ -2,6 +2,7 @@ "globalSetup": "./global-setup.js", "globalTeardown": "./global-teardown.js", "setupFilesAfterEnv": ["./setup.ts"], + "maxWorkers": 1, "testEnvironment": "./environment", "testRunner": "jest-circus/runner", "testTimeout": 120000, diff --git a/examples/demo-react-native-jest/package.json b/examples/demo-react-native-jest/package.json index 9f0e5454b5..c455187a7b 100644 --- a/examples/demo-react-native-jest/package.json +++ b/examples/demo-react-native-jest/package.json @@ -11,12 +11,11 @@ "test:android-genycloud-release-ci": "detox test --configuration android.genycloud.release -l verbose --workers 2 --record-logs all --take-screenshots all" }, "devDependencies": { - "@types/jest": "^26.0.19", + "@types/jest": "^26.0.24", "detox": "^18.19.0-smoke.0", - "jest": "^26.5.0", - "jest-circus": "^26.5.2", + "jest": "^27.0.0", "sanitize-filename": "^1.6.1", - "ts-jest": "^26.4.4", + "ts-jest": "^27.0.0", "typescript": "^4.1.3" }, "dependencies": { From ac9fcdd6e5aecd38394fdfb95c60a15cd829a379 Mon Sep 17 00:00:00 2001 From: Yaroslav Serhieiev Date: Fri, 9 Jul 2021 19:48:41 +0300 Subject: [PATCH 4/4] test: cover skipLegacyWorkersInjection --- detox/local-cli/test.test.js | 101 +++++++++++++++++++++++------------ 1 file changed, 66 insertions(+), 35 deletions(-) diff --git a/detox/local-cli/test.test.js b/detox/local-cli/test.test.js index fadc7ede61..16f24e359f 100644 --- a/detox/local-cli/test.test.js +++ b/detox/local-cli/test.test.js @@ -306,6 +306,23 @@ describe('CLI', () => { }); }); + describe('given skipLegacyWorkersInjection: true', () => { + describe.each([ + ['ios.simulator'], + ['android.emulator'], + ])('for %s', (configurationType) => { + it('should omit --maxWorkers CLI arg', async () => { + singleConfig().type = configurationType; + detoxConfig.skipLegacyWorkersInjection = true; + detoxConfig.runnerConfig = 'package.json'; + + await run(); + + expect(cliCall().command).not.toMatch(/--maxWorkers/); + }); + }); + }); + test.each([['-c'], ['--configuration']])( '%s should provide inverted --testNamePattern that configuration (jest)', async (__configuration) => { @@ -447,49 +464,63 @@ describe('CLI', () => { expect(cliCall().env).toEqual(expect.objectContaining({ DETOX_CAPTURE_VIEW_HIERARCHY: 'enabled' })); }); - test.each([['-w'], ['--workers']])('%s should be passed as CLI argument', async (__workers) => { - await run(`${__workers} 2`); - expect(cliCall().command).toContain('--maxWorkers 2'); - }); + describe.each([ + [false], + [true], + ])('when skipLegacyWorkersInjection is %j', (skipLegacyWorkersInjection) => { + beforeEach(() => { + Object.assign(detoxConfig, { + skipLegacyWorkersInjection, + runnerConfig: tempfile('.json', JSON.stringify({ + maxWorkers: 1, + })), + }); + }); - test.each([['-w'], ['--workers']])('%s should be replaced with --maxWorkers ', async (__workers) => { - await run(`${__workers} 2 --maxWorkers 3`); + test.each([['-w'], ['--workers']])('%s should be passed as CLI argument', async (__workers) => { + await run(`${__workers} 2`); + expect(cliCall().command).toContain('--maxWorkers 2'); + }); - const { command } = cliCall(); - expect(command).toContain('--maxWorkers 3'); - expect(command).not.toContain('--maxWorkers 2'); - }); + test.each([['-w'], ['--workers']])('%s should be replaced with --maxWorkers ', async (__workers) => { + await run(`${__workers} 2 --maxWorkers 3`); - test.each([['-w'], ['--workers']])('%s can be overriden by a later value', async (__workers) => { - await run(`${__workers} 2 ${__workers} 3`); + const { command } = cliCall(); + expect(command).toContain('--maxWorkers 3'); + expect(command).not.toContain('--maxWorkers 2'); + }); - const { command } = cliCall(); - expect(command).toContain('--maxWorkers 3'); - expect(command).not.toContain('--maxWorkers 2'); - }); + test.each([['-w'], ['--workers']])('%s can be overriden by a later value', async (__workers) => { + await run(`${__workers} 2 ${__workers} 3`); - test.each([['-w'], ['--workers']])('%s should not warn anything for iOS', async (__workers) => { - singleConfig().type = 'ios.simulator'; - await run(`${__workers} 2`); - expect(logger.warn).not.toHaveBeenCalled(); - }); + const { command } = cliCall(); + expect(command).toContain('--maxWorkers 3'); + expect(command).not.toContain('--maxWorkers 2'); + }); - test.each([['-w'], ['--workers']])('%s should not put readOnlyEmu environment variable for iOS', async (__workers) => { - singleConfig().type = 'ios.simulator'; - await run(`${__workers} 2`); - expect(cliCall().env).not.toHaveProperty('DETOX_READ_ONLY_EMU'); - }); + test.each([['-w'], ['--workers']])('%s should not warn anything for iOS', async (__workers) => { + singleConfig().type = 'ios.simulator'; + await run(`${__workers} 2`); + expect(logger.warn).not.toHaveBeenCalled(); + }); - test.each([['-w'], ['--workers']])('%s should put readOnlyEmu environment variable for Android if there is a single worker', async (__workers) => { - singleConfig().type = 'android.emulator'; - await run(`${__workers} 1`); - expect(cliCall().env).toEqual(expect.objectContaining({ DETOX_READ_ONLY_EMU: false })); - }); + test.each([['-w'], ['--workers']])('%s should not put readOnlyEmu environment variable for iOS', async (__workers) => { + singleConfig().type = 'ios.simulator'; + await run(`${__workers} 2`); + expect(cliCall().env).not.toHaveProperty('DETOX_READ_ONLY_EMU'); + }); - test.each([['-w'], ['--workers']])('%s should put readOnlyEmu environment variable for Android if there are multiple workers', async (__workers) => { - singleConfig().type = 'android.emulator'; - await run(`${__workers} 2`); - expect(cliCall().env).toEqual(expect.objectContaining({ DETOX_READ_ONLY_EMU: true })); + test.each([['-w'], ['--workers']])('%s should put readOnlyEmu environment variable for Android if there is a single worker', async (__workers) => { + singleConfig().type = 'android.emulator'; + await run(`${__workers} 1`); + expect(cliCall().env).toEqual(expect.objectContaining({ DETOX_READ_ONLY_EMU: false })); + }); + + test.each([['-w'], ['--workers']])('%s should put readOnlyEmu environment variable for Android if there are multiple workers', async (__workers) => { + singleConfig().type = 'android.emulator'; + await run(`${__workers} 2`); + expect(cliCall().env).toEqual(expect.objectContaining({ DETOX_READ_ONLY_EMU: true })); + }); }); test('should omit --testNamePattern for custom platforms', async () => {