From e0f661aa15c696c9f926f010d707ea3a6ee69003 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Thu, 9 Jan 2025 15:55:00 +0100 Subject: [PATCH 1/3] test: try running exec in tests with tinyexec --- test/e2e/commands.spec.ts | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/test/e2e/commands.spec.ts b/test/e2e/commands.spec.ts index 7b359825c..9a36ad659 100644 --- a/test/e2e/commands.spec.ts +++ b/test/e2e/commands.spec.ts @@ -1,16 +1,15 @@ import type { TestFunction } from 'vitest' import type { commands } from '../../src/commands' -import { spawnSync } from 'node:child_process' import { fileURLToPath } from 'node:url' - import { isWindows } from 'std-env' + +import { x } from 'tinyexec' import { describe, expect, it } from 'vitest' const fixtureDir = fileURLToPath(new URL('../../playground', import.meta.url)) -// TODO: fix tests on windows -describe.skipIf(isWindows)('commands', () => { +describe('commands', () => { const tests: Record> = { _dev: 'todo', add: 'todo', @@ -32,19 +31,19 @@ describe.skipIf(isWindows)('commands', () => { } it('throws error if no command is provided', async () => { - const res = spawnSync('pnpm', ['nuxi'], { - cwd: fixtureDir, + const res = await x('pnpm', ['nuxi'], { + nodeOptions: { stdio: 'pipe', cwd: fixtureDir }, }) - expect(res.status).toBe(isWindows ? null : 1) - expect(res.stderr.toString()).toBe('[error] No command specified.\n') + expect(res.exitCode).toBe(isWindows ? null : 1) + expect(res.stderr).toBe('[error] No command specified.\n') }) it('throws error if wrong command is provided', async () => { - const res = spawnSync('pnpm', ['nuxi', 'foo'], { - cwd: fixtureDir, + const res = await x('pnpm', ['nuxi', 'foo'], { + nodeOptions: { stdio: 'pipe', cwd: fixtureDir }, }) - expect(res.status).toBe(isWindows ? null : 1) - expect(res.stderr.toString()).toBe('[error] Unknown command `foo`\n') + expect(res.exitCode).toBe(isWindows ? null : 1) + expect(res.stderr).toBe('[error] Unknown command `foo`\n') }) const testsToRun = Object.entries(tests).filter(([_, value]) => value !== 'todo') From affa704e6039b33b8671b38af2d1e664121c683f Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Thu, 9 Jan 2025 16:01:57 +0100 Subject: [PATCH 2/3] test: update assertion --- test/e2e/commands.spec.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/e2e/commands.spec.ts b/test/e2e/commands.spec.ts index 9a36ad659..af22b6c73 100644 --- a/test/e2e/commands.spec.ts +++ b/test/e2e/commands.spec.ts @@ -34,7 +34,7 @@ describe('commands', () => { const res = await x('pnpm', ['nuxi'], { nodeOptions: { stdio: 'pipe', cwd: fixtureDir }, }) - expect(res.exitCode).toBe(isWindows ? null : 1) + expect(res.exitCode).toBe(1) expect(res.stderr).toBe('[error] No command specified.\n') }) @@ -42,7 +42,8 @@ describe('commands', () => { const res = await x('pnpm', ['nuxi', 'foo'], { nodeOptions: { stdio: 'pipe', cwd: fixtureDir }, }) - expect(res.exitCode).toBe(isWindows ? null : 1) + // TODO: fix this! + expect(res.exitCode).toBe(isWindows ? 0 : 1) expect(res.stderr).toBe('[error] Unknown command `foo`\n') }) From 4ef892e9ec55464f5a2c2cdd9a067f24b9526b49 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Thu, 9 Jan 2025 16:09:40 +0100 Subject: [PATCH 3/3] test: skip one test --- test/e2e/commands.spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/e2e/commands.spec.ts b/test/e2e/commands.spec.ts index af22b6c73..ce936e1c5 100644 --- a/test/e2e/commands.spec.ts +++ b/test/e2e/commands.spec.ts @@ -38,12 +38,12 @@ describe('commands', () => { expect(res.stderr).toBe('[error] No command specified.\n') }) - it('throws error if wrong command is provided', async () => { + // TODO: FIXME - windows currently throws 'nuxt-foo' is not recognized as an internal or external command, operable program or batch file. + it.skipIf(isWindows)('throws error if wrong command is provided', async () => { const res = await x('pnpm', ['nuxi', 'foo'], { nodeOptions: { stdio: 'pipe', cwd: fixtureDir }, }) - // TODO: fix this! - expect(res.exitCode).toBe(isWindows ? 0 : 1) + expect(res.exitCode).toBe(1) expect(res.stderr).toBe('[error] Unknown command `foo`\n') })