1
1
mirror of https://github.com/theoludwig/programming-challenges.git synced 2024-12-08 00:45:29 +01:00

refactor(cli): usage of node:test instead of tap

This commit is contained in:
Théo LUDWIG 2023-07-20 22:00:11 +02:00
parent c25eeaaa98
commit c53c2997ec
Signed by: theoludwig
GPG Key ID: ADFE5A563D718F3B
19 changed files with 647 additions and 4418 deletions

View File

@ -4,12 +4,15 @@
"parserOptions": { "parserOptions": {
"project": "./tsconfig.json" "project": "./tsconfig.json"
}, },
"env": {
"node": true
},
"rules": { "rules": {
"import/extensions": ["error", "always"], "import/extensions": ["error", "always"],
"unicorn/prevent-abbreviations": "error", "unicorn/prevent-abbreviations": "error",
"unicorn/prefer-node-protocol": "error" "unicorn/prefer-node-protocol": "error"
} },
"overrides": [
{
"files": ["*.ts", "*.tsx"],
"parser": "@typescript-eslint/parser"
}
]
} }

9
.taprc
View File

@ -1,9 +0,0 @@
ts: false
jsx: false
flow: false
check-coverage: false
coverage: false
timeout: 60000
files:
- 'build/**/*.test.js'

View File

@ -58,7 +58,7 @@ If you're adding new features to **programming-challenges**, please include test
## Commits ## Commits
The commit message guidelines adheres to [Conventional Commits](https://www.conventionalcommits.org/) and [Semantic Versioning](https://semver.org/) for releases. | The commit message guidelines adheres to [Conventional Commits](https://www.conventionalcommits.org/).
### Examples ### Examples

View File

@ -24,7 +24,7 @@
Each challenge has its **solutions**, its **instructions** and **input/output examples** so you can try to solve them on your own. See [challenges](./challenges) folder. Each challenge has its **solutions**, its **instructions** and **input/output examples** so you can try to solve them on your own. See [challenges](./challenges) folder.
[Related Blog Post](https://theoludwig.fr/blog/programming-challenges/). [🧠 Programming Challenges - Blog Post](https://theoludwig.fr/blog/programming-challenges/).
### ✅ Programming languages available ### ✅ Programming languages available

View File

@ -1,8 +1,9 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import { PassThrough } from 'node:stream' import { PassThrough } from 'node:stream'
import path from 'node:path' import path from 'node:path'
import fs from 'node:fs' import fs from 'node:fs'
import tap from 'tap'
import sinon from 'sinon' import sinon from 'sinon'
import fsMock from 'mock-fs' import fsMock from 'mock-fs'
import chalk from 'chalk' import chalk from 'chalk'
@ -18,7 +19,7 @@ const challenge = 'aaaa-test-jest'
const inputChallenge = `--challenge=${challenge}` const inputChallenge = `--challenge=${challenge}`
const inputGitHubUser = `--github-user=${githubUser}` const inputGitHubUser = `--github-user=${githubUser}`
await tap.test('programming-challenges generate challenge', async (t) => { await test('programming-challenges generate challenge', async (t) => {
t.beforeEach(() => { t.beforeEach(() => {
fsMock( fsMock(
{ {
@ -36,7 +37,7 @@ await tap.test('programming-challenges generate challenge', async (t) => {
sinon.restore() sinon.restore()
}) })
await t.test('succeeds and generate the new challenge', async (t) => { await t.test('succeeds and generate the new challenge', async () => {
sinon.stub(console, 'log').value(() => {}) sinon.stub(console, 'log').value(() => {})
const consoleLogSpy = sinon.spy(console, 'log') const consoleLogSpy = sinon.spy(console, 'log')
const dateString = date.format(new Date(), 'D MMMM Y', true) const dateString = date.format(new Date(), 'D MMMM Y', true)
@ -50,7 +51,7 @@ await tap.test('programming-challenges generate challenge', async (t) => {
} }
) )
stream.end() stream.end()
t.equal(exitCode, 0) assert.strictEqual(exitCode, 0)
const challengePath = path.join(process.cwd(), 'challenges', challenge) const challengePath = path.join(process.cwd(), 'challenges', challenge)
const readmePath = path.join(challengePath, 'README.md') const readmePath = path.join(challengePath, 'README.md')
const readmeContent = await fs.promises.readFile(readmePath, { const readmeContent = await fs.promises.readFile(readmePath, {
@ -59,9 +60,9 @@ await tap.test('programming-challenges generate challenge', async (t) => {
const successMessage = `${chalk.bold.green( const successMessage = `${chalk.bold.green(
'Success:' 'Success:'
)} created the new challenge at ${challengePath}.` )} created the new challenge at ${challengePath}.`
t.equal(consoleLogSpy.calledWith(successMessage), true) assert.strictEqual(consoleLogSpy.calledWith(successMessage), true)
t.equal(await isExistingPath(challengePath), true) assert.strictEqual(await isExistingPath(challengePath), true)
t.equal( assert.strictEqual(
readmeContent, readmeContent,
`# ${challenge} `# ${challenge}
@ -78,7 +79,7 @@ See the \`test\` folder for examples of input/output.
) )
}) })
await t.test('fails without options', async (t) => { await t.test('fails without options', async () => {
const stream = new PassThrough() const stream = new PassThrough()
const promise = getStream(stream) const promise = getStream(stream)
const exitCode = await cli.run(input, { const exitCode = await cli.run(input, {
@ -87,12 +88,12 @@ See the \`test\` folder for examples of input/output.
stderr: stream stderr: stream
}) })
stream.end() stream.end()
t.equal(exitCode, 1) assert.strictEqual(exitCode, 1)
const output = await promise const output = await promise
t.match(output, 'Unknown Syntax Error') assert.match(output, /Unknown Syntax Error/)
}) })
await t.test('fails with already existing challenge', async (t) => { await t.test('fails with already existing challenge', async () => {
sinon.stub(console, 'error').value(() => {}) sinon.stub(console, 'error').value(() => {})
const consoleErrorSpy = sinon.spy(console, 'error') const consoleErrorSpy = sinon.spy(console, 'error')
const stream = new PassThrough() const stream = new PassThrough()
@ -105,8 +106,8 @@ See the \`test\` folder for examples of input/output.
} }
) )
stream.end() stream.end()
t.equal(exitCode, 1) assert.strictEqual(exitCode, 1)
t.equal( assert.strictEqual(
consoleErrorSpy.calledWith( consoleErrorSpy.calledWith(
`${chalk.bold.red('Error:')} The challenge already exists: hello-world.` `${chalk.bold.red('Error:')} The challenge already exists: hello-world.`
), ),
@ -114,7 +115,7 @@ See the \`test\` folder for examples of input/output.
) )
}) })
await t.test('fails with invalid challenge name', async (t) => { await t.test('fails with invalid challenge name', async () => {
sinon.stub(console, 'error').value(() => {}) sinon.stub(console, 'error').value(() => {})
const consoleErrorSpy = sinon.spy(console, 'error') const consoleErrorSpy = sinon.spy(console, 'error')
const stream = new PassThrough() const stream = new PassThrough()
@ -127,8 +128,8 @@ See the \`test\` folder for examples of input/output.
} }
) )
stream.end() stream.end()
t.equal(exitCode, 1) assert.strictEqual(exitCode, 1)
t.equal( assert.strictEqual(
consoleErrorSpy.calledWith( consoleErrorSpy.calledWith(
`${chalk.bold.red('Error:')} Invalid challenge name.` `${chalk.bold.red('Error:')} Invalid challenge name.`
), ),

View File

@ -1,8 +1,9 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import { PassThrough } from 'node:stream' import { PassThrough } from 'node:stream'
import path from 'node:path' import path from 'node:path'
import fs from 'node:fs' import fs from 'node:fs'
import tap from 'tap'
import sinon from 'sinon' import sinon from 'sinon'
import fsMock from 'mock-fs' import fsMock from 'mock-fs'
import chalk from 'chalk' import chalk from 'chalk'
@ -22,7 +23,7 @@ const inputGitHubUser = `--github-user=${githubUser}`
const inputLanguage = `--language=${language}` const inputLanguage = `--language=${language}`
const inputSolution = `--solution=${solution}` const inputSolution = `--solution=${solution}`
await tap.test('programming-challenges generate solution', async (t) => { await test('programming-challenges generate solution', async (t) => {
t.beforeEach(() => { t.beforeEach(() => {
fsMock( fsMock(
{ {
@ -37,7 +38,7 @@ await tap.test('programming-challenges generate solution', async (t) => {
sinon.restore() sinon.restore()
}) })
await t.test('succeeds and generate the new solution', async (t) => { await t.test('succeeds and generate the new solution', async () => {
sinon.stub(console, 'log').value(() => {}) sinon.stub(console, 'log').value(() => {})
const consoleLogSpy = sinon.spy(console, 'log') const consoleLogSpy = sinon.spy(console, 'log')
const dateString = date.format(new Date(), 'D MMMM Y', true) const dateString = date.format(new Date(), 'D MMMM Y', true)
@ -51,7 +52,7 @@ await tap.test('programming-challenges generate solution', async (t) => {
} }
) )
stream.end() stream.end()
t.equal(exitCode, 0) assert.strictEqual(exitCode, 0)
const solutionPath = path.join( const solutionPath = path.join(
process.cwd(), process.cwd(),
'challenges', 'challenges',
@ -67,9 +68,9 @@ await tap.test('programming-challenges generate solution', async (t) => {
const successMessage = `${chalk.bold.green( const successMessage = `${chalk.bold.green(
'Success:' 'Success:'
)} created the new solution at ${solutionPath}.` )} created the new solution at ${solutionPath}.`
t.equal(consoleLogSpy.calledWith(successMessage), true) assert.strictEqual(consoleLogSpy.calledWith(successMessage), true)
t.equal(await isExistingPath(solutionPath), true) assert.strictEqual(await isExistingPath(solutionPath), true)
t.equal( assert.strictEqual(
readmeContent, readmeContent,
`# ${challenge}/${language}/${solution} `# ${challenge}/${language}/${solution}
@ -78,7 +79,7 @@ Created by [@${githubUser}](https://github.com/${githubUser}) on ${dateString}.
) )
}) })
await t.test("fails with challenges that doesn't exist", async (t) => { await t.test("fails with challenges that doesn't exist", async () => {
sinon.stub(console, 'error').value(() => {}) sinon.stub(console, 'error').value(() => {})
const consoleErrorSpy = sinon.spy(console, 'error') const consoleErrorSpy = sinon.spy(console, 'error')
const stream = new PassThrough() const stream = new PassThrough()
@ -99,8 +100,8 @@ Created by [@${githubUser}](https://github.com/${githubUser}) on ${dateString}.
} }
) )
stream.end() stream.end()
t.equal(exitCode, 1) assert.strictEqual(exitCode, 1)
t.equal( assert.strictEqual(
consoleErrorSpy.calledWith( consoleErrorSpy.calledWith(
chalk.bold.red('Error:') + chalk.bold.red('Error:') +
` The challenge doesn't exist yet: ${invalidChallenge}.` ` The challenge doesn't exist yet: ${invalidChallenge}.`
@ -109,7 +110,7 @@ Created by [@${githubUser}](https://github.com/${githubUser}) on ${dateString}.
) )
}) })
await t.test('fails with solution that already exist', async (t) => { await t.test('fails with solution that already exist', async () => {
sinon.stub(console, 'error').value(() => {}) sinon.stub(console, 'error').value(() => {})
const consoleErrorSpy = sinon.spy(console, 'error') const consoleErrorSpy = sinon.spy(console, 'error')
const stream = new PassThrough() const stream = new PassThrough()
@ -130,8 +131,8 @@ Created by [@${githubUser}](https://github.com/${githubUser}) on ${dateString}.
} }
) )
stream.end() stream.end()
t.equal(exitCode, 1) assert.strictEqual(exitCode, 1)
t.equal( assert.strictEqual(
consoleErrorSpy.calledWith( consoleErrorSpy.calledWith(
chalk.bold.red('Error:') + chalk.bold.red('Error:') +
` The solution already exists: ${invalidSolution}.` ` The solution already exists: ${invalidSolution}.`
@ -140,7 +141,7 @@ Created by [@${githubUser}](https://github.com/${githubUser}) on ${dateString}.
) )
}) })
await t.test('fails with invalid language', async (t) => { await t.test('fails with invalid language', async () => {
sinon.stub(console, 'error').value(() => {}) sinon.stub(console, 'error').value(() => {})
const consoleErrorSpy = sinon.spy(console, 'error') const consoleErrorSpy = sinon.spy(console, 'error')
const stream = new PassThrough() const stream = new PassThrough()
@ -161,8 +162,8 @@ Created by [@${githubUser}](https://github.com/${githubUser}) on ${dateString}.
} }
) )
stream.end() stream.end()
t.equal(exitCode, 1) assert.strictEqual(exitCode, 1)
t.equal( assert.strictEqual(
consoleErrorSpy.calledWith( consoleErrorSpy.calledWith(
chalk.bold.red('Error:') + chalk.bold.red('Error:') +
' This programming language is not supported yet.' ' This programming language is not supported yet.'
@ -180,8 +181,8 @@ Created by [@${githubUser}](https://github.com/${githubUser}) on ${dateString}.
stderr: stream stderr: stream
}) })
stream.end() stream.end()
t.equal(exitCode, 1) assert.strictEqual(exitCode, 1)
const output = await promise const output = await promise
t.match(output, 'Unknown Syntax Error') assert.match(output, /Unknown Syntax Error/)
}) })
}) })

View File

@ -1,7 +1,8 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import { PassThrough } from 'node:stream' import { PassThrough } from 'node:stream'
import path from 'node:path' import path from 'node:path'
import tap from 'tap'
import sinon from 'sinon' import sinon from 'sinon'
import chalk from 'chalk' import chalk from 'chalk'
@ -24,12 +25,12 @@ const inputLanguage = `--language=${language}`
const inputSolution = `--solution=${solution}` const inputSolution = `--solution=${solution}`
const inputInputPath = `--input-path=${inputPath}` const inputInputPath = `--input-path=${inputPath}`
await tap.test('programming-challenges run solution', async (t) => { await test('programming-challenges run solution', async (t) => {
t.afterEach(() => { t.afterEach(() => {
sinon.restore() sinon.restore()
}) })
await t.test('succeeds', async (t) => { await t.test('succeeds', async () => {
sinon.stub(console, 'log').value(() => {}) sinon.stub(console, 'log').value(() => {})
const consoleLogSpy = sinon.spy(console, 'log') const consoleLogSpy = sinon.spy(console, 'log')
const stream = new PassThrough() const stream = new PassThrough()
@ -49,11 +50,11 @@ await tap.test('programming-challenges run solution', async (t) => {
} }
) )
stream.end() stream.end()
t.equal(exitCode, 0) assert.strictEqual(exitCode, 0)
t.equal(consoleLogSpy.calledWith(`Hello, world!`), true) 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(() => {}) sinon.stub(console, 'error').value(() => {})
const consoleErrorSpy = sinon.spy(console, 'error') const consoleErrorSpy = sinon.spy(console, 'error')
const stream = new PassThrough() const stream = new PassThrough()
@ -74,8 +75,8 @@ await tap.test('programming-challenges run solution', async (t) => {
} }
) )
stream.end() stream.end()
t.equal(exitCode, 1) assert.strictEqual(exitCode, 1)
t.equal( assert.strictEqual(
consoleErrorSpy.calledWith( consoleErrorSpy.calledWith(
chalk.bold.red('Error:') + ' The solution was not found.' 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(() => {}) sinon.stub(console, 'error').value(() => {})
const consoleErrorSpy = sinon.spy(console, 'error') const consoleErrorSpy = sinon.spy(console, 'error')
const stream = new PassThrough() const stream = new PassThrough()
@ -104,8 +105,8 @@ await tap.test('programming-challenges run solution', async (t) => {
} }
) )
stream.end() stream.end()
t.equal(exitCode, 1) assert.strictEqual(exitCode, 1)
t.equal( assert.strictEqual(
consoleErrorSpy.calledWith( consoleErrorSpy.calledWith(
chalk.bold.red('Error:') + chalk.bold.red('Error:') +
' This programming language is not supported yet.' ' 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(() => {}) sinon.stub(console, 'error').value(() => {})
const consoleErrorSpy = sinon.spy(console, 'error') const consoleErrorSpy = sinon.spy(console, 'error')
const stream = new PassThrough() const stream = new PassThrough()
@ -136,8 +137,8 @@ await tap.test('programming-challenges run solution', async (t) => {
} }
) )
stream.end() stream.end()
t.equal(exitCode, 1) assert.strictEqual(exitCode, 1)
t.equal( assert.strictEqual(
consoleErrorSpy.calledWith( consoleErrorSpy.calledWith(
chalk.bold.red('Error:') + chalk.bold.red('Error:') +
` The \`input-path\` doesn't exist: ${inputPath}.` ` The \`input-path\` doesn't exist: ${inputPath}.`

View File

@ -1,6 +1,7 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import { PassThrough } from 'node:stream' import { PassThrough } from 'node:stream'
import tap from 'tap'
import sinon from 'sinon' import sinon from 'sinon'
import chalk from 'chalk' import chalk from 'chalk'
@ -15,12 +16,12 @@ const inputChallenge = `--challenge=${challenge}`
const inputLanguage = `--language=${language}` const inputLanguage = `--language=${language}`
const inputSolution = `--solution=${solution}` const inputSolution = `--solution=${solution}`
await tap.test('programming-challenges run test', async (t) => { await test('programming-challenges run test', async (t) => {
t.afterEach(() => { t.afterEach(() => {
sinon.restore() sinon.restore()
}) })
await t.test('succeeds', async (t) => { await t.test('succeeds', async () => {
sinon.stub(console, 'log').value(() => {}) sinon.stub(console, 'log').value(() => {})
const consoleLogSpy = sinon.spy(console, 'log') const consoleLogSpy = sinon.spy(console, 'log')
const stream = new PassThrough() const stream = new PassThrough()
@ -33,23 +34,26 @@ await tap.test('programming-challenges run test', async (t) => {
} }
) )
stream.end() stream.end()
t.equal(exitCode, 0) assert.strictEqual(exitCode, 0)
t.equal( assert.strictEqual(
consoleLogSpy.calledWith( consoleLogSpy.calledWith(
`${chalk.bold('Name:')} ${challenge}/${language}/${solution}\n` `${chalk.bold('Name:')} ${challenge}/${language}/${solution}\n`
), ),
true true
) )
t.equal( assert.strictEqual(
consoleLogSpy.calledWith( consoleLogSpy.calledWith(
`${chalk.bold('Tests:')} ${chalk.bold.green('3 passed')}, 3 total` `${chalk.bold('Tests:')} ${chalk.bold.green('3 passed')}, 3 total`
), ),
true 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(() => {}) sinon.stub(console, 'error').value(() => {})
const consoleErrorSpy = sinon.spy(console, 'error') const consoleErrorSpy = sinon.spy(console, 'error')
const stream = new PassThrough() const stream = new PassThrough()
@ -64,8 +68,8 @@ await tap.test('programming-challenges run test', async (t) => {
} }
) )
stream.end() stream.end()
t.equal(exitCode, 1) assert.strictEqual(exitCode, 1)
t.equal( assert.strictEqual(
consoleErrorSpy.calledWith( consoleErrorSpy.calledWith(
chalk.bold.red('Error:') + ' The solution was not found.' 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(() => {}) sinon.stub(console, 'error').value(() => {})
const consoleErrorSpy = sinon.spy(console, 'error') const consoleErrorSpy = sinon.spy(console, 'error')
const stream = new PassThrough() const stream = new PassThrough()
@ -88,8 +92,8 @@ await tap.test('programming-challenges run test', async (t) => {
} }
) )
stream.end() stream.end()
t.equal(exitCode, 1) assert.strictEqual(exitCode, 1)
t.equal( assert.strictEqual(
consoleErrorSpy.calledWith( consoleErrorSpy.calledWith(
chalk.bold.red('Error:') + chalk.bold.red('Error:') +
' This programming language is not supported yet.' ' 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(() => {}) sinon.stub(console, 'error').value(() => {})
const consoleErrorSpy = sinon.spy(console, 'error') const consoleErrorSpy = sinon.spy(console, 'error')
const stream = new PassThrough() const stream = new PassThrough()
@ -108,8 +112,8 @@ await tap.test('programming-challenges run test', async (t) => {
stderr: stream stderr: stream
}) })
stream.end() stream.end()
t.equal(exitCode, 1) assert.strictEqual(exitCode, 1)
t.equal( assert.strictEqual(
consoleErrorSpy.calledWith( consoleErrorSpy.calledWith(
`${chalk.bold.red( `${chalk.bold.red(
'Error:' 'Error:'

View File

@ -60,7 +60,7 @@ export class Docker {
) )
try { try {
const { stdout, stderr } = await subprocess const { stdout, stderr } = await subprocess
if (stderr.length !== 0) { if (stderr.length > 0) {
throw new Error(stderr) throw new Error(stderr)
} }
return { return {

View File

@ -1,6 +1,7 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import crypto from 'node:crypto' import crypto from 'node:crypto'
import tap from 'tap'
import sinon from 'sinon' import sinon from 'sinon'
import { Challenge } from '../Challenge.js' import { Challenge } from '../Challenge.js'
@ -10,7 +11,7 @@ import { parseCommandOutput } from '../../utils/parseCommandOutput.js'
const gitAffected = new GitAffected() const gitAffected = new GitAffected()
await tap.test('services/GitAffected', async (t) => { await test('services/GitAffected', async (t) => {
t.afterEach(() => { t.afterEach(() => {
sinon.restore() sinon.restore()
}) })
@ -22,19 +23,22 @@ await tap.test('services/GitAffected', async (t) => {
}) })
await t.test('parseCommandOutput', async (t) => { await t.test('parseCommandOutput', async (t) => {
await t.test('returns the right output array', async (t) => { await t.test('returns the right output array', async () => {
t.same(parseCommandOutput('1.txt\n 2.txt '), ['1.txt', '2.txt']) assert.deepStrictEqual(parseCommandOutput('1.txt\n 2.txt '), [
'1.txt',
'2.txt'
])
}) })
}) })
await t.test('getAffectedSolutionsFromFiles', async (t) => { await t.test('getAffectedSolutionsFromFiles', async (t) => {
await t.test('returns the affected solutions', async (t) => { await t.test('returns the affected solutions', async () => {
const files = [ const files = [
'challenges/hello-world/solutions/javascript/function/solution.js', 'challenges/hello-world/solutions/javascript/function/solution.js',
'challenges/is-palindrome/solutions/c/function/input.c' 'challenges/is-palindrome/solutions/c/function/input.c'
] ]
const solutions = await gitAffected.getAffectedSolutionsFromFiles(files) const solutions = await gitAffected.getAffectedSolutionsFromFiles(files)
t.same(solutions, [ assert.deepStrictEqual(solutions, [
new Solution({ new Solution({
challenge: new Challenge({ name: 'hello-world' }), challenge: new Challenge({ name: 'hello-world' }),
name: 'function', name: 'function',
@ -50,10 +54,10 @@ await tap.test('services/GitAffected', async (t) => {
await t.test( await t.test(
'returns the affected solutions from Dockerfile changes', 'returns the affected solutions from Dockerfile changes',
async (t) => { async () => {
const files = ['templates/docker/javascript/Dockerfile'] const files = ['templates/docker/javascript/Dockerfile']
const solutions = await gitAffected.getAffectedSolutionsFromFiles(files) const solutions = await gitAffected.getAffectedSolutionsFromFiles(files)
t.same( assert.deepStrictEqual(
solutions[0], solutions[0],
new Solution({ new Solution({
challenge: new Challenge({ name: 'camel-case' }), challenge: new Challenge({ name: 'camel-case' }),
@ -61,7 +65,7 @@ await tap.test('services/GitAffected', async (t) => {
programmingLanguageName: 'javascript' programmingLanguageName: 'javascript'
}) })
) )
t.same( assert.deepStrictEqual(
solutions[1], solutions[1],
new Solution({ new Solution({
challenge: new Challenge({ name: 'first-non-repeating-character' }), challenge: new Challenge({ name: 'first-non-repeating-character' }),
@ -74,10 +78,10 @@ await tap.test('services/GitAffected', async (t) => {
await t.test( await t.test(
'returns the affected solutions from Docker template changes', 'returns the affected solutions from Docker template changes',
async (t) => { async () => {
const files = ['templates/docker/javascript/package.json'] const files = ['templates/docker/javascript/package.json']
const solutions = await gitAffected.getAffectedSolutionsFromFiles(files) const solutions = await gitAffected.getAffectedSolutionsFromFiles(files)
t.same( assert.deepStrictEqual(
solutions[0], solutions[0],
new Solution({ new Solution({
challenge: new Challenge({ name: 'camel-case' }), challenge: new Challenge({ name: 'camel-case' }),
@ -85,7 +89,7 @@ await tap.test('services/GitAffected', async (t) => {
programmingLanguageName: 'javascript' programmingLanguageName: 'javascript'
}) })
) )
t.same( assert.deepStrictEqual(
solutions[1], solutions[1],
new Solution({ new Solution({
challenge: new Challenge({ name: 'first-non-repeating-character' }), challenge: new Challenge({ name: 'first-non-repeating-character' }),
@ -98,10 +102,10 @@ await tap.test('services/GitAffected', async (t) => {
await t.test( await t.test(
'returns the affected solutions from input/output files', 'returns the affected solutions from input/output files',
async (t) => { async () => {
const files = ['challenges/hello-world/test/1/input.txt'] const files = ['challenges/hello-world/test/1/input.txt']
const solutions = await gitAffected.getAffectedSolutionsFromFiles(files) const solutions = await gitAffected.getAffectedSolutionsFromFiles(files)
t.same( assert.deepStrictEqual(
solutions[0], solutions[0],
new Solution({ new Solution({
challenge: new Challenge({ name: 'hello-world' }), challenge: new Challenge({ name: 'hello-world' }),
@ -109,7 +113,7 @@ await tap.test('services/GitAffected', async (t) => {
programmingLanguageName: 'c' programmingLanguageName: 'c'
}) })
) )
t.same( assert.deepStrictEqual(
solutions[1], solutions[1],
new Solution({ new Solution({
challenge: new Challenge({ name: 'hello-world' }), challenge: new Challenge({ name: 'hello-world' }),
@ -117,7 +121,7 @@ await tap.test('services/GitAffected', async (t) => {
programmingLanguageName: 'cpp' programmingLanguageName: 'cpp'
}) })
) )
t.same( assert.deepStrictEqual(
solutions[2], solutions[2],
new Solution({ new Solution({
challenge: new Challenge({ name: 'hello-world' }), challenge: new Challenge({ name: 'hello-world' }),
@ -125,7 +129,7 @@ await tap.test('services/GitAffected', async (t) => {
programmingLanguageName: 'cs' programmingLanguageName: 'cs'
}) })
) )
t.same( assert.deepStrictEqual(
solutions[3], solutions[3],
new Solution({ new Solution({
challenge: new Challenge({ name: 'hello-world' }), challenge: new Challenge({ name: 'hello-world' }),

View File

@ -1,16 +1,17 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import fs from 'node:fs' import fs from 'node:fs'
import tap from 'tap'
import fsMock from 'mock-fs' import fsMock from 'mock-fs'
import { copyDirectory } from '../copyDirectory.js' import { copyDirectory } from '../copyDirectory.js'
await tap.test('utils/copyDirectory', async (t) => { await test('utils/copyDirectory', async (t) => {
t.afterEach(() => { t.afterEach(() => {
fsMock.restore() fsMock.restore()
}) })
await t.test('copy the files', async (t) => { await t.test('copy the files', async () => {
fsMock({ fsMock({
'/source': { '/source': {
'default.png': '', 'default.png': '',
@ -21,19 +22,22 @@ await tap.test('utils/copyDirectory', async (t) => {
let destinationDirectoryContent = await fs.promises.readdir('/destination') let destinationDirectoryContent = await fs.promises.readdir('/destination')
let sourceDirectoryContent = await fs.promises.readdir('/source') let sourceDirectoryContent = await fs.promises.readdir('/source')
t.equal(destinationDirectoryContent.length, 0) assert.strictEqual(destinationDirectoryContent.length, 0)
t.equal(sourceDirectoryContent.length, 2) assert.strictEqual(sourceDirectoryContent.length, 2)
await copyDirectory('/source', '/destination') await copyDirectory('/source', '/destination')
destinationDirectoryContent = await fs.promises.readdir('/destination') destinationDirectoryContent = await fs.promises.readdir('/destination')
sourceDirectoryContent = await fs.promises.readdir('/source') sourceDirectoryContent = await fs.promises.readdir('/source')
t.equal(destinationDirectoryContent.length, 2) assert.strictEqual(destinationDirectoryContent.length, 2)
t.equal(sourceDirectoryContent.length, 2) assert.strictEqual(sourceDirectoryContent.length, 2)
t.strictSame(destinationDirectoryContent, ['default.png', 'index.ts']) assert.deepStrictEqual(destinationDirectoryContent, [
t.strictSame(sourceDirectoryContent, ['default.png', 'index.ts']) 'default.png',
'index.ts'
])
assert.deepStrictEqual(sourceDirectoryContent, ['default.png', 'index.ts'])
}) })
await t.test('copy the files and folders recursively', async (t) => { await t.test('copy the files and folders recursively', async () => {
fsMock({ fsMock({
'/source': { '/source': {
'random-folder': { 'random-folder': {
@ -53,10 +57,10 @@ await tap.test('utils/copyDirectory', async (t) => {
let secondRandomFolderContent = await fs.promises.readdir( let secondRandomFolderContent = await fs.promises.readdir(
'/source/random-folder/second-random-folder' '/source/random-folder/second-random-folder'
) )
t.equal(randomFolderContent.length, 2) assert.strictEqual(randomFolderContent.length, 2)
t.equal(secondRandomFolderContent.length, 1) assert.strictEqual(secondRandomFolderContent.length, 1)
t.equal(destinationDirectoryContent.length, 0) assert.strictEqual(destinationDirectoryContent.length, 0)
t.equal(sourceDirectoryContent.length, 2) assert.strictEqual(sourceDirectoryContent.length, 2)
await copyDirectory('/source', '/destination') await copyDirectory('/source', '/destination')
destinationDirectoryContent = await fs.promises.readdir('/destination') destinationDirectoryContent = await fs.promises.readdir('/destination')
@ -67,13 +71,22 @@ await tap.test('utils/copyDirectory', async (t) => {
secondRandomFolderContent = await fs.promises.readdir( secondRandomFolderContent = await fs.promises.readdir(
'/destination/random-folder/second-random-folder' '/destination/random-folder/second-random-folder'
) )
t.equal(destinationDirectoryContent.length, 2) assert.strictEqual(destinationDirectoryContent.length, 2)
t.equal(sourceDirectoryContent.length, 2) assert.strictEqual(sourceDirectoryContent.length, 2)
t.strictSame(destinationDirectoryContent, ['index.ts', 'random-folder']) assert.deepStrictEqual(destinationDirectoryContent, [
t.strictSame(sourceDirectoryContent, ['index.ts', 'random-folder']) 'index.ts',
t.equal(randomFolderContent.length, 2) 'random-folder'
t.equal(secondRandomFolderContent.length, 1) ])
t.strictSame(randomFolderContent, ['default.png', 'second-random-folder']) assert.deepStrictEqual(sourceDirectoryContent, [
t.strictSame(secondRandomFolderContent, ['mycode.ts']) 'index.ts',
'random-folder'
])
assert.strictEqual(randomFolderContent.length, 2)
assert.strictEqual(secondRandomFolderContent.length, 1)
assert.deepStrictEqual(randomFolderContent, [
'default.png',
'second-random-folder'
])
assert.deepStrictEqual(secondRandomFolderContent, ['mycode.ts'])
}) })
}) })

View File

@ -1,9 +1,11 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import fsMock from 'mock-fs' import fsMock from 'mock-fs'
import tap from 'tap'
import { isExistingPath } from '../isExistingPath.js' import { isExistingPath } from '../isExistingPath.js'
await tap.test('utils/isExistingPath', async (t) => { await test('utils/isExistingPath', async (t) => {
t.afterEach(() => { t.afterEach(() => {
fsMock.restore() fsMock.restore()
}) })
@ -12,13 +14,13 @@ await tap.test('utils/isExistingPath', async (t) => {
fsMock({ fsMock({
'/file.txt': '' '/file.txt': ''
}) })
t.equal(await isExistingPath('/file.txt'), true) assert.strictEqual(await isExistingPath('/file.txt'), true)
}) })
await t.test("should return false if the file doesn't exists", async () => { await t.test("should return false if the file doesn't exists", async () => {
fsMock({ fsMock({
'/file.txt': '' '/file.txt': ''
}) })
t.equal(await isExistingPath('/randomfile.txt'), false) assert.strictEqual(await isExistingPath('/randomfile.txt'), false)
}) })
}) })

4760
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -23,8 +23,8 @@
"lint:commit": "commitlint", "lint:commit": "commitlint",
"lint:editorconfig": "editorconfig-checker", "lint:editorconfig": "editorconfig-checker",
"lint:markdown": "markdownlint-cli2", "lint:markdown": "markdownlint-cli2",
"lint:eslint": "eslint ./cli --ignore-path .gitignore", "lint:eslint": "eslint ./cli --max-warnings 0 --report-unused-disable-directives --ignore-path .gitignore",
"test": "tap" "test": "cross-env NODE_ENV=test node --enable-source-maps --test build/"
}, },
"dependencies": { "dependencies": {
"chalk": "5.3.0", "chalk": "5.3.0",
@ -39,26 +39,26 @@
"validate-npm-package-name": "5.0.0" "validate-npm-package-name": "5.0.0"
}, },
"devDependencies": { "devDependencies": {
"@commitlint/cli": "17.6.6", "@commitlint/cli": "17.6.7",
"@commitlint/config-conventional": "17.6.6", "@commitlint/config-conventional": "17.6.7",
"@swc/cli": "0.1.62", "@swc/cli": "0.1.62",
"@swc/core": "1.3.67", "@swc/core": "1.3.70",
"@tsconfig/strictest": "2.0.1", "@tsconfig/strictest": "2.0.1",
"@types/date-and-time": "0.13.0", "@types/date-and-time": "0.13.0",
"@types/mock-fs": "4.13.1", "@types/mock-fs": "4.13.1",
"@types/ms": "0.7.31", "@types/ms": "0.7.31",
"@types/node": "20.3.3", "@types/node": "20.4.2",
"@types/sinon": "10.0.15", "@types/sinon": "10.0.15",
"@types/tap": "15.0.8",
"@types/validate-npm-package-name": "4.0.0", "@types/validate-npm-package-name": "4.0.0",
"@typescript-eslint/eslint-plugin": "5.60.1", "@typescript-eslint/eslint-plugin": "6.1.0",
"@typescript-eslint/parser": "5.60.1", "@typescript-eslint/parser": "6.1.0",
"cross-env": "7.0.3",
"editorconfig-checker": "5.1.1", "editorconfig-checker": "5.1.1",
"eslint": "8.44.0", "eslint": "8.45.0",
"eslint-config-conventions": "10.0.0", "eslint-config-conventions": "11.0.1",
"eslint-plugin-import": "2.27.5", "eslint-plugin-import": "2.27.5",
"eslint-plugin-promise": "6.1.1", "eslint-plugin-promise": "6.1.1",
"eslint-plugin-unicorn": "47.0.0", "eslint-plugin-unicorn": "48.0.0",
"get-stream": "7.0.1", "get-stream": "7.0.1",
"markdownlint-cli2": "0.8.1", "markdownlint-cli2": "0.8.1",
"markdownlint-rule-relative-links": "2.1.0", "markdownlint-rule-relative-links": "2.1.0",
@ -66,7 +66,6 @@
"ms": "2.1.3", "ms": "2.1.3",
"rimraf": "5.0.1", "rimraf": "5.0.1",
"sinon": "15.2.0", "sinon": "15.2.0",
"tap": "16.3.7", "typescript": "5.1.6"
"typescript": "5.0.4"
} }
} }

View File

@ -1,4 +1,4 @@
FROM dart:3.0.5 AS builder FROM dart:3.0.6 AS builder
WORKDIR /usr/src/application WORKDIR /usr/src/application
COPY ./ ./ COPY ./ ./
RUN dart compile exe solution.dart -o solution RUN dart compile exe solution.dart -o solution

View File

@ -1,4 +1,4 @@
FROM rust:1.70.0 AS builder FROM rust:1.71.0 AS builder
WORKDIR /usr/src/rust_application WORKDIR /usr/src/rust_application
# Cache dependencies # Cache dependencies

View File

@ -1,9 +1,9 @@
FROM node:18.16.1 AS builder-dependencies FROM node:18.17.0 AS builder-dependencies
WORKDIR /usr/src/application WORKDIR /usr/src/application
COPY ./package*.json ./ COPY ./package*.json ./
RUN npm install RUN npm install
FROM node:18.16.1 AS builder FROM node:18.17.0 AS builder
WORKDIR /usr/src/application WORKDIR /usr/src/application
COPY --from=builder-dependencies /usr/src/application/node_modules ./node_modules COPY --from=builder-dependencies /usr/src/application/node_modules ./node_modules
COPY ./ ./ COPY ./ ./

View File

@ -4,7 +4,7 @@
"build": "tsc" "build": "tsc"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "20.3.3", "@types/node": "20.4.2",
"typescript": "5.1.6" "typescript": "5.1.6"
} }
} }

View File

@ -3,7 +3,7 @@
"target": "ESNext", "target": "ESNext",
"module": "ESNext", "module": "ESNext",
"lib": ["ESNext"], "lib": ["ESNext"],
"moduleResolution": "node", "moduleResolution": "Node",
"outDir": "./build", "outDir": "./build",
"rootDir": "./", "rootDir": "./",
"strict": true, "strict": true,