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 282af43..542b5b7 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,9 +1,27 @@ import assert from 'node:assert/strict' +import { spawnSync } from 'node:child_process' import { test } from 'node:test' -import { getNpmStartOutput } from '../run-npm-start.ts' +function getOutput() { + const result = spawnSync('npm', ['start', '--silent'], { + encoding: 'utf8', + shell: true, + }) -const output = getNpmStartOutput() + 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() 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 b6dd408..551b7d1 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,10 +1,28 @@ import assert from 'node:assert/strict' +import { spawnSync } from 'node:child_process' import { readFileSync } from 'node:fs' import { test } from 'node:test' -import { getNpmStartOutput } from '../run-npm-start.ts' +function getOutput() { + const result = spawnSync('npm', ['start', '--silent'], { + encoding: 'utf8', + shell: true, + }) -const output = getNpmStartOutput() + 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() 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 e8888f8..0664624 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,9 +1,27 @@ import assert from 'node:assert/strict' +import { spawnSync } from 'node:child_process' import { test } from 'node:test' -import { getNpmStartOutput } from '../run-npm-start.ts' +function getOutput() { + const result = spawnSync('npm', ['start', '--silent'], { + encoding: 'utf8', + shell: true, + }) -const output = getNpmStartOutput() + 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 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 6edcd30..7fcefb1 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,9 +1,27 @@ import assert from 'node:assert/strict' +import { spawnSync } from 'node:child_process' import { test } from 'node:test' -import { getNpmStartOutput } from '../run-npm-start.ts' +function getOutput() { + const result = spawnSync('npm', ['start', '--silent'], { + encoding: 'utf8', + shell: true, + }) -const output = getNpmStartOutput() + 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() 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 deleted file mode 100644 index 8a1019b..0000000 --- a/exercises/01.expressions-and-output/run-npm-start.ts +++ /dev/null @@ -1,21 +0,0 @@ -import assert from 'node:assert/strict' -import { spawnSync } from 'node:child_process' - -export function getNpmStartOutput() { - const result = spawnSync('npm', ['start', '--silent'], { - encoding: 'utf8', - shell: true, - }) - - 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') -}