Best JavaScript code snippet using root
test.test.js
Source:test.test.js
...53 });54 describe('(mocha)', () => {55 describe('given no extra args', () => {56 beforeEach(async () => run());57 test('should default to mocha', () => expect(cliCall().command).toMatch(/^mocha/));58 test('should default to --opts e2e/mocha.opts', () => expect(cliCall().command).toMatch(/--opts e2e\/mocha.opts/));59 test('should default to "e2e" test folder', () => expect(cliCall().command).toMatch(/ e2e$/));60 test('should pass --use-custom-logger true', () => expect(cliCall().command).toMatch(/--use-custom-logger true/));61 test('should not override process.env', () => expect(cliCall().env).toStrictEqual({}));62 test('should produce a default command (integration test)', () => {63 const quoteChar = detoxConfigPath.indexOf('\\') === -1 ? '' : undefined;64 const args = [65 `--opts`, `e2e/mocha.opts`,66 `--grep`, `:android:`, `--invert`,67 `--config-path`, quote(detoxConfigPath, quoteChar),68 `--use-custom-logger`, `true`69 ].join(' ');70 expect(cliCall().command).toBe(`mocha ${args} e2e`);71 });72 });73 test.each([['-o'], ['--runner-config']])('%s <path> should be aware of mocha.opts extension', async (__runnerConfig) => {74 await run(`${__runnerConfig} e2e/custom.opts`);75 expect(cliCall().command).toContain(`--opts e2e/custom.opts`);76 });77 test.each([['-o'], ['--runner-config']])('%s <path> should be aware of .mocharc extension', async (__runnerConfig) => {78 await run(`${__runnerConfig} e2e/.mocharc`);79 expect(cliCall().command).toContain(`--config e2e/.mocharc`);80 });81 test.each([['-l'], ['--loglevel']])('%s <value> should be passed as CLI argument', async (__loglevel) => {82 await run(`${__loglevel} verbose`);83 expect(cliCall().command).toContain(`--loglevel verbose`);84 });85 test('--no-color should be passed as CLI argument', async () => {86 await run(`--no-color`);87 expect(cliCall().command).toContain(' --no-colors ');88 });89 test.each([['-R'], ['--retries']])('%s <value> should print warning', async (__retries) => {90 await run(`${__retries} 1`);91 expect(logger.warn).toHaveBeenCalledWith(expect.stringContaining('Cannot use -R, --retries.'));92 });93 test.each([['-R'], ['--retries']])('%s <value> should be ignored', async (__retries) => {94 cp.execSync.mockImplementation(() => { throw new Error; });95 await run(`${__retries} 1`).catch(_.noop);96 expect(cliCall(0)).toBeDefined();97 expect(cliCall(1)).toBe(null);98 });99 test.each([['-r'], ['--reuse']])('%s <value> should be passed as CLI argument', async (__reuse) => {100 await run(`${__reuse}`);101 expect(cliCall().command).toContain('--reuse');102 });103 test.each([['-u'], ['--cleanup']])('%s <value> should be passed as CLI argument', async (__cleanup) => {104 await run(`${__cleanup}`);105 expect(cliCall().command).toContain('--cleanup');106 });107 test.each([['-d'], ['--debug-synchronization']])('%s <value> should have default value = 3000', async (__debug_synchronization) => {108 await run(`${__debug_synchronization}`);109 expect(cliCall().command).toContain('--debug-synchronization 3000');110 });111 test.each([['-d'], ['--debug-synchronization']])('%s <value> should be passed as 0 when given false', async (__debug_synchronization) => {112 await run(`${__debug_synchronization} false`);113 expect(cliCall().command).toContain('--debug-synchronization 0');114 });115 test.each([['-a'], ['--artifacts-location']])('%s <value> should be passed as CLI argument', async (__artifacts_location) => {116 await run(`${__artifacts_location} someLocation`);117 expect(cliCall().command).toContain('--artifacts-location someLocation');118 });119 test('--record-logs <value> should be passed as CLI argument', async () => {120 await run(`--record-logs all`);121 expect(cliCall().command).toContain('--record-logs all');122 });123 test('--take-screenshots <value> should be passed as CLI argument', async () => {124 await run(`--take-screenshots failing`);125 expect(cliCall().command).toContain('--take-screenshots failing');126 });127 test('--record-videos <value> should be passed as CLI argument', async () => {128 await run(`--record-videos failing`);129 expect(cliCall().command).toContain('--record-videos failing');130 });131 test('--capture-view-hierarchy <value> should be passed as CLI argument', async () => {132 await run(`--capture-view-hierarchy enabled`);133 expect(cliCall().command).toContain('--capture-view-hierarchy enabled');134 });135 test('--record-performance <value> should be passed as CLI argument', async () => {136 await run(`--record-performance all`);137 expect(cliCall().command).toContain('--record-performance all');138 });139 test('--record-timeline <value> should print "unsupported" warning', async () => {140 await run(`--record-timeline all`);141 expect(logger.warn).toHaveBeenCalledWith(expect.stringContaining('Cannot use --record-timeline.'));142 });143 test.each([['-w'], ['--workers']])('%s <value> should print "unsupported" warning', async (__workers) => {144 await run(`${__workers} 2`);145 expect(logger.warn).toHaveBeenCalledWith(expect.stringContaining('Cannot use -w, --workers.'));146 });147 test.each([['-H'], ['--headless']])('%s <value> should be passed as CLI argument', async (__headless) => {148 await run(`${__headless}`);149 expect(cliCall().command).toContain('--headless');150 });151 test('--gpu <value> should be passed as CLI argument', async () => {152 await run(`--gpu angle_indirect`);153 expect(cliCall().command).toContain('--gpu angle_indirect');154 });155 test('--device-boot-args should be passed as an environment variable (without deprecation warnings)', async () => {156 await run(`--device-boot-args "--verbose"`);157 expect(cliCall().env).toEqual({158 DETOX_DEVICE_BOOT_ARGS: '--verbose',159 });160 expect(logger.warn).not.toHaveBeenCalledWith(DEVICE_LAUNCH_ARGS_DEPRECATION);161 });162 test('--device-launch-args should serve as a deprecated alias to --device-boot-args', async () => {163 await run(`--device-launch-args "--verbose"`);164 expect(cliCall().env).toEqual({165 DETOX_DEVICE_BOOT_ARGS: '--verbose',166 });167 expect(logger.warn).toHaveBeenCalledWith(DEVICE_LAUNCH_ARGS_DEPRECATION);168 });169 test('--app-launch-args should be passed as an environment variable', async () => {170 await run(`--app-launch-args "--debug yes"`);171 expect(cliCall().env).toEqual({172 DETOX_APP_LAUNCH_ARGS: '--debug yes',173 });174 });175 test('--use-custom-logger false should be prevent passing CLI argument', async () => {176 await run(`--use-custom-logger false`);177 expect(cliCall().command).not.toContain('--use-custom-logger');178 });179 test('--force-adb-install should be ignored for iOS', async () => {180 singleConfig().type = 'ios.simulator';181 await run(`--force-adb-install`);182 expect(cliCall().command).not.toContain('--force-adb-install');183 });184 test('--force-adb-install should be passed as CLI argument for Android', async () => {185 singleConfig().type = 'android.emulator';186 await run(`--force-adb-install`);187 expect(cliCall().command).toContain('--force-adb-install');188 });189 test.each([['-n'], ['--device-name']])('%s <value> should be passed as CLI argument', async (__device_name) => {190 await run(`${__device_name} TheDevice`);191 expect(cliCall().command).toContain('--device-name TheDevice');192 });193 test('should omit --grep --invert for custom platforms', async () => {194 singleConfig().type = tempfile('.js', aCustomDriverModule());195 await run();196 expect(cliCall().command).not.toContain(' --invert ');197 expect(cliCall().command).not.toContain(' --grep ');198 });199 test('specifying direct test paths', async () => {200 await run(`e2e/01.sanity.test.js e2e/02.sanity.test.js`);201 expect(cliCall().command).not.toMatch(/ e2e /);202 expect(cliCall().command).not.toMatch(/ e2e$/);203 expect(cliCall().command).toMatch(/ e2e\/01.sanity.test.js e2e\/02.sanity.test.js$/);204 });205 test('e.g., --bail should be passed through', async () => {206 await run(`--bail`);207 expect(cliCall().command).toContain('--bail');208 });209 test('e.g., --reporter spec should be passed through', async () => {210 await run(`--reporter spec`);211 expect(cliCall().command).toContain('--reporter spec');212 });213 test('e.g., --bail e2e/Login.test.js should be split to --bail and e2e/Login.test.js', async () => {214 await run(`--bail e2e/Login.test.js --reporter spec`);215 expect(cliCall().command).toContain('--bail --reporter spec e2e/Login.test.js');216 });217 test.each([218 [`--runner-config "mocha configs/.mocharc"`, `--config ${quote('mocha configs/.mocharc')}`],219 [`--artifacts-location "artifacts dir/"`, `--artifacts-location ${quote('artifacts dir/')}`],220 [`--device-name "iPhone X"`, `--device-name ${quote('iPhone X')}`],221 [`"e2e tests/first test.spec.js"`, `"e2e tests/first test.spec.js"`],222 ])('should escape %s when forwarding it as a CLI argument', async (cmd, expected) => {223 await run(cmd);224 expect(cliCall().command).toContain(` ${expected}`);225 });226 });227 describe('(jest)', () => {228 beforeEach(() => {229 detoxConfig.testRunner = 'jest';230 });231 describe('given no extra args (iOS)', () => {232 beforeEach(async () => {233 singleConfig().type = 'ios.simulator';234 await run();235 });236 test('should produce a default command (integration test, ios)', () => {237 const args = `--config e2e/config.json --testNamePattern ${quote('^((?!:android:).)*$')} --maxWorkers 1`;238 expect(cliCall().command).toBe(`jest ${args} e2e`);239 });240 test('should put default environment variables (integration test, ios)', () => {241 expect(cliCall().env).toEqual({242 DETOX_START_TIMESTAMP: expect.any(Number),243 DETOX_CONFIG_PATH: expect.any(String),244 DETOX_REPORT_SPECS: true,245 DETOX_USE_CUSTOM_LOGGER: true,246 });247 });248 });249 describe('given no extra args (Android)', () => {250 beforeEach(async () => {251 singleConfig().type = 'android.emulator';252 await run();253 });254 test('should produce a default command (integration test)', () => {255 const args = `--config e2e/config.json --testNamePattern ${quote('^((?!:ios:).)*$')} --maxWorkers 1`;256 expect(cliCall().command).toBe(`jest ${args} e2e`);257 });258 test('should put default environment variables (integration test)', () => {259 expect(cliCall().env).toEqual({260 DETOX_START_TIMESTAMP: expect.any(Number),261 DETOX_CONFIG_PATH: expect.any(String),262 DETOX_REPORT_SPECS: true,263 DETOX_USE_CUSTOM_LOGGER: true,264 });265 });266 });267 describe('given skipLegacyWorkersInjection: true', () => {268 describe.each([269 ['ios.simulator'],270 ['android.emulator'],271 ])('for %s', (configurationType) => {272 it('should omit --maxWorkers CLI arg', async () => {273 singleConfig().type = configurationType;274 detoxConfig.skipLegacyWorkersInjection = true;275 detoxConfig.runnerConfig = 'package.json';276 await run();277 expect(cliCall().command).not.toMatch(/--maxWorkers/);278 });279 });280 });281 test.each([['-c'], ['--configuration']])(282 '%s <configuration> should provide inverted --testNamePattern that configuration (jest)',283 async (__configuration) => {284 detoxConfig.configurations.iosTest = { ...detoxConfig.configurations.single };285 detoxConfig.configurations.iosTest.type = 'ios.simulator';286 detoxConfig.configurations.androidTest = { ...detoxConfig.configurations.single };287 detoxConfig.configurations.androidTest.type = 'android.emulator';288 await run(`${__configuration} androidTest`);289 expect(cliCall(0).command).toContain(`--testNamePattern ${quote('^((?!:ios:).)*$')}`);290 expect(cliCall(0).env.DETOX_CONFIGURATION).toBe('androidTest');291 await run(`${__configuration} iosTest`);292 expect(cliCall(1).command).toContain(`--testNamePattern ${quote('^((?!:android:).)*$')}`);293 expect(cliCall(1).env.DETOX_CONFIGURATION).toBe('iosTest');294 }295 );296 test.each([['-o'], ['--runner-config']])('%s <path> should point to the specified Jest config', async (__runnerConfig) => {297 await run(`${__runnerConfig} e2e/custom.config.js`);298 expect(cliCall().command).toContain(`--config e2e/custom.config.js`);299 });300 test.each([['-l'], ['--loglevel']])('%s <value> should be passed as environment variable', async (__loglevel) => {301 await run(`${__loglevel} trace`);302 expect(cliCall().env).toEqual(expect.objectContaining({ DETOX_LOGLEVEL: 'trace' }));303 });304 test('--no-color should be passed as CLI argument', async () => {305 await run(`--no-color`);306 expect(cliCall().command).toContain(' --no-color ');307 });308 test.each([['-R'], ['--retries']])('%s <value> should execute successful run once', async (__retries) => {309 await run(`-R 1`);310 expect(cliCall(1)).toBe(null);311 });312 test.each([['-R'], ['--retries']])('%s <value> should clear failed tests file', async (__retries) => {313 await run(`-R 1`);314 const { resetLastFailedTests } = require('../src/utils/lastFailedTests');315 expect(resetLastFailedTests).toHaveBeenCalled();316 });317 test.each([['-R'], ['--retries']])('%s <value> should execute unsuccessful run N extra times', async (__retries) => {318 const { loadLastFailedTests } = require('../src/utils/lastFailedTests');319 loadLastFailedTests.mockReturnValueOnce(['e2e/failing1.test.js', 'e2e/failing2.test.js']);320 loadLastFailedTests.mockReturnValueOnce(['e2e/failing2.test.js']);321 cp.execSync.mockImplementation(() => { throw new Error; });322 await run(`-R 2`).catch(_.noop);323 expect(cliCall(0).command).toMatch(/ e2e$/);324 expect(cliCall(0).env).not.toHaveProperty('DETOX_RERUN_INDEX');325 expect(cliCall(1).command).toMatch(/ e2e\/failing1.test.js e2e\/failing2.test.js$/);326 expect(cliCall(1).env.DETOX_RERUN_INDEX).toBe(1);327 expect(cliCall(2).command).toMatch(/ e2e\/failing2.test.js$/);328 expect(cliCall(2).env.DETOX_RERUN_INDEX).toBe(2);329 });330 test.each([['-R'], ['--retries']])('%s <value> should not restart test runner if there are no failing tests paths', async (__retries) => {331 const { loadLastFailedTests } = require('../src/utils/lastFailedTests');332 loadLastFailedTests.mockReturnValueOnce([]);333 cp.execSync.mockImplementation(() => { throw new Error; });334 await run(`-R 1`).catch(_.noop);335 expect(cliCall(0)).not.toBe(null);336 expect(cliCall(1)).toBe(null);337 });338 test.each([['-R'], ['--retries']])('%s <value> should retain -- <...explicitPassthroughArgs>', async (__retries) => {339 const { loadLastFailedTests } = require('../src/utils/lastFailedTests');340 loadLastFailedTests.mockReturnValue(['tests/failing.test.js']);341 cp.execSync.mockImplementation(() => { throw new Error; });342 await run(`-R 1 tests -- --debug`).catch(_.noop);343 expect(cliCall(0).command).toMatch(/ --debug .* tests$/);344 expect(cliCall(1).command).toMatch(/ --debug .* tests\/failing.test.js$/);345 });346 test.each([['-r'], ['--reuse']])('%s <value> should be passed as environment variable', async (__reuse) => {347 await run(`${__reuse}`);348 expect(cliCall().env).toEqual(expect.objectContaining({ DETOX_REUSE: true }));349 });350 test.each([['-u'], ['--cleanup']])('%s <value> should be passed as environment variable', async (__cleanup) => {351 await run(`${__cleanup}`);352 expect(cliCall().env).toEqual(expect.objectContaining({ DETOX_CLEANUP: true }));353 });354 test.each([['-d'], ['--debug-synchronization']])('%s <value> should be passed as environment variable', async (__debug_synchronization) => {355 await run(`${__debug_synchronization} 5000`);356 expect(cliCall().env).toEqual(expect.objectContaining({ DETOX_DEBUG_SYNCHRONIZATION: 5000 }));357 });358 test.each([['-d'], ['--debug-synchronization']])('%s <value> should be passed as 0 when given false', async (__debug_synchronization) => {359 await run(`${__debug_synchronization} false`);360 expect(cliCall().env).toEqual(expect.objectContaining({ DETOX_DEBUG_SYNCHRONIZATION: 0 }));361 });362 test.each([['-d'], ['--debug-synchronization']])('%s <value> should have default value = 3000', async (__debug_synchronization) => {363 await run(`${__debug_synchronization}`);364 expect(cliCall().env).toEqual(expect.objectContaining({ DETOX_DEBUG_SYNCHRONIZATION: 3000 }));365 });366 test.each([['-a'], ['--artifacts-location']])('%s <value> should be passed as environment variable', async (__artifacts_location) => {367 await run(`${__artifacts_location} /tmp`);368 expect(cliCall().env).toEqual(expect.objectContaining({ DETOX_ARTIFACTS_LOCATION: '/tmp' }));369 });370 test('--record-logs <value> should be passed as environment variable', async () => {371 await run(`--record-logs all`);372 expect(cliCall().env).toEqual(expect.objectContaining({ DETOX_RECORD_LOGS: 'all' }));373 });374 test('--take-screenshots <value> should be passed as environment variable', async () => {375 await run(`--take-screenshots failing`);376 expect(cliCall().env).toEqual(expect.objectContaining({ DETOX_TAKE_SCREENSHOTS: 'failing' }));377 });378 test('--record-videos <value> should be passed as environment variable', async () => {379 await run(`--record-videos failing`);380 expect(cliCall().env).toEqual(expect.objectContaining({ DETOX_RECORD_VIDEOS: 'failing' }));381 });382 test('--record-performance <value> should be passed as environment variable', async () => {383 await run(`--record-performance all`);384 expect(cliCall().env).toEqual(expect.objectContaining({ DETOX_RECORD_PERFORMANCE: 'all' }));385 });386 test('--record-timeline <value> should be passed as environment variable', async () => {387 await run(`--record-timeline all`);388 expect(cliCall().env).toEqual(expect.objectContaining({ DETOX_RECORD_TIMELINE: 'all' }));389 });390 test('--capture-view-hierarchy <value> should be passed as environment variable', async () => {391 await run(`--capture-view-hierarchy enabled`);392 expect(cliCall().env).toEqual(expect.objectContaining({ DETOX_CAPTURE_VIEW_HIERARCHY: 'enabled' }));393 });394 describe.each([395 [false],396 [true],397 ])('when skipLegacyWorkersInjection is %j', (skipLegacyWorkersInjection) => {398 beforeEach(() => {399 Object.assign(detoxConfig, {400 skipLegacyWorkersInjection,401 runnerConfig: tempfile('.json', JSON.stringify({402 maxWorkers: 1,403 })),404 });405 });406 test.each([['-w'], ['--workers']])('%s <value> should be passed as CLI argument', async (__workers) => {407 await run(`${__workers} 2`);408 expect(cliCall().command).toContain('--maxWorkers 2');409 });410 test.each([['-w'], ['--workers']])('%s <value> should be replaced with --maxWorkers <value>', async (__workers) => {411 await run(`${__workers} 2 --maxWorkers 3`);412 const { command } = cliCall();413 expect(command).toContain('--maxWorkers 3');414 expect(command).not.toContain('--maxWorkers 2');415 });416 test.each([['-w'], ['--workers']])('%s <value> can be overriden by a later value', async (__workers) => {417 await run(`${__workers} 2 ${__workers} 3`);418 const { command } = cliCall();419 expect(command).toContain('--maxWorkers 3');420 expect(command).not.toContain('--maxWorkers 2');421 });422 test.each([['-w'], ['--workers']])('%s <value> should not warn anything for iOS', async (__workers) => {423 singleConfig().type = 'ios.simulator';424 await run(`${__workers} 2`);425 expect(logger.warn).not.toHaveBeenCalled();426 });427 test.each([['-w'], ['--workers']])('%s <value> should not put readOnlyEmu environment variable for iOS', async (__workers) => {428 singleConfig().type = 'ios.simulator';429 await run(`${__workers} 2`);430 expect(cliCall().env).not.toHaveProperty('DETOX_READ_ONLY_EMU');431 });432 test.each([['-w'], ['--workers']])('%s <value> should not put readOnlyEmu environment variable for android.attached', async (__workers) => {433 singleConfig().type = 'android.attached';434 await run(`${__workers} 2`);435 expect(cliCall().env).not.toHaveProperty('DETOX_READ_ONLY_EMU');436 });437 test.each([['-w'], ['--workers']])('%s <value> should not put readOnlyEmu environment variable for android.emulator if there is a single worker', async (__workers) => {438 singleConfig().type = 'android.emulator';439 await run(`${__workers} 1`);440 expect(cliCall().env).not.toHaveProperty('DETOX_READ_ONLY_EMU');441 });442 test.each([['-w'], ['--workers']])('%s <value> should put readOnlyEmu environment variable for Android if there are multiple workers', async (__workers) => {443 singleConfig().type = 'android.emulator';444 await run(`${__workers} 2`);445 expect(cliCall().env).toEqual(expect.objectContaining({ DETOX_READ_ONLY_EMU: true }));446 });447 });448 test('should omit --testNamePattern for custom platforms', async () => {449 singleConfig().type = tempfile('.js', aCustomDriverModule());450 await run();451 expect(cliCall().command).not.toContain('--testNamePattern');452 });453 test.each([['-t'], ['--testNamePattern']])('should override --testNamePattern if a custom %s value is passed', async (__testNamePattern) => {454 await run(`${__testNamePattern} customPattern`);455 const { command } = cliCall();456 expect(command).not.toMatch(/--testNamePattern .*(ios|android)/);457 expect(command).toMatch(/--testNamePattern customPattern($| )/);458 });459 test('--jest-report-specs, by default, should be true, as environment variable', async () => {460 await run();461 expect(cliCall().env).toEqual(expect.objectContaining({ DETOX_REPORT_SPECS: true }));462 });463 test('--jest-report-specs, by default, should be false, if multiple workers are enabled', async () => {464 await run('--workers 2');465 expect(cliCall().env).toEqual(expect.objectContaining({ DETOX_REPORT_SPECS: false }));466 });467 test('--jest-report-specs, set explicitly, should override single worker defaults', async () => {468 await run('--jest-report-specs false');469 expect(cliCall().env).toEqual(expect.objectContaining({ DETOX_REPORT_SPECS: false }));470 });471 test('--jest-report-specs, set explicitly, should override multiple workers defaults', async () => {472 await run('--workers 2 --jest-report-specs');473 expect(cliCall().env).toEqual(expect.objectContaining({ DETOX_REPORT_SPECS: true }));474 });475 test.each([['-H'], ['--headless']])('%s <value> should be passed as environment variable', async (__headless) => {476 await run(`${__headless}`);477 expect(cliCall().env).toEqual(expect.objectContaining({ DETOX_HEADLESS: true }));478 });479 test('--gpu <value> should be passed as environment variable', async () => {480 await run(`--gpu angle_indirect`);481 expect(cliCall().env).toEqual(expect.objectContaining({ DETOX_GPU: 'angle_indirect' }));482 });483 test('--device-boot-args should be passed as an environment variable (without deprecation warnings)', async () => {484 await run(`--device-boot-args "--verbose"`);485 expect(cliCall().env).toEqual(expect.objectContaining({486 DETOX_DEVICE_BOOT_ARGS: '--verbose'487 }));488 expect(logger.warn).not.toHaveBeenCalledWith(DEVICE_LAUNCH_ARGS_DEPRECATION);489 });490 test('--device-launch-args should serve as a deprecated alias to --device-boot-args', async () => {491 await run(`--device-launch-args "--verbose"`);492 expect(cliCall().env.DETOX_DEVICE_BOOT_ARGS).toBe('--verbose');493 expect(logger.warn).toHaveBeenCalledWith(DEVICE_LAUNCH_ARGS_DEPRECATION);494 });495 test('--app-launch-args should be passed as an environment variable', async () => {496 await run(`--app-launch-args "--debug yes"`);497 expect(cliCall().env).toEqual(expect.objectContaining({498 DETOX_APP_LAUNCH_ARGS: '--debug yes',499 }));500 });501 test('--use-custom-logger false should be prevent passing environment variable', async () => {502 await run(`--use-custom-logger false`);503 expect(cliCall().env).toEqual(expect.objectContaining({504 DETOX_USE_CUSTOM_LOGGER: false505 }));506 });507 test('--force-adb-install should be ignored for iOS', async () => {508 singleConfig().type = 'ios.simulator';509 await run(`--force-adb-install`);510 expect(cliCall().env).not.toHaveProperty('DETOX_FORCE_ADB_INSTALL');511 });512 test('--force-adb-install should be passed as environment variable', async () => {513 singleConfig().type = 'android.emulator';514 await run(`--force-adb-install`);515 expect(cliCall().env).toEqual(expect.objectContaining({516 DETOX_FORCE_ADB_INSTALL: true,517 }));518 });519 test.each([['-n'], ['--device-name']])('%s <value> should be passed as environment variable', async (__device_name) => {520 await run(`${__device_name} TheDevice`);521 expect(cliCall().env).toEqual(expect.objectContaining({522 DETOX_DEVICE_NAME: 'TheDevice',523 }));524 });525 test('specifying direct test paths', async () => {526 await run(`e2e/01.sanity.test.js e2e/02.sanity.test.js`);527 expect(cliCall().command).not.toMatch(/ e2e /);528 expect(cliCall().command).not.toMatch(/ e2e$/);529 expect(cliCall().command).toMatch(/ e2e\/01.sanity.test.js e2e\/02.sanity.test.js$/);530 });531 // TODO: fix --inspect-brk behavior on Windows, and replace (cmd|js) with js here532 test.each([533 ['--inspect-brk e2eFolder', /^node --inspect-brk .*jest\.(?:cmd|js) .* e2eFolder$/, {}],534 ['-d e2eFolder', / e2eFolder$/, { DETOX_DEBUG_SYNCHRONIZATION: 3000 }],535 ['--debug-synchronization e2eFolder', / e2eFolder$/, { DETOX_DEBUG_SYNCHRONIZATION: 3000 }],536 ['-r e2eFolder', / e2eFolder$/, { DETOX_REUSE: true }],537 ['--reuse e2eFolder', / e2eFolder$/, { DETOX_REUSE: true }],538 ['-u e2eFolder', / e2eFolder$/, { DETOX_CLEANUP: true }],539 ['--cleanup e2eFolder', / e2eFolder$/, { DETOX_CLEANUP: true }],540 ['--jest-report-specs e2eFolder', / e2eFolder$/, { DETOX_REPORT_SPECS: true }],541 ['-H e2eFolder', / e2eFolder$/, { DETOX_HEADLESS: true }],542 ['--headless e2eFolder', / e2eFolder$/, { DETOX_HEADLESS: true }],543 ['--keepLockFile e2eFolder', / e2eFolder$/, {}],544 ['--use-custom-logger e2eFolder', / e2eFolder$/, { DETOX_USE_CUSTOM_LOGGER: true }],545 ['--force-adb-install e2eFolder', / e2eFolder$/, { DETOX_FORCE_ADB_INSTALL: true }],546 ])('"%s" should be disambigued correctly', async (command, commandMatcher, envMatcher) => {547 singleConfig().type = 'android.emulator';548 await run(command);549 expect(cliCall().command).toMatch(commandMatcher);550 expect(cliCall().env).toEqual(expect.objectContaining(envMatcher));551 });552 test('e.g., --debug should be passed through', async () => {553 await run(`--debug`);554 expect(cliCall().command).toContain('--debug');555 });556 test('e.g., --coverageProvider v8 should be passed through', async () => {557 await run(`--coverageProvider v8`);558 expect(cliCall().command).toContain('--coverageProvider v8');559 });560 test('e.g., --debug e2e/Login.test.js should be split to --debug and e2e/Login.test.js', async () => {561 await run(`--debug e2e/Login.test.js --coverageProvider v8`);562 expect(cliCall().command).toMatch(/--debug --coverageProvider v8 e2e\/Login.test.js$/);563 });564 test.each([565 [`--testNamePattern "should tap"`, `--testNamePattern ${quote('should tap')}`],566 [`"e2e tests/first test.spec.js"`, `"e2e tests/first test.spec.js"`],567 ])('should escape %s when forwarding it as a CLI argument', async (cmd, expected) => {568 await run(cmd);569 expect(cliCall().command).toContain(` ${expected}`);570 });571 });572 describe.each([['mocha'], ['jest']])('(%s)', (testRunner) => {573 beforeEach(() => {574 detoxConfig.testRunner = testRunner;575 });576 test(`should deduce wrapped ${testRunner} CLI`, async () => {577 detoxConfig.testRunner = `nyc ${testRunner}`;578 await run();579 expect(cliCall().command).toMatch(RegExp(`nyc ${testRunner} .* e2e$`));580 });581 describe.each([['ios.simulator'], ['android.emulator']])('for %s', (deviceType) => {582 beforeEach(() => {583 Object.values(detoxConfig.configurations)[0].type = deviceType;584 });585 test('--keepLockFile should be suppress clearing the device lock file', async () => {586 await run('--keepLockFile');587 expect(DeviceRegistry).not.toHaveBeenCalled();588 });589 test('--keepLockFile omission means clearing the device lock file', async () => {590 await run();591 expect(DeviceRegistry.mock.instances[0].reset).toHaveBeenCalled();592 });593 });594 test('-- <...explicitPassthroughArgs> should be forwarded to the test runner CLI as-is', async () => {595 await run('--device-boot-args detoxArgs e2eFolder -- a -a --a --device-boot-args runnerArgs');596 expect(cliCall().command).toMatch(/a -a --a --device-boot-args runnerArgs .* e2eFolder$/);597 expect(cliCall().env).toEqual(expect.objectContaining({ DETOX_DEVICE_BOOT_ARGS: 'detoxArgs' }));598 });599 test('-- <...explicitPassthroughArgs> should omit double-dash "--" itself, when forwarding args', async () => {600 await run('./detox -- --forceExit');601 expect(cliCall().command).toMatch(/ --forceExit .* \.\/detox$/);602 expect(cliCall().command).not.toMatch(/ -- --forceExit .* \.\/detox$/);603 });604 test('--inspect-brk should prepend "node --inspect-brk" to the command', async () => {605 // TODO: fix --inspect-brk behavior on Windows606 if (process.platform === 'win32') return;607 await run('--inspect-brk');608 const absolutePathToTestRunnerJs = require.resolve(`.bin/${testRunner}`);609 expect(cliCall().command).toMatch(RegExp(`^node --inspect-brk ${absolutePathToTestRunnerJs}`));610 });611 test('should append $DETOX_ARGV_OVERRIDE to detox test ... command and print a warning', async () => {612 process.env.PLATFORM = 'ios';613 process.env.DETOX_ARGV_OVERRIDE = '--inspect-brk --testNamePattern "[$PLATFORM] tap" e2e/sanity/*.test.js';614 await run();615 const pattern = new RegExp(`^node --inspect-brk.* --testNamePattern ${quote('\\[ios\\] tap')}.* e2e/sanity/\\*\\.test.js$`);616 expect(cliCall().command).toMatch(pattern);617 expect(logger.warn).toHaveBeenCalledWith(expect.stringContaining('$DETOX_ARGV_OVERRIDE is detected'));618 });619 });620 test('should fail for unrecognized test runner', async () => {621 detoxConfig.testRunner = 'ava';622 await expect(run('--inspect-brk')).rejects.toThrowError(/ava.*is not supported/);623 });624 // Helpers625 function tempfile(extension, content) {626 const tempFilePath = require('tempfile')(extension);627 fs.ensureFileSync(tempFilePath);628 if (content) {629 fs.writeFileSync(tempFilePath, content);630 }631 temporaryFiles.push(tempFilePath);632 return tempFilePath;633 }634 async function runRaw(command = '') {635 let argv;636 try {637 argv = process.argv.splice(2, Infinity, ...command.trim().split(' '));638 return await new Promise((resolve, reject) => {639 const testCommand = require('./test');640 const originalHandler = testCommand.handler;641 const parser = yargs()642 .scriptName('detox')643 .parserConfiguration({644 'boolean-negation': false,645 'camel-case-expansion': false,646 'dot-notation': false,647 'duplicate-arguments-array': false,648 'populate--': true,649 })650 .command({651 ...testCommand,652 async handler(argv) {653 try {654 await originalHandler(argv);655 resolve();656 } catch (e) {657 reject(e);658 }659 },660 })661 .wrap(null);662 parser.parse(command, err => err && reject(err));663 });664 } finally {665 argv && process.argv.splice(2, Infinity, ...argv);666 }667 }668 async function run(command = '') {669 detoxConfigPath = tempfile('.json', JSON.stringify(detoxConfig));670 const __configPath = Math.random() > 0.5 ? '-C' : '--config-path';671 return runRaw(`test ${__configPath} ${detoxConfigPath} ${command}`);672 }673 function cliCall(index = 0) {674 const mockCall = cp.execSync.mock.calls[index];675 if (!mockCall) {676 return null;677 }678 const [command, opts] = mockCall;679 return {680 command,681 env: _.omitBy(opts.env, (_value, key) => key in process.env),682 };683 }684 function singleConfig() {685 return Object.values(detoxConfig.configurations)[0];686 }687 function isInCMD() {...
RTYCommon.js
Source:RTYCommon.js
1/**2 * åç
§Python模åçå®ç°3 * Created by Ian on 2016/12/25.4 */5// / æ¥æºäºNodejSç³»ç»å
ç½®ç6const sysUtil = require('util')7const sysURL = require('url')8const sysFS = require('fs')9const sysOS = require('os')10const sysCluster = require('cluster')11const sysChildProcess = require('child_process')12const sysNet = require('net')13const sysHTTP = require('http')14const sysHTTPS = require('https')15const sysEvents = require('events')16const sysDNS = require('dns')17const sysPunyCode = require('punycode')18const sysReadline = require('readline')19const sysStream = require('stream')20const sysStringDecoder = require('string_decoder')21const sysTLS = require('tls')22const sysDatagram = require('dgram')23const sysVM = require('vm')24const sysZlib = require('zlib')25const sysBuffer = require('buffer')26const sysCrypto = require('crypto')27const sysPath = require('path')28const Q = require('q')29// æå¡å¨ä¼ åå°å®¢æ·ç«¯çæ¶æ¯ç±»å30const ServerTaskMsgTypes = {31 Running: 's_task_exec_running',32 RealTimeFeedback: 's_task_exec_feedback',33 Err: 's_err_progress',34 Complete: 's_task_exec_result'35}36function obj2str (obj) {37 if (sysUtil.isObject(obj) || sysUtil.isArray(obj)) {38 return sysUtil.inspect(obj, {39 showHidden: true,40 depth: null41 })42 }43 return obj44}45function Singleton () {46 const that = this47 // æå¡å¨ä¼ åå°å®¢æ·ç«¯çæ¶æ¯ç±»å48 that.ServerTaskMsgTypes = ServerTaskMsgTypes49 that.obj2str = obj2str50 // æ¹ä¾¿è°å¼çå¤çæ¹å¼51 that.debugHandler = {}52 /**53 * app å¨readyç¶æä¸ï¼å¿
é¡»æ´æ°54 * @returns {{}|*}55 */56 that.updateDebugHandler = function () {57 const that = this58 that.debugHandler = {59 sysOS,60 sysPath,61 sysFS,62 sysBuffer,63 sysUtil,64 sysCrypto,65 sysCluster,66 sysChildProcess,67 sysNet,68 sysHTTP,69 sysHTTPS,70 sysEvents,71 sysDNS,72 sysPunyCode,73 sysReadline,74 sysStream,75 sysStringDecoder,76 sysTLS,77 sysDatagram,78 sysVM,79 sysZlib,80 //81 $END: {}82 }83 return that.debugHandler84 }85 // 对象Clone86 that.clone = function (obj) {87 //88 // We only need to clone reference types (Object)89 //90 let copy = {}91 if (obj instanceof Error) {92 // With potential custom Error objects, this might not be exactly correct,93 // but probably close-enough for purposes of this lib.94 copy = new Error(obj.message)95 Object.getOwnPropertyNames(obj).forEach(key => {96 copy[key] = obj[key]97 })98 return copy99 } else if (!(obj instanceof Object)) {100 return obj101 } else if (obj instanceof Date) {102 return new Date(obj.getTime())103 }104 for (const i in obj) {105 if (Array.isArray(obj[i])) {106 copy[i] = obj[i].slice(0)107 } else if (obj[i] instanceof Buffer) {108 copy[i] = obj[i].slice(0)109 } else if (typeof obj[i] !== 'function') {110 copy[i] = obj[i] instanceof Object ? exports.clone(obj[i]) : obj[i]111 } else if (typeof obj[i] === 'function') {112 copy[i] = obj[i]113 }114 }115 return copy116 }117 // ////////////////////////////////////////////////////////////118 // å·²ç»å è½½Moduleåå
¸119 that.globalLoadedModulesMap = {}120 // æ¥æ¾å·²ç»å è½½çModuleæ¯å¦åå¨121 that.findLoadedModuleByPath = function (modulePath) {122 const that = this123 // console.log("globalLoadedModulesMap = %s", that.obj2str(that.globalLoadedModulesMap));124 return that.globalLoadedModulesMap.hasOwnProperty(modulePath)125 }126 // æ·»å æ°çModuleå°åå
¸ä¸127 that.registerLoadedModule = function (modulePath, moduleObj) {128 const that = this129 that.globalLoadedModulesMap[modulePath] = moduleObj130 console.log('register new module, ', modulePath)131 }132 // è·åæå®çModule133 that.getLoadedModule = function (modulePath, reload) {134 const that = this135 if (that.findLoadedModuleByPath(modulePath)) {136 if (reload === true) {137 // å é¤ç¼åï¼ç¶åéæ°å è½½138 const CachesForModulePath = require.resolve(modulePath)139 console.log('CachesForModulePath = %s', CachesForModulePath)140 console.log('require.cache = %s', require.cache)141 try {142 delete require.cache[CachesForModulePath]143 delete that.globalLoadedModulesMap[modulePath]144 } catch (err) {145 console.trace(err)146 }147 } else {148 return that.globalLoadedModulesMap[modulePath]149 }150 }151 return null152 }153 // è·åJSONå符串154 that.getJSONMessage = function (info) {155 try {156 return JSON.stringify(info)157 } catch (err) {158 console.error(err)159 console.trace(err)160 }161 return ''162 }163 // è·åFunc164 that.getFunc = function (moduleName, funcName, reload) {165 const that = this166 let funcObj = null167 // Check Path is Exist?168 const modulePath = './' + moduleName169 let specModule = that.getLoadedModule(modulePath, reload)170 if (!specModule) {171 try {172 specModule = require(modulePath)173 if (specModule) {174 that.registerLoadedModule(modulePath, specModule)175 }176 } catch (err) {177 console.error(err)178 console.trace(err)179 }180 }181 if (specModule) {182 if (specModule.hasOwnProperty(funcName)) {183 const _func = specModule[funcName]184 if (sysUtil.isFunction(_func)) {185 funcObj = _func186 }187 }188 }189 if (!funcObj) {190 console.log('the Module:', moduleName, ' call ' + funcName + ' function faild....')191 }192 return funcObj193 }194 /**195 * CLIè°ç¨Agent196 */197 const CLICallAgent = (function () {198 function CLICallAgent (taskInfo, user_id, cb, event, service) {199 this.taskInfo = taskInfo200 this.user_id = user_id201 this.cb = cb202 this.event = event203 this.service = service204 this.baseInfo = {205 task_id: taskInfo.task_id,206 task_cli: taskInfo.cli,207 cb: taskInfo.callback,208 event: event209 }210 this.result = null211 }212 CLICallAgent.prototype.start = function () {213 const self = this214 self.run()215 }216 CLICallAgent.prototype.run = function () {217 const self = this218 // /////////////////////////////////////////////219 const fnSendMessageToClient = self.cb220 let result_data = null,221 cli = null,222 command = null,223 reload = false224 try {225 console.log('taskInfo = %s', obj2str(self.taskInfo))226 cli = self.taskInfo.cli227 reload = self.taskInfo.reload228 command = self.taskInfo.command229 console.log('CLICallAgent cli=%s, command=%s, reload=%d', obj2str(cli), obj2str(command), reload)230 // / å¼å§è¿è¡é¨å231 var info = self.service.clone(self.baseInfo)232 info.msg_type = ServerTaskMsgTypes.Running233 // / é
ç½®åºç¡ä¿¡æ¯234 var jsonStr = self.service.getJSONMessage(info)235 // / è¿åè°ç¨çä¿¡æ¯236 fnSendMessageToClient(self.user_id, self.event, jsonStr)237 // / å®ä¹åé¦å½æ°238 function sendFeedback (user_id, baseInfo, content, msg_type, injectedFunc) {239 const info = self.service.clone(baseInfo)240 info.msg_type = msg_type || ServerTaskMsgTypes.RealTimeFeedback241 info.content = content242 injectedFunc && injectedFunc(info) // 注å
¥å
¶ä»ä¿¡æ¯243 const jsonStr = self.service.getJSONMessage(info)244 fnSendMessageToClient(self.user_id, self.event, jsonStr) // è¿åè°ç¨çä¿¡æ¯245 }246 function fncSendFeedbackMessage (content, injectedFunc) {247 sendFeedback(self.user_id, self.baseInfo, content, ServerTaskMsgTypes.RealTimeFeedback, injectedFunc)248 }249 function fncSendResultMessage (content, injectedFunc) {250 sendFeedback(self.user_id, self.baseInfo, content, ServerTaskMsgTypes.Complete, injectedFunc)251 }252 function fncSendErrorMessage (content, injectedFunc) {253 sendFeedback(self.user_id, self.baseInfo, content, ServerTaskMsgTypes.Err, injectedFunc)254 }255 /**256 # CLI æ§è¡257 # é»è®¤ä¿®æ¹æè
建ç«æ¨¡åçå使ç¨MainRTYCLIå½æ°258 # 1.çæµæ¯å¦åå¨259 # 2.MainRTYCLI,å å
¥åæ°ï¼fncSendFeedbackMessage åé¦ä¿¡æ¯å°å®¢æ·ç«¯çå½æ°å¥æ260 #261 * */262 console.log('To find %s.MainRTYCLI', cli)263 const cliMain = self.service.getFunc(cli, 'MainRTYCLI', reload)264 if (cliMain) {265 result_data = cliMain(fncSendFeedbackMessage, command, self.baseInfo)266 } else {267 console.log('no found cliMain.......')268 }269 // å¤æresult_dataç对象类å270 if (result_data && typeof result_data.then === 'function') {271 const promise = result_data272 // promise273 promise.then(function (deferredListOrDeferred) {274 var tmpList = []275 if (Array.isArray(deferredListOrDeferred)) {276 tmpList = deferredListOrDeferred277 } else {278 tmpList.push(deferredListOrDeferred)279 }280 tmpList.forEach((oneDeferred) => {281 oneDeferred.promise.then(function (dataInfo) {282 fncSendResultMessage(dataInfo, function (info) {283 })284 })285 })286 }, function (err) {287 fncSendErrorMessage(err.message, function (info) {288 info.traceback = err.stack || ''289 info.tracebackMsg = err.stack || ''290 })291 })292 // promise end293 } else if (result_data) {294 const info = self.baseInfo295 info.msg_type = ServerTaskMsgTypes.Complete296 info.result = result_data || {}297 const jsonStr = self.service.getJSONMessage(info)298 fnSendMessageToClient(self.user_id, jsonStr)299 }300 } catch (err) {301 console.error('Exception = %s', err)302 console.trace(err)303 const info = self.service.clone(self.baseInfo)304 info.msg_type = ServerTaskMsgTypes.Err305 info.content = err.message || ''306 info.traceback = err.stack || ''307 info.tracebackMsg = err.stack || ''308 const jsonStr = self.service.getJSONMessage(info)309 fnSendMessageToClient(self.user_id, jsonStr)310 }311 }312 return CLICallAgent313 })()314 // ////////////// éç¨Callæ¹å¼315 /**316 * éè¿ååæ¹å¼ï¼è°ç¨å
¶ä»ç模åçpythonï¼å¹¶ä¸å¯ä»¥å°ä¿¡æ¯è¿åå°è°ç¨è
317 * @param taskInfo 对象ï¼ï½task_id, cli, callbackï½. ä¼ è¿æ¥çä»»å¡å¯¹è±¡318 * @param user_id æ è¯ä¸è°çè¿æ¥319 * @param cb è°ç¨æ¹ä¼ è¿æ¥çåè°å½æ°320 */321 that.callCommonCLI = function (taskInfo, user_id, cb, event) {322 const that = this323 console.log('callCommonCLI: %s', obj2str(taskInfo))324 const agent = new CLICallAgent(taskInfo, user_id, cb, event, that)325 agent.start()326 }327}328/* ************************************************************************329 Singleton CLASS DEFINITION330 ************************************************************************ */331Singleton.instance = null332/**333 * Singleton getInstance definition334 * @return Singleton class335 */336Singleton.getInstance = function () {337 const that = this338 if (that.instance === null) {339 that.instance = new Singleton()340 that.instance.updateDebugHandler()341 console.log('### <Singleton.getInstance>')342 }343 return this.instance344}...
index.ts
Source:index.ts
1import { runCLI } from "@jest/core";2import * as path from "path";3export function run(): Promise<void> {4 return new Promise<void>((c, e) => {5 // Generated files will be in out/, therefore we have another6 const projectRootPath = path.resolve(__dirname, "../../..");7 const config = path.join(projectRootPath, "jest.config.js");8 runCLI({"config": config, "runInBand": true, "$0": "", "_": []}, [projectRootPath]).9 then((jestCLICallResult) => {10 jestCLICallResult.results.testResults.forEach((testResult) => {11 testResult.testResults.12 filter((assertionResult) => assertionResult.status === "passed").13 forEach(({ ancestorTitles, title, status }) => {14 console.info(` â ${ancestorTitles} ⺠${title} (${status})`);15 });16 });17 jestCLICallResult.results.testResults.forEach((testResult) => {18 if (testResult.failureMessage) {19 console.error(testResult.failureMessage);20 }21 });22 c();23 }).catch((error) => {24 console.error(error);25 e(error);26 });27 });...
Using AI Code Generation
1var root = require('root');2root.cliCall('test2.js', 'hello', 'world');3var root = require('root');4root.cliCall('test3.js', 'hello', 'world');5var root = require('root');6root.cliCall('test4.js', 'hello', 'world');7var root = require('root');8root.cliCall('test5.js', 'hello', 'world');9var root = require('root');10root.cliCall('test6.js', 'hello', 'world');11var root = require('root');12root.cliCall('test7.js', 'hello', 'world');13var root = require('root');14root.cliCall('test8.js', 'hello', 'world');15var root = require('root');16root.cliCall('test9.js', 'hello', 'world');17var root = require('root');18root.cliCall('test10.js', 'hello', 'world');19var root = require('root');20root.cliCall('test11.js', 'hello', 'world');21var root = require('root');22root.cliCall('test12.js', 'hello', 'world');23var root = require('root');24root.cliCall('test13.js', 'hello', 'world');25var root = require('root');26root.cliCall('test14.js', 'hello', 'world');
Using AI Code Generation
1const cliCall = require('./root.js').cliCall;2const args = process.argv.slice(2);3cliCall(args);4const cliCall = require('./root.js').cliCall;5const args = process.argv.slice(2);6cliCall(args);7const cliCall = require('./root.js').cliCall;8const args = process.argv.slice(2);9cliCall(args);10const cliCall = require('./root.js').cliCall;11const args = process.argv.slice(2);12cliCall(args);13const cliCall = require('./root.js').cliCall;14const args = process.argv.slice(2);15cliCall(args);16const cliCall = require('./root.js').cliCall;17const args = process.argv.slice(2);18cliCall(args);19const cliCall = require('./root.js').cliCall;20const args = process.argv.slice(2);21cliCall(args);22const cliCall = require('./root.js').cliCall;23const args = process.argv.slice(2);24cliCall(args);25const cliCall = require('./root.js').cliCall;26const args = process.argv.slice(2);27cliCall(args);28const cliCall = require('./root.js').cliCall;29const args = process.argv.slice(2);30cliCall(args);31const cliCall = require('./root.js').cliCall;32const args = process.argv.slice(2);33cliCall(args);34const cliCall = require('./root.js').cliCall;35const args = process.argv.slice(2);36cliCall(args);
Using AI Code Generation
1var cliCall = require('cli-call').cliCall;2cliCall('node', ['--version'], function (err, stdout, stderr) {3 if (err) {4 console.log('Error: ' + err);5 return;6 }7 console.log('stdout: ' + stdout);8 console.log('stderr: ' + stderr);9});10var child = require('cli-call/child');11child.cliCall('node', ['--version'], function (err, stdout, stderr) {12 if (err) {13 console.log('Error: ' + err);14 return;15 }16 console.log('stdout: ' + stdout);17 console.log('stderr: ' + stderr);18});19var cliCallSync = require('cli-call').cliCallSync;20var result = cliCallSync('node', ['--version']);21console.log('stdout: ' + result.stdout);22console.log('stderr: ' + result.stderr);23var child = require('cli-call/child');24var result = child.cliCallSync('node', ['--version']);25console.log('stdout: ' + result.stdout);26console.log('stderr: ' + result.stderr);27var cliCall = require('cli-call').cliCall;28cliCall('node', ['--version'], function (err, stdout, stderr) {29 if (err) {30 console.log('Error: ' + err);31 return;32 }33 console.log('stdout: ' + stdout);34 console.log('stderr: ' + stderr);35});36var child = require('cli-call/child');37child.cliCall('node', ['--version'], function (err, stdout, stderr) {38 if (err) {39 console.log('Error: ' + err);40 return;41 }42 console.log('stdout: ' + stdout);43 console.log('stderr: ' + stderr);44});45var cliCallSync = require('cli-call').cliCallSync;46var result = cliCallSync('node', ['--version']);47console.log('stdout: ' + result.stdout);48console.log('stderr: ' + result.stderr);
Using AI Code Generation
1var cliCall = require('./index.js').cliCall;2cliCall('echo', ['Hello World!'], function(err, stdout, stderr) {3 if (err) {4 console.log('Error: ' + err);5 }6 else {7 console.log('Success: ' + stdout);8 }9});10var exec = require('child_process').exec;11exports.cliCall = function(cmd, args, callback) {12 var child = exec(cmd + ' ' + args.join(' '), function(err, stdout, stderr) {13 callback(err, stdout, stderr);14 });15};
Using AI Code Generation
1var rootkit = require('rootkit');2rootkit.cliCall("ls -l", function(err, stdout, stderr) {3 console.log(stdout);4 console.log(stderr);5});6var rootkit = require('rootkit');7rootkit.cliCall("ls -l", function(err, stdout, stderr) {8 console.log(stdout);9 console.log(stderr);10});11var rootkit = require('rootkit');12rootkit.cliCall("ls -l", function(err, stdout, stderr) {13 console.log(stdout);14 console.log(stderr);15});16var rootkit = require('rootkit');17rootkit.cliCall("ls -l", function(err, stdout, stderr) {18 console.log(stdout);19 console.log(stderr);20});21var rootkit = require('rootkit');22rootkit.cliCall("ls -l", function(err, stdout, stderr) {23 console.log(stdout);24 console.log(stderr);25});26var rootkit = require('rootkit');27rootkit.cliCall("ls -l", function(err, stdout, stderr) {28 console.log(stdout);29 console.log(stderr);30});31var rootkit = require('rootkit');32rootkit.cliCall("ls -l", function(err, stdout, stderr) {33 console.log(stdout);34 console.log(stderr);35});36var rootkit = require('rootkit');37rootkit.cliCall("ls -l", function(err, stdout, stderr) {38 console.log(stdout);39 console.log(stderr);40});41var rootkit = require('rootkit');42rootkit.cliCall("ls -l", function(err, stdout, stderr) {43 console.log(stdout);44 console.log(stderr);45});46var rootkit = require('rootkit');47rootkit.cliCall("ls -l", function(err, stdout, stderr) {48 console.log(stdout);49 console.log(stderr);50});51var rootkit = require('rootkit');52rootkit.cliCall("ls -l
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!