How to use isInCMD method in root

Best JavaScript code snippet using root

test.test.js

Source:test.test.js Github

copy

Full Screen

...51 test('should default to "e2e" test folder', () => expect(cliCall().command).toMatch(/ e2e$/));52 test('should pass --use-custom-logger true', () => expect(cliCall().command).toMatch(/--use-custom-logger true/));53 test('should not override process.env', () => expect(cliCall().env).toStrictEqual({}));54 test('should produce a default command (integration test)', () => {55 const quoteChar = !isInCMD() && detoxConfigPath.indexOf('\\') >= 0 ? `'` : '';56 const args = [57 `--opts`, `e2e/mocha.opts`,58 `--grep`, `:android:`, `--invert`,59 `--config-path`, quote(detoxConfigPath, quoteChar),60 `--use-custom-logger`, `true`61 ].join(' ');62 expect(cliCall().command).toBe(`mocha ${args} e2e`);63 });64 });65 test.each([['-o'], ['--runner-config']])('%s <path> should be aware of mocha.opts extension', async (__runnerConfig) => {66 await run(`${__runnerConfig} e2e/custom.opts`);67 expect(cliCall().command).toContain(`--opts e2e/custom.opts`);68 });69 test.each([['-o'], ['--runner-config']])('%s <path> should be aware of .mocharc extension', async (__runnerConfig) => {70 await run(`${__runnerConfig} e2e/.mocharc`);71 expect(cliCall().command).toContain(`--config e2e/.mocharc`);72 });73 test.each([['-l'], ['--loglevel']])('%s <value> should be passed as CLI argument', async (__loglevel) => {74 await run(`${__loglevel} verbose`);75 expect(cliCall().command).toContain(`--loglevel verbose`);76 });77 test('--no-color should be passed as CLI argument', async () => {78 await run(`--no-color`);79 expect(cliCall().command).toContain(' --no-colors ');80 });81 test.each([['-R'], ['--retries']])('%s <value> should print warning', async (__retries) => {82 await run(`${__retries} 1`);83 expect(logger.warn).toHaveBeenCalledWith(expect.stringContaining('Cannot use -R, --retries.'));84 });85 test.each([['-R'], ['--retries']])('%s <value> should be ignored', async (__retries) => {86 cp.execSync.mockImplementation(() => { throw new Error });87 await run(`${__retries} 1`).catch(_.noop);88 expect(cliCall(0)).toBeDefined()89 expect(cliCall(1)).toBe(null);90 });91 test.each([['-r'], ['--reuse']])('%s <value> should be passed as CLI argument', async (__reuse) => {92 await run(`${__reuse}`);93 expect(cliCall().command).toContain('--reuse')94 });95 test.each([['-u'], ['--cleanup']])('%s <value> should be passed as CLI argument', async (__cleanup) => {96 await run(`${__cleanup}`);97 expect(cliCall().command).toContain('--cleanup')98 });99 test.each([['-d'], ['--debug-synchronization']])('%s <value> should be passed as CLI argument', async (__debug_synchronization) => {100 await run(`${__debug_synchronization} 5000`);101 expect(cliCall().command).toContain('--debug-synchronization 5000')102 });103 test.each([['-d'], ['--debug-synchronization']])('%s <value> should have default value = 3000', async (__debug_synchronization) => {104 await run(`${__debug_synchronization}`);105 expect(cliCall().command).toContain('--debug-synchronization 3000')106 });107 test.each([['-a'], ['--artifacts-location']])('%s <value> should be passed as CLI argument', async (__artifacts_location) => {108 await run(`${__artifacts_location} someLocation`);109 expect(cliCall().command).toContain('--artifacts-location someLocation')110 });111 test('--record-logs <value> should be passed as CLI argument', async () => {112 await run(`--record-logs all`);113 expect(cliCall().command).toContain('--record-logs all')114 });115 test('--take-screenshots <value> should be passed as CLI argument', async () => {116 await run(`--take-screenshots failing`);117 expect(cliCall().command).toContain('--take-screenshots failing')118 });119 test('--record-videos <value> should be passed as CLI argument', async () => {120 await run(`--record-videos failing`);121 expect(cliCall().command).toContain('--record-videos failing')122 });123 test('--record-performance <value> should be passed as CLI argument', async () => {124 await run(`--record-performance all`);125 expect(cliCall().command).toContain('--record-performance all')126 });127 test('--record-timeline <value> should print "unsupported" warning', async () => {128 await run(`--record-timeline all`);129 expect(logger.warn).toHaveBeenCalledWith(expect.stringContaining('Cannot use --record-timeline.'));130 });131 test.each([['-w'], ['--workers']])('%s <value> should print "unsupported" warning', async (__workers) => {132 await run(`${__workers} 2`);133 expect(logger.warn).toHaveBeenCalledWith(expect.stringContaining('Cannot use -w, --workers.'));134 });135 test.each([['-H'], ['--headless']])('%s <value> should be passed as CLI argument', async (__headless) => {136 await run(`${__headless}`);137 expect(cliCall().command).toContain('--headless');138 });139 test('--gpu <value> should be passed as CLI argument', async () => {140 await run(`--gpu angle_indirect`);141 expect(cliCall().command).toContain('--gpu angle_indirect');142 });143 test('--device-launch-args should be passed as an environment variable', async () => {144 await run(`--device-launch-args "--verbose"`);145 expect(cliCall().env).toEqual({146 deviceLaunchArgs: '--verbose',147 });148 });149 test('--app-launch-args should be passed as an environment variable', async () => {150 await run(`--app-launch-args "--debug yes"`);151 expect(cliCall().env).toEqual({152 appLaunchArgs: '--debug yes',153 });154 });155 test('--use-custom-logger false should be prevent passing CLI argument', async () => {156 await run(`--use-custom-logger false`);157 expect(cliCall().command).not.toContain('--use-custom-logger');158 });159 test('--force-adb-install should be ignored for iOS', async () => {160 singleConfig().type = 'ios.simulator';161 await run(`--force-adb-install`);162 expect(cliCall().command).not.toContain('--force-adb-install');163 });164 test('--force-adb-install should be passed as CLI argument for Android', async () => {165 singleConfig().type = 'android.emulator';166 await run(`--force-adb-install`);167 expect(cliCall().command).toContain('--force-adb-install');168 });169 test.each([['-n'], ['--device-name']])('%s <value> should be passed as CLI argument', async (__device_name) => {170 await run(`${__device_name} TheDevice`);171 expect(cliCall().command).toContain('--device-name TheDevice');172 });173 test('should omit --grep --invert for custom platforms', async () => {174 const customDriver = `module.exports = class CustomDriver {};`175 singleConfig().type = tempfile('.js', customDriver);176 await run();177 expect(cliCall().command).not.toContain(' --invert ');178 expect(cliCall().command).not.toContain(' --grep ');179 });180 test('specifying direct test paths', async () => {181 await run(`e2e/01.sanity.test.js e2e/02.sanity.test.js`);182 expect(cliCall().command).not.toMatch(/ e2e /);183 expect(cliCall().command).not.toMatch(/ e2e$/);184 expect(cliCall().command).toMatch(/ e2e\/01.sanity.test.js e2e\/02.sanity.test.js$/);185 });186 test('e.g., --bail should be passed through', async () => {187 await run(`--bail`);188 expect(cliCall().command).toContain('--bail');189 });190 test('e.g., --reporter spec should be passed through', async () => {191 await run(`--reporter spec`);192 expect(cliCall().command).toContain('--reporter spec');193 });194 test('e.g., --bail e2e/Login.test.js should be split to --bail and e2e/Login.test.js', async () => {195 await run(`--bail e2e/Login.test.js --reporter spec`);196 expect(cliCall().command).toContain('--bail --reporter spec e2e/Login.test.js');197 });198 test.each([199 [`--runner-config "mocha configs/.mocharc"`, `--config ${quote('mocha configs/.mocharc')}`],200 [`--artifacts-location "artifacts dir/"`, `--artifacts-location ${quote('artifacts dir/')}`],201 [`--device-name "iPhone X"`, `--device-name ${quote('iPhone X')}`],202 [`"e2e tests/first test.spec.js"`, `"e2e tests/first test.spec.js"`],203 ])('should escape %s when forwarding it as a CLI argument', async (cmd, expected) => {204 await run(cmd);205 expect(cliCall().command).toContain(` ${expected}`);206 });207 });208 describe('(jest)', () => {209 beforeEach(() => {210 detoxConfig.testRunner = 'jest';211 });212 describe('given no extra args (iOS)', () => {213 beforeEach(async () => {214 singleConfig().type = 'ios.simulator';215 await run();216 });217 test('should produce a default command (integration test, ios)', () => {218 const args = `--config e2e/config.json --testNamePattern ${quote('^((?!:android:).)*$')} --maxWorkers 1`;219 expect(cliCall().command).toBe(`jest ${args} e2e`);220 });221 test('should put default environment variables (integration test, ios)', () => {222 expect(cliCall().env).toEqual({223 DETOX_START_TIMESTAMP: expect.any(Number),224 configPath: expect.any(String),225 reportSpecs: true,226 useCustomLogger: true,227 });228 });229 });230 describe('given no extra args (Android)', () => {231 beforeEach(async () => {232 singleConfig().type = 'android.emulator';233 await run();234 });235 test('should produce a default command (integration test)', () => {236 const args = `--config e2e/config.json --testNamePattern ${quote('^((?!:ios:).)*$')} --maxWorkers 1`;237 expect(cliCall().command).toBe(`jest ${args} e2e`);238 });239 test('should put default environment variables (integration test)', () => {240 expect(cliCall().env).toEqual({241 DETOX_START_TIMESTAMP: expect.any(Number),242 configPath: expect.any(String),243 reportSpecs: true,244 useCustomLogger: true,245 forceAdbInstall: false,246 readOnlyEmu: false,247 });248 });249 });250 test.each([['-c'], ['--configuration']])(251 '%s <configuration> should provide inverted --testNamePattern that configuration (jest)',252 async (__configuration) => {253 detoxConfig.configurations.iosTest = { ...detoxConfig.configurations.single };254 detoxConfig.configurations.iosTest.type = 'ios.simulator';255 detoxConfig.configurations.androidTest = { ...detoxConfig.configurations.single };256 detoxConfig.configurations.androidTest.type = 'android.emulator';257 await run(`${__configuration} androidTest`);258 expect(cliCall(0).command).toContain(`--testNamePattern ${quote('^((?!:ios:).)*$')}`);259 expect(cliCall(0).env.configuration).toBe('androidTest');260 await run(`${__configuration} iosTest`);261 expect(cliCall(1).command).toContain(`--testNamePattern ${quote('^((?!:android:).)*$')}`);262 expect(cliCall(1).env.configuration).toBe('iosTest');263 }264 );265 test.each([['-o'], ['--runner-config']])('%s <path> should point to the specified Jest config', async (__runnerConfig) => {266 await run(`${__runnerConfig} e2e/custom.config.js`);267 expect(cliCall().command).toContain(`--config e2e/custom.config.js`);268 });269 test.each([['-l'], ['--loglevel']])('%s <value> should be passed as environment variable', async (__loglevel) => {270 await run(`${__loglevel} trace`);271 expect(cliCall().env).toEqual(expect.objectContaining({ loglevel: 'trace' }));272 });273 test('--no-color should be passed as CLI argument', async () => {274 await run(`--no-color`);275 expect(cliCall().command).toContain(' --no-color ');276 });277 test.each([['-R'], ['--retries']])('%s <value> should execute successful run once', async (__retries) => {278 await run(`-R 1`);279 expect(cliCall(1)).toBe(null);280 });281 test.each([['-R'], ['--retries']])('%s <value> should clear failed tests file', async (__retries) => {282 await run(`-R 1`);283 const { resetLastFailedTests } = require('../src/utils/lastFailedTests');284 expect(resetLastFailedTests).toHaveBeenCalled();285 });286 test.each([['-R'], ['--retries']])('%s <value> should execute unsuccessful run N extra times', async (__retries) => {287 const { loadLastFailedTests } = require('../src/utils/lastFailedTests');288 loadLastFailedTests.mockReturnValueOnce(['e2e/failing1.test.js', 'e2e/failing2.test.js']);289 loadLastFailedTests.mockReturnValueOnce(['e2e/failing2.test.js']);290 cp.execSync.mockImplementation(() => { throw new Error; });291 await run(`-R 2`).catch(_.noop);292 expect(cliCall(0).command).toMatch(/ e2e$/);293 expect(cliCall(0).env).not.toHaveProperty('DETOX_RERUN_INDEX');294 expect(cliCall(1).command).toMatch(/ e2e\/failing1.test.js e2e\/failing2.test.js$/);295 expect(cliCall(1).env.DETOX_RERUN_INDEX).toBe(1);296 expect(cliCall(2).command).toMatch(/ e2e\/failing2.test.js$/);297 expect(cliCall(2).env.DETOX_RERUN_INDEX).toBe(2);298 });299 test.each([['-R'], ['--retries']])('%s <value> should not restart test runner if there are no failing tests paths', async (__retries) => {300 const { loadLastFailedTests } = require('../src/utils/lastFailedTests');301 loadLastFailedTests.mockReturnValueOnce([]);302 cp.execSync.mockImplementation(() => { throw new Error; });303 await run(`-R 1`).catch(_.noop);304 expect(cliCall(0)).not.toBe(null);305 expect(cliCall(1)).toBe(null);306 });307 test.each([['-R'], ['--retries']])('%s <value> should retain -- <...explicitPassthroughArgs>', async (__retries) => {308 const { loadLastFailedTests } = require('../src/utils/lastFailedTests');309 loadLastFailedTests.mockReturnValue(['tests/failing.test.js']);310 cp.execSync.mockImplementation(() => { throw new Error; });311 await run(`-R 1 tests -- --debug`).catch(_.noop);312 expect(cliCall(0).command).toMatch(/ --debug .* tests$/);313 expect(cliCall(1).command).toMatch(/ --debug .* tests\/failing.test.js$/);314 });315 test.each([['-r'], ['--reuse']])('%s <value> should be passed as environment variable', async (__reuse) => {316 await run(`${__reuse}`);317 expect(cliCall().env).toEqual(expect.objectContaining({ reuse: true }));318 });319 test.each([['-u'], ['--cleanup']])('%s <value> should be passed as environment variable', async (__cleanup) => {320 await run(`${__cleanup}`);321 expect(cliCall().env).toEqual(expect.objectContaining({ cleanup: true }));322 });323 test.each([['-d'], ['--debug-synchronization']])('%s <value> should be passed as environment variable', async (__debug_synchronization) => {324 await run(`${__debug_synchronization} 5000`);325 expect(cliCall().env).toEqual(expect.objectContaining({ debugSynchronization: 5000 }));326 });327 test.each([['-d'], ['--debug-synchronization']])('%s <value> should have default value = 3000', async (__debug_synchronization) => {328 await run(`${__debug_synchronization}`);329 expect(cliCall().env).toEqual(expect.objectContaining({ debugSynchronization: 3000 }));330 });331 test.each([['-a'], ['--artifacts-location']])('%s <value> should be passed as environment variable', async (__artifacts_location) => {332 await run(`${__artifacts_location} /tmp`);333 expect(cliCall().env).toEqual(expect.objectContaining({ artifactsLocation: '/tmp' }));334 });335 test('--record-logs <value> should be passed as environment variable', async () => {336 await run(`--record-logs all`);337 expect(cliCall().env).toEqual(expect.objectContaining({ recordLogs: 'all' }));338 });339 test('--take-screenshots <value> should be passed as environment variable', async () => {340 await run(`--take-screenshots failing`);341 expect(cliCall().env).toEqual(expect.objectContaining({ takeScreenshots: 'failing' }));342 });343 test('--record-videos <value> should be passed as environment variable', async () => {344 await run(`--record-videos failing`);345 expect(cliCall().env).toEqual(expect.objectContaining({ recordVideos: 'failing' }));346 });347 test('--record-performance <value> should be passed as environment variable', async () => {348 await run(`--record-performance all`);349 expect(cliCall().env).toEqual(expect.objectContaining({ recordPerformance: 'all' }));350 });351 test('--record-timeline <value> should be passed as environment variable', async () => {352 await run(`--record-timeline all`);353 expect(cliCall().env).toEqual(expect.objectContaining({ recordTimeline: 'all' }));354 });355 test.each([['-w'], ['--workers']])('%s <value> should be passed as CLI argument', async (__workers) => {356 await run(`${__workers} 2`);357 expect(cliCall().command).toContain('--maxWorkers 2');358 });359 test.each([['-w'], ['--workers']])('%s <value> should be replaced with --maxWorkers <value>', async (__workers) => {360 await run(`${__workers} 2 --maxWorkers 3`);361 const { command } = cliCall();362 expect(command).toContain('--maxWorkers 3');363 expect(command).not.toContain('--maxWorkers 2');364 });365 test.each([['-w'], ['--workers']])('%s <value> can be overriden by a later value', async (__workers) => {366 await run(`${__workers} 2 ${__workers} 3`);367 const { command } = cliCall();368 expect(command).toContain('--maxWorkers 3');369 expect(command).not.toContain('--maxWorkers 2');370 });371 test.each([['-w'], ['--workers']])('%s <value> should not warn anything for iOS', async (__workers) => {372 singleConfig().type = 'ios.simulator';373 await run(`${__workers} 2`);374 expect(logger.warn).not.toHaveBeenCalled();375 });376 test.each([['-w'], ['--workers']])('%s <value> should not put readOnlyEmu environment variable for iOS', async (__workers) => {377 singleConfig().type = 'ios.simulator';378 await run(`${__workers} 2`);379 expect(cliCall().env).not.toHaveProperty('readOnlyEmu');380 });381 test.each([['-w'], ['--workers']])('%s <value> should put readOnlyEmu environment variable for Android if there is a single worker', async (__workers) => {382 singleConfig().type = 'android.emulator';383 await run(`${__workers} 1`);384 expect(cliCall().env).toEqual(expect.objectContaining({ readOnlyEmu: false }));385 });386 test.each([['-w'], ['--workers']])('%s <value> should put readOnlyEmu environment variable for Android if there are multiple workers', async (__workers) => {387 singleConfig().type = 'android.emulator';388 await run(`${__workers} 2`);389 expect(cliCall().env).toEqual(expect.objectContaining({ readOnlyEmu: true }));390 });391 test('should omit --testNamePattern for custom platforms', async () => {392 const customDriver = `module.exports = class CustomDriver {};`393 singleConfig().type = tempfile('.js', customDriver);394 await run();395 expect(cliCall().command).not.toContain('--testNamePattern');396 });397 test.each([['-t'], ['--testNamePattern']])('should override --testNamePattern if a custom %s value is passed', async (__testNamePattern) => {398 await run(`${__testNamePattern} customPattern`);399 const { command } = cliCall();400 expect(command).not.toMatch(/--testNamePattern .*(ios|android)/);401 expect(command).toMatch(/--testNamePattern customPattern($| )/);402 });403 test('--jest-report-specs, by default, should be true, as environment variable', async () => {404 await run();405 expect(cliCall().env).toEqual(expect.objectContaining({ reportSpecs: true }));406 });407 test('--jest-report-specs, by default, should be false, if multiple workers are enabled', async () => {408 await run('--workers 2');409 expect(cliCall().env).toEqual(expect.objectContaining({ reportSpecs: false }));410 });411 test('--jest-report-specs, set explicitly, should override single worker defaults', async () => {412 await run('--jest-report-specs false');413 expect(cliCall().env).toEqual(expect.objectContaining({ reportSpecs: false }));414 });415 test('--jest-report-specs, set explicitly, should override multiple workers defaults', async () => {416 await run('--workers 2 --jest-report-specs');417 expect(cliCall().env).toEqual(expect.objectContaining({ reportSpecs: true }));418 });419 test.each([['-H'], ['--headless']])('%s <value> should be passed as environment variable', async (__headless) => {420 await run(`${__headless}`);421 expect(cliCall().env).toEqual(expect.objectContaining({ headless: true }));422 });423 test('--gpu <value> should be passed as environment variable', async () => {424 await run(`--gpu angle_indirect`);425 expect(cliCall().env).toEqual(expect.objectContaining({ gpu: 'angle_indirect' }));426 });427 test('--device-launch-args should be passed as environment variable', async () => {428 await run(`--device-launch-args "--verbose"`);429 expect(cliCall().env).toEqual(expect.objectContaining({430 deviceLaunchArgs: '--verbose'431 }));432 });433 test('--app-launch-args should be passed as an environment variable', async () => {434 await run(`--app-launch-args "--debug yes"`);435 expect(cliCall().env).toEqual(expect.objectContaining({436 appLaunchArgs: '--debug yes',437 }));438 });439 test('--use-custom-logger false should be prevent passing environment variable', async () => {440 await run(`--use-custom-logger false`);441 expect(cliCall().env).toEqual(expect.objectContaining({442 useCustomLogger: false443 }));444 });445 test('--force-adb-install should be ignored for iOS', async () => {446 singleConfig().type = 'ios.simulator';447 await run(`--force-adb-install`);448 expect(cliCall().env).not.toHaveProperty('forceAdbInstall');449 });450 test('--force-adb-install should be passed as environment variable', async () => {451 singleConfig().type = 'android.emulator';452 await run(`--force-adb-install`);453 expect(cliCall().env).toEqual(expect.objectContaining({454 forceAdbInstall: true,455 }));456 });457 test.each([['-n'], ['--device-name']])('%s <value> should be passed as environment variable', async (__device_name) => {458 await run(`${__device_name} TheDevice`);459 expect(cliCall().env).toEqual(expect.objectContaining({460 deviceName: 'TheDevice',461 }));462 });463 test('specifying direct test paths', async () => {464 await run(`e2e/01.sanity.test.js e2e/02.sanity.test.js`);465 expect(cliCall().command).not.toMatch(/ e2e /);466 expect(cliCall().command).not.toMatch(/ e2e$/);467 expect(cliCall().command).toMatch(/ e2e\/01.sanity.test.js e2e\/02.sanity.test.js$/);468 });469 test.each([470 ['--inspect-brk e2eFolder', /^node --inspect-brk .*jest\.js .* e2eFolder$/, {}],471 ['-d e2eFolder', / e2eFolder$/, { debugSynchronization: 3000 }],472 ['--debug-synchronization e2eFolder', / e2eFolder$/, { debugSynchronization: 3000 }],473 ['-r e2eFolder', / e2eFolder$/, { reuse: true }],474 ['--reuse e2eFolder', / e2eFolder$/, { reuse: true }],475 ['-u e2eFolder', / e2eFolder$/, { cleanup: true }],476 ['--cleanup e2eFolder', / e2eFolder$/, { cleanup: true }],477 ['--jest-report-specs e2eFolder', / e2eFolder$/, { reportSpecs: true }],478 ['-H e2eFolder', / e2eFolder$/, { headless: true }],479 ['--headless e2eFolder', / e2eFolder$/, { headless: true }],480 ['--keepLockFile e2eFolder', / e2eFolder$/, {}],481 ['--use-custom-logger e2eFolder', / e2eFolder$/, { useCustomLogger: true }],482 ['--force-adb-install e2eFolder', / e2eFolder$/, { forceAdbInstall: true }],483 ])('"%s" should be disambigued correctly', async (command, commandMatcher, envMatcher) => {484 singleConfig().type = 'android.emulator';485 await run(command);486 expect(cliCall().command).toMatch(commandMatcher);487 expect(cliCall().env).toEqual(expect.objectContaining(envMatcher));488 });489 test('e.g., --debug should be passed through', async () => {490 await run(`--debug`);491 expect(cliCall().command).toContain('--debug');492 });493 test('e.g., --coverageProvider v8 should be passed through', async () => {494 await run(`--coverageProvider v8`);495 expect(cliCall().command).toContain('--coverageProvider v8');496 });497 test('e.g., --debug e2e/Login.test.js should be split to --debug and e2e/Login.test.js', async () => {498 await run(`--debug e2e/Login.test.js --coverageProvider v8`);499 expect(cliCall().command).toMatch(/--debug --coverageProvider v8 e2e\/Login.test.js$/);500 });501 test.each([502 [`--testNamePattern "should tap"`, `--testNamePattern ${quote('should tap')}`],503 [`"e2e tests/first test.spec.js"`, `"e2e tests/first test.spec.js"`],504 ])('should escape %s when forwarding it as a CLI argument', async (cmd, expected) => {505 await run(cmd);506 expect(cliCall().command).toContain(` ${expected}`);507 });508 });509 describe.each([['mocha'], ['jest']])('(%s)', (testRunner) => {510 beforeEach(() => {511 detoxConfig.testRunner = testRunner;512 });513 test(`should deduce wrapped ${testRunner} CLI`, async () => {514 detoxConfig.testRunner = `nyc ${testRunner}`;515 await run();516 expect(cliCall().command).toMatch(RegExp(`nyc ${testRunner} .* e2e$`));517 });518 describe.each([['ios.simulator'], ['android.emulator']])('for %s', (deviceType) => {519 beforeEach(() => {520 Object.values(detoxConfig.configurations)[0].type = deviceType;521 });522 test('--keepLockFile should be suppress clearing the device lock file', async () => {523 await run('--keepLockFile');524 expect(DeviceRegistry).not.toHaveBeenCalled();525 });526 test('--keepLockFile omission means clearing the device lock file', async () => {527 await run();528 expect(DeviceRegistry.mock.instances[0].reset).toHaveBeenCalled();529 });530 });531 test('-- <...explicitPassthroughArgs> should be forwarded to the test runner CLI as-is', async () => {532 await run('--device-launch-args detoxArgs e2eFolder -- a -a --a --device-launch-args runnerArgs');533 expect(cliCall().command).toMatch(/a -a --a --device-launch-args runnerArgs .* e2eFolder$/);534 expect(cliCall().env).toEqual(expect.objectContaining({ deviceLaunchArgs: 'detoxArgs' }));535 });536 test('-- <...explicitPassthroughArgs> should omit double-dash "--" itself, when forwarding args', async () => {537 await run('./detox -- --forceExit');538 expect(cliCall().command).toMatch(/ --forceExit .* \.\/detox$/);539 expect(cliCall().command).not.toMatch(/ -- --forceExit .* \.\/detox$/);540 });541 test('--inspect-brk should prepend "node --inspect-brk" to the command', async () => {542 await run('--inspect-brk');543 const absolutePathToTestRunnerJs = require.resolve(`.bin/${testRunner}`);544 expect(cliCall().command).toMatch(RegExp(`^node --inspect-brk ${absolutePathToTestRunnerJs}`));545 });546 test('should append $DETOX_ARGV_OVERRIDE to detox test ... command and print a warning', async () => {547 process.env.PLATFORM = 'ios';548 process.env.DETOX_ARGV_OVERRIDE = '--inspect-brk --testNamePattern "[$PLATFORM] tap" e2e/sanity/*.test.js';549 await run();550 const pattern = new RegExp(`^node --inspect-brk.* --testNamePattern ${quote('\\[ios\\] tap')}.* e2e/sanity/\\*\\.test.js$`);551 expect(cliCall().command).toMatch(pattern);552 expect(logger.warn).toHaveBeenCalledWith(expect.stringContaining('$DETOX_ARGV_OVERRIDE is detected'));553 });554 });555 test('should fail for unrecognized test runner', async () => {556 detoxConfig.testRunner = 'ava';557 await expect(run('--inspect-brk')).rejects.toThrowError(/ava.*is not supported/);558 });559 // Helpers560 function tempfile(extension, content) {561 const tempFilePath = require('tempfile')(extension);562 fs.ensureFileSync(tempFilePath);563 if (content) {564 fs.writeFileSync(tempFilePath, content);565 }566 temporaryFiles.push(tempFilePath);567 return tempFilePath;568 }569 async function runRaw(command = '') {570 let argv;571 try {572 argv = process.argv.splice(2, Infinity, ...command.trim().split(' '));573 return await new Promise((resolve, reject) => {574 const testCommand = require('./test');575 const originalHandler = testCommand.handler;576 const parser = yargs()577 .scriptName('detox')578 .parserConfiguration({579 'boolean-negation': false,580 'camel-case-expansion': false,581 'dot-notation': false,582 'duplicate-arguments-array': false,583 'populate--': true,584 })585 .command({586 ...testCommand,587 async handler(argv) {588 try {589 await originalHandler(argv);590 resolve();591 } catch (e) {592 reject(e);593 }594 },595 })596 .wrap(null);597 parser.parse(command, err => err && reject(err));598 });599 } finally {600 argv && process.argv.splice(2, Infinity, ...argv);601 }602 }603 async function run(command = '') {604 detoxConfigPath = tempfile('.json', JSON.stringify(detoxConfig));605 const __configPath = Math.random() > 0.5 ? '-C' : '--config-path';606 return runRaw(`test ${__configPath} ${detoxConfigPath} ${command}`);607 }608 function cliCall(index = 0) {609 const mockCall = cp.execSync.mock.calls[index];610 if (!mockCall) {611 return null;612 }613 const [command, opts] = mockCall;614 return {615 command,616 env: _.omitBy(opts.env, (_value, key) => key in process.env),617 };618 }619 function singleConfig() {620 return Object.values(detoxConfig.configurations)[0];621 }622 function isInCMD() {623 return process.platform === 'win32' && !process.env.SHELL;624 }625 function quote(s, q = isInCMD() ? `"` : `'`) {626 return q + s + q;627 }...

Full Screen

Full Screen

TryShapesMgr.js

Source:TryShapesMgr.js Github

copy

Full Screen

1/**2 *------3 * BGA framework: © Gregory Isabelli <gisabelli@boardgamearena.com> & Emmanuel Colin <ecolin@boardgamearena.com>4 * theisleofcatsbennygui implementation : © Guillaume Benny bennygui@gmail.com5 *6 * This code has been produced on the BGA studio platform for use on http://boardgamearena.com.7 * See http://en.boardgamearena.com/#!doc/Studio for more information.8 * -----9 */10define(11 [12 'dojo',13 'dojo/_base/declare',14 ],15 (dojo, declare) => {16 return declare(17 'tioc.TryShapesMgr',18 null, {19 game: null,20 isInCmd: false,21 constructor(game) {22 this.game = game;23 },24 setup(gamedatas) {25 this.game.commandMgr.registerObserver('tioc.TryShapesMgr', () => {26 this.updateButton();27 });28 },29 onEnteringState(stateName, args) {30 this.updateButton();31 },32 onLeavingState(stateName) {33 this.updateButton();34 },35 onUpdateActionButtons(stateName, args) {36 if (this.game.isSpectator) {37 return;38 }39 this.game.addActionButton(40 'button_try_shapes',41 _('Try shapes'),42 () => this.onTryShapes(),43 null, // unused44 false, // blinking45 'gray'46 );47 this.updateButton();48 },49 isTryingShapes() {50 return this.isInCmd;51 },52 updateButton() {53 const tryButton = document.getElementById('button_try_shapes');54 if (tryButton === null) {55 return;56 }57 const undoButton = document.getElementById('button_undo_try_shapes');58 const cmd = this.game.commandMgr;59 if (this.isInCmd) {60 tryButton.innerText = _('Exit "Try shapes" mode');61 if (undoButton === null) {62 this.game.addActionButton('button_undo_try_shapes', _('Undo (Try shapes)'), () => this.undoLastTryShapes());63 }64 if (cmd.currentCommandStateValue() && cmd.currentCommandStateValue().shapeList && cmd.currentCommandStateValue().shapeList.length > 0) {65 dojo.removeClass('button_undo_try_shapes', 'disabled');66 } else {67 dojo.addClass('button_undo_try_shapes', 'disabled');68 }69 cmd.disableButtons();70 this.game.islandMgr.allowTryShapes();71 } else {72 tryButton.innerText = _('Try shapes');73 if (undoButton !== null) {74 undoButton.remove();75 }76 cmd.enableButtons();77 this.game.islandMgr.disallowTryShapes();78 if (this.game.isCurrentPlayerActive()) {79 switch (this.game.gamedatas.gamestate.name) {80 case 'STATE_PHASE_ANYTIME_DRAW_AND_BOAT_SHAPE':81 this.game.islandMgr.allowTakeToPlaceShape();82 break;83 case 'STATE_FAMILY_RESCUE_CAT':84 if (!this.game.phase45Mgr.hasRescuedCat()) {85 this.game.islandMgr.allowFamilyRescueCat();86 }87 break;88 }89 }90 }91 },92 onTryShapes(initialShapeList = null) {93 const cmd = this.game.commandMgr;94 if (this.isInCmd) {95 this.isInCmd = false;96 this.updateButton();97 cmd.undo();98 this.game.boatMgr.clearTryShapes();99 return;100 }101 if (cmd.isInCommand()) {102 this.game.showMessage(_('You must finish your current action (or undo) before you can enable the "Try shapes" mode'), 'error');103 return;104 }105 this.isInCmd = true;106 this.updateButton();107 const cmdStateValue = {108 shapeList: [],109 };110 if (initialShapeList !== null) {111 debugger;112 for (const shapeInfo of initialShapeList) {113 const gridElem = document.querySelector('#tioc-player-boat-' + this.game.player_id + ' .tioc-grid.x_' + shapeInfo.x + '_y_' + shapeInfo.y);114 this.game.createShapeElement(115 gridElem.id,116 shapeInfo.shapeId + '-try-shapes',117 this.game.getShapeTypeIdFromShapeId(shapeInfo.shapeId),118 this.game.getShapeDefIdFromShapeId(shapeInfo.shapeId),119 this.game.getShapeColorIdFromShapeId(shapeInfo.shapeId)120 );121 this.game.boatMgr.applyTransformToShapeId(122 shapeInfo.shapeId + '-try-shapes',123 shapeInfo.rotation,124 shapeInfo.flipH,125 shapeInfo.flipV126 );127 for (const grid of shapeInfo.usedGrid) {128 this.game.boatMgr.markGridUsed(shapeInfo.shapeId, grid.x, grid.y, true);129 }130 const shapeClone = document.getElementById('tioc-shape-id-' + shapeInfo.shapeId + '-try-shapes');131 shapeClone.classList.add('tioc-try-shapes');132 const shape = document.getElementById('tioc-shape-id-' + shapeInfo.shapeId);133 shape.classList.add('tioc-try-shapes-hidden');134 cmdStateValue.shapeList.push(shapeInfo);135 }136 }137 cmd.startCommand(cmdStateValue);138 cmd.addSimple(139 () => {},140 () => {141 this.game.islandMgr.removeAllIslandClickable();142 this.game.shapeControl.detach();143 const tryShapes = document.querySelectorAll('.tioc-try-shapes');144 for (const shape of tryShapes) {145 shape.remove();146 }147 const shapes = document.querySelectorAll('.tioc-try-shapes-hidden');148 for (const shape of shapes) {149 shape.classList.remove('tioc-try-shapes-hidden');150 }151 for (let i = 0; i < cmdStateValue.shapeList.length; ++i) {152 this.game.boatMgr.markGridUnused(cmdStateValue.shapeList[i].shapeId, true);153 }154 this.game.boatMgr.updateGridOverlay();155 },156 );157 cmd.add(158 (onContinue, onError) => {159 this.game.islandMgr.allowTryShapes();160 },161 () => {},162 () => {},163 );164 cmd.endCommand();165 },166 undoLastTryShapes() {167 if (!this.isTryingShapes()) {168 return;169 }170 const cmd = this.game.commandMgr;171 const shapeList = dojo.clone(cmd.currentCommandStateValue().shapeList);172 if (shapeList.length > 0) {173 shapeList.pop();174 }175 this.onTryShapes();176 this.onTryShapes(shapeList);177 },178 }179 );180 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var root = require('root');2console.log(root.isInCMD());3var child = require('child');4console.log(child.isInCMD());5var grandchild = require('grandchild');6console.log(grandchild.isInCMD());7var greatgrandchild = require('greatgrandchild');8console.log(greatgrandchild.isInCMD());9var greatgreatgrandchild = require('greatgreatgrandchild');10console.log(greatgreatgrandchild.isInCMD());11var greatgreatgreatgrandchild = require('greatgreatgreatgrandchild');12console.log(greatgreatgreatgrandchild.isInCMD());13var greatgreatgreatgreatgrandchild = require('greatgreatgreatgreatgrandchild');14console.log(greatgreatgreatgreatgrandchild.isInCMD());15var greatgreatgreatgreatgreatgrandchild = require('greatgreatgreatgreatgreatgrandchild');16console.log(greatgreatgreatgreatgreatgrandchild.isInCMD());17var greatgreatgreatgreatgreatgreatgrandchild = require('greatgreatgreatgreatgreatgreatgrandchild');18console.log(greatgreatgreatgreatgreatgreatgrandchild.isInCMD());19var greatgreatgreatgreatgreatgreatgreatgrandchild = require('greatgreatgreatgreatgreatgreatgreatgrandchild');20console.log(greatgreatgreatgreatgreatgreatgreatgrandchild.isInCMD());21var greatgreatgreatgreatgreatgreatgreatgreatgrandchild = require('greatgreatgreatgreatgreatgreatgreatgreatgrandchild');22console.log(greatgreatgreatgreatgreatgreatgreatgreatgrandchild.isInCMD());23var greatgreatgreatgreatgreatgreatgreatgreatgreatgrandchild = require('greatgreatgreatgreatgreatgreatgreatgreatgreatgrandchild');24console.log(greatgreatgreatgreatgreat

Full Screen

Using AI Code Generation

copy

Full Screen

1var root = require('root');2var isCmd = root.isInCMD();3var sub = require('sub');4var isCmd = sub.isInCMD();5var root = require('root');6var isCmd = root.isInCMD();7var sub = require('sub');8var isCmd = sub.isInCMD();9var root = require('root');10var isCmd = root.isInCMD();11var sub = require('sub');12var isCmd = sub.isInCMD();

Full Screen

Using AI Code Generation

copy

Full Screen

1var root = require('root');2console.log(root.isInCMD());3module.exports = {4 isInCMD: function () {5 return typeof window === 'undefined';6 }7};8var root = require('root');9console.log(root.isInCMD());

Full Screen

Using AI Code Generation

copy

Full Screen

1var isInCMD = require('./root').isInCMD;2if(isInCMD){3 console.log("Running in command prompt");4}else{5 console.log("Not running in command prompt");6}7var isRoot = require('./root').isRoot;8if(isRoot){9 console.log("Running as root");10}else{11 console.log("Not running as root");12}13var isRootOrSudo = require('./root').isRootOrSudo;14if(isRootOrSudo){15 console.log("Running as root or sudo");16}else{17 console.log("Not running as root or sudo");18}19var isSudo = require('./root').isSudo;20if(isSudo){21 console.log("Running as sudo");22}else{23 console.log("Not running as sudo");24}25var isRootOrSudo = require('./root').isRootOrSudo;26if(isRootOrSudo){27 console.log("Running as root or sudo");28}else{29 console.log("Not running as root or sudo");30}31var isUser = require('./root').isUser;32if(isUser){33 console.log("Running as user");34}else{35 console.log("Not running as user");36}37var isUser = require('./root').isUser;38if(isUser){39 console.log("Running as user");40}else{41 console.log("Not running as user");42}43var isUser = require('./root').isUser;44if(isUser){45 console.log("Running as user");46}else{47 console.log("Not running as user");

Full Screen

Using AI Code Generation

copy

Full Screen

1var root = require('./root');2var isInCMD = root.isInCMD;3if (isInCMD()) {4 console.log('in cmd');5}6else {7 console.log('not in cmd');8}

Full Screen

Using AI Code Generation

copy

Full Screen

1var root = require('./root.js');2root.isInCMD();3var isInCMD = function() {4 console.log("isInCMD method of root");5}6exports.isInCMD = isInCMD;7var root = require('./root.js');8root.isInCMD();9var isInCMD = function() {10 console.log("isInCMD method of root");11}12exports.isInCMD = isInCMD;13var root = require('./root.js');14root.isInCMD();15var isInCMD = function() {16 console.log("isInCMD method of root");17}18exports.isInCMD = isInCMD;19var root = require('./root.js');20root.isInCMD();21var isInCMD = function() {22 console.log("isInCMD method of root");23}24exports.isInCMD = isInCMD;25var root = require('./root.js');26root.isInCMD();27var isInCMD = function() {28 console.log("isInCMD method of root");29}30exports.isInCMD = isInCMD;31var root = require('./root.js');32root.isInCMD();33var isInCMD = function() {34 console.log("isInCMD method of root");35}36exports.isInCMD = isInCMD;37var root = require('./root.js');38root.isInCMD();39var isInCMD = function() {40 console.log("isInCMD method of root");41}42exports.isInCMD = isInCMD;43var root = require('./root.js');

Full Screen

Using AI Code Generation

copy

Full Screen

1var root = require('./root.js');2var rootObj = new root();3console.log(rootObj.isInCMD());4var root = function () {5 this.isInCMD = function () {6 return (typeof window === 'undefined');7 }8}9module.exports = root;10if (typeof window === 'undefined') {11 console.log('In command prompt');12} else {13 console.log('In browser');14}

Full Screen

Using AI Code Generation

copy

Full Screen

1var root = require('./root');2var result = root.isInCMD();3console.log(result);4isInInteractive()5root.isInInteractive()6module.exports.isInInteractive = function () {7 return process.env.NODE_ENV === 'interactive';8}9var root = require('./root');10var result = root.isInInteractive();11console.log(result);12isInREPL()13root.isInREPL()14module.exports.isInREPL = function () {15 return process.env.NODE_ENV === 'repl';16}17var root = require('./root');18var result = root.isInREPL();19console.log(result);

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful