From 3d2131e204b845d9947c4c6d5e94878474cf178d Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 6 Jul 2026 18:45:36 +0000 Subject: [PATCH 1/2] Fix Windows npm start test spawning Co-authored-by: Kent C. Dodds --- .../index.test.ts | 19 ++--------------- .../03.solution.strings/index.test.ts | 19 ++--------------- .../04.solution.numbers/index.test.ts | 19 ++--------------- .../index.test.ts | 19 ++--------------- .../run-npm-start.ts | 21 +++++++++++++++++++ 5 files changed, 29 insertions(+), 68 deletions(-) create mode 100644 exercises/01.expressions-and-output/run-npm-start.ts diff --git a/exercises/01.expressions-and-output/02.solution.escaping-strings/index.test.ts b/exercises/01.expressions-and-output/02.solution.escaping-strings/index.test.ts index 57ae972..282af43 100644 --- a/exercises/01.expressions-and-output/02.solution.escaping-strings/index.test.ts +++ b/exercises/01.expressions-and-output/02.solution.escaping-strings/index.test.ts @@ -1,24 +1,9 @@ import assert from 'node:assert/strict' -import { spawnSync } from 'node:child_process' import { test } from 'node:test' -function getOutput() { - const result = spawnSync('npm', ['start', '--silent'], { encoding: 'utf8' }) +import { getNpmStartOutput } from '../run-npm-start.ts' - if (result.error) { - throw result.error - } - - assert.strictEqual( - result.status, - 0, - result.stderr || '🚨 Running the program failed', - ) - - return result.stdout.replace(/\r\n/g, '\n') -} - -const output = getOutput() +const output = getNpmStartOutput() await test('should print apostrophe string', () => { assert.ok( diff --git a/exercises/01.expressions-and-output/03.solution.strings/index.test.ts b/exercises/01.expressions-and-output/03.solution.strings/index.test.ts index 77d60af..b6dd408 100644 --- a/exercises/01.expressions-and-output/03.solution.strings/index.test.ts +++ b/exercises/01.expressions-and-output/03.solution.strings/index.test.ts @@ -1,25 +1,10 @@ import assert from 'node:assert/strict' -import { spawnSync } from 'node:child_process' import { readFileSync } from 'node:fs' import { test } from 'node:test' -function getOutput() { - const result = spawnSync('npm', ['start', '--silent'], { encoding: 'utf8' }) +import { getNpmStartOutput } from '../run-npm-start.ts' - if (result.error) { - throw result.error - } - - assert.strictEqual( - result.status, - 0, - result.stderr || '🚨 Running the program failed', - ) - - return result.stdout.replace(/\r\n/g, '\n') -} - -const output = getOutput() +const output = getNpmStartOutput() await test('should print Hello TypeScript', () => { assert.ok( diff --git a/exercises/01.expressions-and-output/04.solution.numbers/index.test.ts b/exercises/01.expressions-and-output/04.solution.numbers/index.test.ts index fd271b9..e8888f8 100644 --- a/exercises/01.expressions-and-output/04.solution.numbers/index.test.ts +++ b/exercises/01.expressions-and-output/04.solution.numbers/index.test.ts @@ -1,24 +1,9 @@ import assert from 'node:assert/strict' -import { spawnSync } from 'node:child_process' import { test } from 'node:test' -function getOutput() { - const result = spawnSync('npm', ['start', '--silent'], { encoding: 'utf8' }) +import { getNpmStartOutput } from '../run-npm-start.ts' - if (result.error) { - throw result.error - } - - assert.strictEqual( - result.status, - 0, - result.stderr || '🚨 Running the program failed', - ) - - return result.stdout.replace(/\r\n/g, '\n') -} - -const output = getOutput() +const output = getNpmStartOutput() const lines = output .split('\n') .map((line) => line.trim()) diff --git a/exercises/01.expressions-and-output/05.solution.template-literals/index.test.ts b/exercises/01.expressions-and-output/05.solution.template-literals/index.test.ts index 9bbb99c..6edcd30 100644 --- a/exercises/01.expressions-and-output/05.solution.template-literals/index.test.ts +++ b/exercises/01.expressions-and-output/05.solution.template-literals/index.test.ts @@ -1,24 +1,9 @@ import assert from 'node:assert/strict' -import { spawnSync } from 'node:child_process' import { test } from 'node:test' -function getOutput() { - const result = spawnSync('npm', ['start', '--silent'], { encoding: 'utf8' }) +import { getNpmStartOutput } from '../run-npm-start.ts' - if (result.error) { - throw result.error - } - - assert.strictEqual( - result.status, - 0, - result.stderr || '🚨 Running the program failed', - ) - - return result.stdout.replace(/\r\n/g, '\n') -} - -const output = getOutput() +const output = getNpmStartOutput() await test('should print "The answer is 42"', () => { assert.ok( diff --git a/exercises/01.expressions-and-output/run-npm-start.ts b/exercises/01.expressions-and-output/run-npm-start.ts new file mode 100644 index 0000000..dfb499a --- /dev/null +++ b/exercises/01.expressions-and-output/run-npm-start.ts @@ -0,0 +1,21 @@ +import assert from 'node:assert/strict' +import { spawnSync } from 'node:child_process' + +export function getNpmStartOutput() { + const result = spawnSync('npm', ['start', '--silent'], { + encoding: 'utf8', + shell: process.platform === 'win32', + }) + + if (result.error) { + throw result.error + } + + assert.strictEqual( + result.status, + 0, + result.stderr || '🚨 Running the program failed', + ) + + return result.stdout.replace(/\r\n/g, '\n') +} From 0aed4d101f07dd3f634a10519176cd704788b6cf Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 6 Jul 2026 19:10:03 +0000 Subject: [PATCH 2/2] Use consistent shell spawning for npm start tests Co-authored-by: Kent C. Dodds --- exercises/01.expressions-and-output/run-npm-start.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/01.expressions-and-output/run-npm-start.ts b/exercises/01.expressions-and-output/run-npm-start.ts index dfb499a..8a1019b 100644 --- a/exercises/01.expressions-and-output/run-npm-start.ts +++ b/exercises/01.expressions-and-output/run-npm-start.ts @@ -4,7 +4,7 @@ import { spawnSync } from 'node:child_process' export function getNpmStartOutput() { const result = spawnSync('npm', ['start', '--silent'], { encoding: 'utf8', - shell: process.platform === 'win32', + shell: true, }) if (result.error) {