diff --git a/e2e/__tests__/install.test.js b/e2e/__tests__/install.test.js index 4082de195..49de1eac4 100644 --- a/e2e/__tests__/install.test.js +++ b/e2e/__tests__/install.test.js @@ -1,6 +1,6 @@ // @flow import path from 'path'; -import {runCli, getTempDirectory, cleanup, writeFiles} from '../helpers'; +import {run, getTempDirectory, cleanup, writeFiles} from '../helpers'; const DIR = getTempDirectory('command-install-test'); const pkg = 'react-native-config'; @@ -18,7 +18,7 @@ test.each(['yarn', 'npm'])('install module with %s', pm => { if (pm === 'yarn') { writeFiles(DIR, {'yarn.lock': ''}); } - const {stdout, code} = runCli(DIR, ['install', pkg]); + const {stdout, code} = run(DIR, ['install', pkg]); expect(stdout).toContain(`Installing "${pkg}"`); expect(stdout).toContain(`Linking "${pkg}"`); diff --git a/e2e/__tests__/uninstall.test.js b/e2e/__tests__/uninstall.test.js index 4b74187e0..1c9f6df05 100644 --- a/e2e/__tests__/uninstall.test.js +++ b/e2e/__tests__/uninstall.test.js @@ -1,5 +1,5 @@ // @flow -import {runCli, getTempDirectory, cleanup, writeFiles} from '../helpers'; +import {run, getTempDirectory, cleanup, writeFiles} from '../helpers'; const DIR = getTempDirectory('command-uninstall-test'); const pkg = 'react-native-config'; @@ -24,7 +24,7 @@ test('uninstall fails when package is not defined', () => { "dependencies": {} }`, }); - const {stderr, code} = runCli(DIR, ['uninstall']); + const {stderr, code} = run(DIR, ['uninstall']); expect(stderr).toContain('missing required argument'); expect(code).toBe(1); @@ -36,7 +36,7 @@ test('uninstall fails when package is not installed', () => { "dependencies": {} }`, }); - const {stderr, code} = runCli(DIR, ['uninstall', pkg]); + const {stderr, code} = run(DIR, ['uninstall', pkg]); expect(stderr).toContain(`Project "${pkg}" is not a react-native library`); expect(code).toBe(1); @@ -46,7 +46,7 @@ test.each(['yarn', 'npm'])('uninstall module with %s', pm => { if (pm === 'yarn') { writeFiles(DIR, {'yarn.lock': ''}); } - const {stdout, code} = runCli(DIR, ['uninstall', pkg]); + const {stdout, code} = run(DIR, ['uninstall', pkg]); expect(stdout).toContain(`Unlinking "${pkg}"`); expect(stdout).toContain(`Uninstalling "${pkg}"`); diff --git a/e2e/helpers.js b/e2e/helpers.js index a338b3798..da4dca334 100644 --- a/e2e/helpers.js +++ b/e2e/helpers.js @@ -4,33 +4,31 @@ import os from 'os'; import path from 'path'; import {createDirectory} from 'jest-util'; import rimraf from 'rimraf'; -import execa, {type SyncResult, type ThenableChildProcess} from 'execa'; +import execa from 'execa'; import {Writable} from 'readable-stream'; -import stripAnsi from 'strip-ansi'; const CLI_PATH = path.resolve(__dirname, '../packages/cli/build/bin.js'); -type RunCliOptions = { +type RunOptions = { nodeOptions?: string, nodePath?: string, - stripAnsi?: boolean, // remove colors from stdout and stderr, timeout?: number, // kill the process after X milliseconds }; -export function runCli( +export function run( dir: string, args?: Array, - options: RunCliOptions = {}, + options: RunOptions = {}, ) { return spawnCli(dir, args, options); } // Runs cli until a given output is achieved, then kills it with `SIGTERM` -export async function until( +export async function runUntil( dir: string, args: Array | void, text: string, - options: RunCliOptions = {}, + options: RunOptions = {}, ) { const spawnPromise = spawnCliAsync(dir, args, {timeout: 30000, ...options}); @@ -108,11 +106,7 @@ export const copyDir = (src: string, dest: string) => { export const getTempDirectory = (name: string) => path.resolve(os.tmpdir(), name); -function spawnCli( - dir: string, - args?: Array, - options: RunCliOptions = {}, -) { +function spawnCli(dir: string, args?: Array, options: RunOptions = {}) { const {spawnArgs, spawnOptions} = getCliArguments({dir, args, options}); return execa.sync(process.execPath, spawnArgs, spawnOptions); @@ -121,7 +115,7 @@ function spawnCli( function spawnCliAsync( dir: string, args?: Array, - options: RunCliOptions = {}, + options: RunOptions = {}, ) { const {spawnArgs, spawnOptions} = getCliArguments({dir, args, options});