From dc6499548821a28e57ba7fc57b87ac9c0f7a7d74 Mon Sep 17 00:00:00 2001 From: Vlad Frangu Date: Fri, 20 Dec 2024 09:01:14 +0200 Subject: [PATCH 1/2] fix: running commands with spaces on windows --- src/lib/exec.ts | 5 ++++- test/commands/windows/create.test.ts | 31 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 test/commands/windows/create.test.ts diff --git a/src/lib/exec.ts b/src/lib/exec.ts index 34a6ceff..f0926108 100644 --- a/src/lib/exec.ts +++ b/src/lib/exec.ts @@ -1,4 +1,5 @@ import { type SpawnOptions, type SpawnOptionsWithoutStdio, spawn } from 'node:child_process'; +import { isAbsolute } from 'node:path'; import { run } from './outputs.js'; @@ -11,8 +12,10 @@ const windowsOptions: SpawnOptions = { * Run child process and returns stdout and stderr to user stout */ const spawnPromised = async (cmd: string, args: string[], opts: SpawnOptionsWithoutStdio) => { + const escapedCommand = isAbsolute(cmd) && process.platform === 'win32' ? `"${cmd}"` : cmd; + // NOTE: Pipes stderr, stdout to main process - const childProcess = spawn(cmd, args, { + const childProcess = spawn(escapedCommand, args, { ...opts, stdio: process.env.APIFY_NO_LOGS_IN_TESTS ? 'ignore' : 'inherit', ...(process.platform === 'win32' ? windowsOptions : {}), diff --git a/test/commands/windows/create.test.ts b/test/commands/windows/create.test.ts new file mode 100644 index 00000000..f14fd6d3 --- /dev/null +++ b/test/commands/windows/create.test.ts @@ -0,0 +1,31 @@ +import { existsSync } from 'node:fs'; + +import { useTempPath } from '../../__setup__/hooks/useTempPath.js'; + +const actName = 'create my actor'; +const { beforeAllCalls, afterAllCalls, tmpPath } = useTempPath(actName, { + create: true, + remove: true, + cwd: true, + cwdParent: true, +}); + +const { CreateCommand } = await import('../../../src/commands/create.js'); + +describe.runIf(process.platform === 'win32')('apify create on windows', () => { + beforeEach(async () => { + await beforeAllCalls(); + }); + + afterEach(async () => { + await afterAllCalls(); + }); + + it('works for creating an actor when the folder path contains spaces', async () => { + const ACT_TEMPLATE = 'python-playwright'; + await CreateCommand.run([actName, '--template', ACT_TEMPLATE], import.meta.url); + + // check files structure + expect(existsSync(tmpPath)).toBeTruthy(); + }); +}); From 6106491d377afabd1d351af1e76ba13c3260cc63 Mon Sep 17 00:00:00 2001 From: Vlad Frangu Date: Fri, 20 Dec 2024 09:17:55 +0200 Subject: [PATCH 2/2] chore: test correctly --- test/commands/windows/create.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/commands/windows/create.test.ts b/test/commands/windows/create.test.ts index f14fd6d3..39d15c19 100644 --- a/test/commands/windows/create.test.ts +++ b/test/commands/windows/create.test.ts @@ -2,17 +2,17 @@ import { existsSync } from 'node:fs'; import { useTempPath } from '../../__setup__/hooks/useTempPath.js'; -const actName = 'create my actor'; -const { beforeAllCalls, afterAllCalls, tmpPath } = useTempPath(actName, { +const actName = 'create-my-spaced-actor'; +const { beforeAllCalls, afterAllCalls, joinPath } = useTempPath('spaced actor', { create: true, remove: true, cwd: true, - cwdParent: true, + cwdParent: false, }); const { CreateCommand } = await import('../../../src/commands/create.js'); -describe.runIf(process.platform === 'win32')('apify create on windows', () => { +describe.runIf(process.env.FORCE_WINDOWS_TESTS || process.platform === 'win32')('apify create on windows', () => { beforeEach(async () => { await beforeAllCalls(); }); @@ -26,6 +26,6 @@ describe.runIf(process.platform === 'win32')('apify create on windows', () => { await CreateCommand.run([actName, '--template', ACT_TEMPLATE], import.meta.url); // check files structure - expect(existsSync(tmpPath)).toBeTruthy(); + expect(existsSync(joinPath(actName))).toBeTruthy(); }); });