Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { platform } from 'process'
import { normalize } from 'path'
import test from 'ava'
import { each } from 'test-each'
import { getBinPathSync } from 'get-bin-path'
import execa from 'execa'
import isCi from 'is-ci'
import pathKey from 'path-key'
import nvexeca from '../src/main.js'
import { HELPER_VERSION, TEST_VERSION } from './helpers/versions.js'
const FORK_FILE = normalize(`${__dirname}/helpers/fork.js`)
const BIN_PATH = getBinPathSync()
// Those tests do not work in Travis CI with Windows.
// However they work on Windows locally.
// TODO: figure out why those tests are failing on CI.
// This will probably be fixed once nyc@15 is released.
// See https://github.com/istanbuljs/spawn-wrap/issues/108
if (platform !== 'win32' || !isCi) {
each(
[
['node', '--version'],
['node', FORK_FILE, 'node', '--version'],
['node', BIN_PATH, HELPER_VERSION, 'node', '--version'],
],
[{}, { [pathKey()]: undefined }],
({ title }, args, env) => {
test(`Works with child processes | ${title}`, async t => {
import execa from 'execa'
import { getBinPath } from 'get-bin-path'
import { nodejs } from 'figures'
const BIN_PATH = getBinPath()
// eslint-disable-next-line max-params
export const runSerial = function(opts, versionRange, args, execaOpts) {
return runCli(opts, `${versionRange} ${versionRange}`, args, execaOpts)
}
// eslint-disable-next-line max-params
export const runParallel = function(opts, versionRange, args, execaOpts) {
return runCli(
`${opts} --parallel`,
`${versionRange} ${versionRange}`,
args,
execaOpts,
)
}
import execa from 'execa'
import { getBinPath } from 'get-bin-path'
const BINARY_PATH = getBinPath()
// Call CLI command `unix-permissions COMMAND ...ARGS` and return output
export const callCli = async function(command, ...args) {
const argsA = args.map(stringifyCliArg)
const { stdout, stderr, exitCode } = await execa(
await BINARY_PATH,
[command, ...argsA],
{ reject: false },
)
const stderrA = stderr.replace(HELP_MESSAGE_REGEXP, 'Help message')
return { exitCode, stdout, stderr: stderrA }
}
import { promisify } from 'util'
import Nodemon from 'nodemon'
import { exec } from 'gulp-execa'
import { getBinPath } from 'get-bin-path'
const EXAMPLE_PATH = `${__dirname}/../examples/main.js`
const SRC_PATH = `${__dirname}/../build/src`
const BINARY_PATH = getBinPath()
// We use this instead of requiring the application to test the CLI
export const runProd = async () => {
const binaryPath = await BINARY_PATH
await exec(`node ${binaryPath}`, { cwd: 'examples' })
}
// eslint-disable-next-line fp/no-mutation
runProd.description = 'Run an example production server'
export const runDev = () => startNodemon(NODEMON_CONFIG)
// eslint-disable-next-line fp/no-mutation
runDev.description = 'Start an example dev server'
export const runDebug = () => startNodemon(DEBUG_NODEMON_CONFIG)
import { execFile } from 'child_process'
import { promisify } from 'util'
import { getBinPathSync } from 'get-bin-path'
const NVE_PATH = getBinPathSync()
const pExecFile = promisify(execFile)
const VERSION = '6.0.0'
// This must be substracted from the time taken by any of the following tasks
export const nodeVersion = {
title: 'node --version',
async main() {
await pExecFile('node', ['--version'])
},
}
// This must be substracted from the time taken by nvm
export const bash = async function() {
await pExecFile('bash', ['-i', '-c', ''])