mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2025-05-18 12:02:53 +02:00
refactor(cli): usage of node:test instead of tap
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { PassThrough } from 'node:stream'
|
||||
import path from 'node:path'
|
||||
|
||||
import tap from 'tap'
|
||||
import sinon from 'sinon'
|
||||
import chalk from 'chalk'
|
||||
|
||||
@ -24,12 +25,12 @@ const inputLanguage = `--language=${language}`
|
||||
const inputSolution = `--solution=${solution}`
|
||||
const inputInputPath = `--input-path=${inputPath}`
|
||||
|
||||
await tap.test('programming-challenges run solution', async (t) => {
|
||||
await test('programming-challenges run solution', async (t) => {
|
||||
t.afterEach(() => {
|
||||
sinon.restore()
|
||||
})
|
||||
|
||||
await t.test('succeeds', async (t) => {
|
||||
await t.test('succeeds', async () => {
|
||||
sinon.stub(console, 'log').value(() => {})
|
||||
const consoleLogSpy = sinon.spy(console, 'log')
|
||||
const stream = new PassThrough()
|
||||
@ -49,11 +50,11 @@ await tap.test('programming-challenges run solution', async (t) => {
|
||||
}
|
||||
)
|
||||
stream.end()
|
||||
t.equal(exitCode, 0)
|
||||
t.equal(consoleLogSpy.calledWith(`Hello, world!`), true)
|
||||
assert.strictEqual(exitCode, 0)
|
||||
assert.strictEqual(consoleLogSpy.calledWith(`Hello, world!`), true)
|
||||
})
|
||||
|
||||
await t.test("fails with solution that doesn't exist", async (t) => {
|
||||
await t.test("fails with solution that doesn't exist", async () => {
|
||||
sinon.stub(console, 'error').value(() => {})
|
||||
const consoleErrorSpy = sinon.spy(console, 'error')
|
||||
const stream = new PassThrough()
|
||||
@ -74,8 +75,8 @@ await tap.test('programming-challenges run solution', async (t) => {
|
||||
}
|
||||
)
|
||||
stream.end()
|
||||
t.equal(exitCode, 1)
|
||||
t.equal(
|
||||
assert.strictEqual(exitCode, 1)
|
||||
assert.strictEqual(
|
||||
consoleErrorSpy.calledWith(
|
||||
chalk.bold.red('Error:') + ' The solution was not found.'
|
||||
),
|
||||
@ -83,7 +84,7 @@ await tap.test('programming-challenges run solution', async (t) => {
|
||||
)
|
||||
})
|
||||
|
||||
await t.test('fails with invalid language', async (t) => {
|
||||
await t.test('fails with invalid language', async () => {
|
||||
sinon.stub(console, 'error').value(() => {})
|
||||
const consoleErrorSpy = sinon.spy(console, 'error')
|
||||
const stream = new PassThrough()
|
||||
@ -104,8 +105,8 @@ await tap.test('programming-challenges run solution', async (t) => {
|
||||
}
|
||||
)
|
||||
stream.end()
|
||||
t.equal(exitCode, 1)
|
||||
t.equal(
|
||||
assert.strictEqual(exitCode, 1)
|
||||
assert.strictEqual(
|
||||
consoleErrorSpy.calledWith(
|
||||
chalk.bold.red('Error:') +
|
||||
' This programming language is not supported yet.'
|
||||
@ -114,7 +115,7 @@ await tap.test('programming-challenges run solution', async (t) => {
|
||||
)
|
||||
})
|
||||
|
||||
await t.test('fails with invalid `input-path`', async (t) => {
|
||||
await t.test('fails with invalid `input-path`', async () => {
|
||||
sinon.stub(console, 'error').value(() => {})
|
||||
const consoleErrorSpy = sinon.spy(console, 'error')
|
||||
const stream = new PassThrough()
|
||||
@ -136,8 +137,8 @@ await tap.test('programming-challenges run solution', async (t) => {
|
||||
}
|
||||
)
|
||||
stream.end()
|
||||
t.equal(exitCode, 1)
|
||||
t.equal(
|
||||
assert.strictEqual(exitCode, 1)
|
||||
assert.strictEqual(
|
||||
consoleErrorSpy.calledWith(
|
||||
chalk.bold.red('Error:') +
|
||||
` The \`input-path\` doesn't exist: ${inputPath}.`
|
||||
|
@ -1,6 +1,7 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { PassThrough } from 'node:stream'
|
||||
|
||||
import tap from 'tap'
|
||||
import sinon from 'sinon'
|
||||
import chalk from 'chalk'
|
||||
|
||||
@ -15,12 +16,12 @@ const inputChallenge = `--challenge=${challenge}`
|
||||
const inputLanguage = `--language=${language}`
|
||||
const inputSolution = `--solution=${solution}`
|
||||
|
||||
await tap.test('programming-challenges run test', async (t) => {
|
||||
await test('programming-challenges run test', async (t) => {
|
||||
t.afterEach(() => {
|
||||
sinon.restore()
|
||||
})
|
||||
|
||||
await t.test('succeeds', async (t) => {
|
||||
await t.test('succeeds', async () => {
|
||||
sinon.stub(console, 'log').value(() => {})
|
||||
const consoleLogSpy = sinon.spy(console, 'log')
|
||||
const stream = new PassThrough()
|
||||
@ -33,23 +34,26 @@ await tap.test('programming-challenges run test', async (t) => {
|
||||
}
|
||||
)
|
||||
stream.end()
|
||||
t.equal(exitCode, 0)
|
||||
t.equal(
|
||||
assert.strictEqual(exitCode, 0)
|
||||
assert.strictEqual(
|
||||
consoleLogSpy.calledWith(
|
||||
`${chalk.bold('Name:')} ${challenge}/${language}/${solution}\n`
|
||||
),
|
||||
true
|
||||
)
|
||||
t.equal(
|
||||
assert.strictEqual(
|
||||
consoleLogSpy.calledWith(
|
||||
`${chalk.bold('Tests:')} ${chalk.bold.green('3 passed')}, 3 total`
|
||||
),
|
||||
true
|
||||
)
|
||||
t.equal(consoleLogSpy.calledWith(SolutionTestsResult.SUCCESS_MESSAGE), true)
|
||||
assert.strictEqual(
|
||||
consoleLogSpy.calledWith(SolutionTestsResult.SUCCESS_MESSAGE),
|
||||
true
|
||||
)
|
||||
})
|
||||
|
||||
await t.test("fails with solution that doesn't exist", async (t) => {
|
||||
await t.test("fails with solution that doesn't exist", async () => {
|
||||
sinon.stub(console, 'error').value(() => {})
|
||||
const consoleErrorSpy = sinon.spy(console, 'error')
|
||||
const stream = new PassThrough()
|
||||
@ -64,8 +68,8 @@ await tap.test('programming-challenges run test', async (t) => {
|
||||
}
|
||||
)
|
||||
stream.end()
|
||||
t.equal(exitCode, 1)
|
||||
t.equal(
|
||||
assert.strictEqual(exitCode, 1)
|
||||
assert.strictEqual(
|
||||
consoleErrorSpy.calledWith(
|
||||
chalk.bold.red('Error:') + ' The solution was not found.'
|
||||
),
|
||||
@ -73,7 +77,7 @@ await tap.test('programming-challenges run test', async (t) => {
|
||||
)
|
||||
})
|
||||
|
||||
await t.test('fails with invalid language', async (t) => {
|
||||
await t.test('fails with invalid language', async () => {
|
||||
sinon.stub(console, 'error').value(() => {})
|
||||
const consoleErrorSpy = sinon.spy(console, 'error')
|
||||
const stream = new PassThrough()
|
||||
@ -88,8 +92,8 @@ await tap.test('programming-challenges run test', async (t) => {
|
||||
}
|
||||
)
|
||||
stream.end()
|
||||
t.equal(exitCode, 1)
|
||||
t.equal(
|
||||
assert.strictEqual(exitCode, 1)
|
||||
assert.strictEqual(
|
||||
consoleErrorSpy.calledWith(
|
||||
chalk.bold.red('Error:') +
|
||||
' This programming language is not supported yet.'
|
||||
@ -98,7 +102,7 @@ await tap.test('programming-challenges run test', async (t) => {
|
||||
)
|
||||
})
|
||||
|
||||
await t.test('fails without options', async (t) => {
|
||||
await t.test('fails without options', async () => {
|
||||
sinon.stub(console, 'error').value(() => {})
|
||||
const consoleErrorSpy = sinon.spy(console, 'error')
|
||||
const stream = new PassThrough()
|
||||
@ -108,8 +112,8 @@ await tap.test('programming-challenges run test', async (t) => {
|
||||
stderr: stream
|
||||
})
|
||||
stream.end()
|
||||
t.equal(exitCode, 1)
|
||||
t.equal(
|
||||
assert.strictEqual(exitCode, 1)
|
||||
assert.strictEqual(
|
||||
consoleErrorSpy.calledWith(
|
||||
`${chalk.bold.red(
|
||||
'Error:'
|
||||
|
Reference in New Issue
Block a user