diff --git a/tests/_runCli.ts b/tests/_runCli.ts index 52cee362b..e53adec4a 100644 --- a/tests/_runCli.ts +++ b/tests/_runCli.ts @@ -4,15 +4,11 @@ import * as path from 'path'; import {pathToFileURL} from 'url'; export async function runCli(cwd: PortablePath, argv: Array, withCustomRegistry?: boolean): Promise<{exitCode: number | null, stdout: string, stderr: string}> { - return spawnCmd(cwd, process.execPath, [`--no-warnings`, ...(withCustomRegistry ? [`--import`, pathToFileURL(path.join(__dirname, `_registryServer.mjs`)) as any as string] : [`-r`, require.resolve(`./recordRequests.js`)]), require.resolve(`../dist/corepack.js`), ...argv]); -} - -export async function spawnCmd(cwd: PortablePath, cmd: string, argv: Array): Promise<{exitCode: number | null, stdout: string, stderr: string}> { const out: Array = []; const err: Array = []; return new Promise((resolve, reject) => { - const child = spawn(cmd, argv, { + const child = spawn(process.execPath, [`--no-warnings`, ...(withCustomRegistry ? [`--import`, pathToFileURL(path.join(__dirname, `_registryServer.mjs`)) as any as string] : [`-r`, require.resolve(`./recordRequests.js`)]), require.resolve(`../dist/corepack.js`), ...argv], { cwd: npath.fromPortablePath(cwd), env: process.env, stdio: `pipe`, diff --git a/tests/main.test.ts b/tests/main.test.ts index 030717229..b0d194fc2 100644 --- a/tests/main.test.ts +++ b/tests/main.test.ts @@ -7,7 +7,7 @@ import config from '../config.json'; import * as folderUtils from '../sources/folderUtils'; import {SupportedPackageManagerSet} from '../sources/types'; -import {runCli, spawnCmd} from './_runCli'; +import {runCli} from './_runCli'; beforeEach(async () => { @@ -524,17 +524,12 @@ describe(`read-only and offline environment`, () => { // Reset to default delete process.env.COREPACK_DEFAULT_TO_LATEST; - // $ corepack enable await expect(runCli(installDir, [`enable`, `--install-directory`, npath.fromPortablePath(installDir), `yarn`])).resolves.toMatchObject({ stdout: ``, stderr: ``, exitCode: 0, }); - // Simulate the effect of `$ corepack enable` without the custom --install-directory option. - process.env.PATH = `${npath.toPortablePath(installDir)}:${process.env.PATH}`; - - // $ corepack install --global yarn@2.2.2 await expect(runCli(installDir, [`install`, `--global`, `yarn@2.2.2`])).resolves.toMatchObject({ stdout: `Installing yarn@2.2.2...\n`, stderr: ``, @@ -550,18 +545,11 @@ describe(`read-only and offline environment`, () => { process.env.HTTP_PROXY = `0.0.0.0`; process.env.HTTPS_PROXY = `0.0.0.0`; - // $ corepack yarn --version await expect(runCli(installDir, [`yarn`, `--version`])).resolves.toMatchObject({ stdout: `2.2.2\n`, stderr: ``, exitCode: 0, }); - // $ yarn --version - await expect(spawnCmd(installDir, `yarn`, [`--version`])).resolves.toMatchObject({ - stdout: `2.2.2\n`, - stderr: ``, - exitCode: 0, - }); }); }); });