1
1
mirror of https://github.com/theoludwig/programming-challenges.git synced 2025-05-18 12:02:53 +02:00

chore: better Prettier config for easier reviews

This commit is contained in:
2023-10-23 23:16:24 +02:00
parent d7d5f9a5ac
commit 1e2736b8aa
70 changed files with 1476 additions and 1382 deletions

View File

@ -1,143 +1,143 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import crypto from 'node:crypto'
import test from "node:test"
import assert from "node:assert/strict"
import crypto from "node:crypto"
import sinon from 'sinon'
import sinon from "sinon"
import { Challenge } from '../Challenge.js'
import { GitAffected } from '../GitAffected.js'
import { Solution } from '../Solution.js'
import { parseCommandOutput } from '../../utils/parseCommandOutput.js'
import { Challenge } from "../Challenge.js"
import { GitAffected } from "../GitAffected.js"
import { Solution } from "../Solution.js"
import { parseCommandOutput } from "../../utils/parseCommandOutput.js"
const gitAffected = new GitAffected()
await test('services/GitAffected', async (t) => {
await test("services/GitAffected", async (t) => {
t.afterEach(() => {
sinon.restore()
})
t.beforeEach(() => {
sinon.stub(crypto, 'randomUUID').value(() => {
return 'uuid'
sinon.stub(crypto, "randomUUID").value(() => {
return "uuid"
})
})
await t.test('parseCommandOutput', async (t) => {
await t.test('returns the right output array', async () => {
assert.deepStrictEqual(parseCommandOutput('1.txt\n 2.txt '), [
'1.txt',
'2.txt'
await t.test("parseCommandOutput", async (t) => {
await t.test("returns the right output array", async () => {
assert.deepStrictEqual(parseCommandOutput("1.txt\n 2.txt "), [
"1.txt",
"2.txt",
])
})
})
await t.test('getAffectedSolutionsFromFiles', async (t) => {
await t.test('returns the affected solutions', async () => {
await t.test("getAffectedSolutionsFromFiles", async (t) => {
await t.test("returns the affected solutions", async () => {
const files = [
'challenges/hello-world/solutions/javascript/function/solution.js',
'challenges/is-palindrome/solutions/c/function/input.c'
"challenges/hello-world/solutions/javascript/function/solution.js",
"challenges/is-palindrome/solutions/c/function/input.c",
]
const solutions = await gitAffected.getAffectedSolutionsFromFiles(files)
assert.deepStrictEqual(solutions, [
new Solution({
challenge: new Challenge({ name: 'hello-world' }),
name: 'function',
programmingLanguageName: 'javascript'
challenge: new Challenge({ name: "hello-world" }),
name: "function",
programmingLanguageName: "javascript",
}),
new Solution({
challenge: new Challenge({ name: 'is-palindrome' }),
name: 'function',
programmingLanguageName: 'c'
})
challenge: new Challenge({ name: "is-palindrome" }),
name: "function",
programmingLanguageName: "c",
}),
])
})
await t.test(
'returns the affected solutions from Dockerfile changes',
"returns the affected solutions from Dockerfile changes",
async () => {
const files = ['templates/docker/javascript/Dockerfile']
const files = ["templates/docker/javascript/Dockerfile"]
const solutions = await gitAffected.getAffectedSolutionsFromFiles(files)
assert.deepStrictEqual(
solutions[0],
new Solution({
challenge: new Challenge({ name: 'camel-case' }),
name: 'function',
programmingLanguageName: 'javascript'
})
challenge: new Challenge({ name: "camel-case" }),
name: "function",
programmingLanguageName: "javascript",
}),
)
assert.deepStrictEqual(
solutions[1],
new Solution({
challenge: new Challenge({ name: 'first-non-repeating-character' }),
name: 'function',
programmingLanguageName: 'javascript'
})
challenge: new Challenge({ name: "first-non-repeating-character" }),
name: "function",
programmingLanguageName: "javascript",
}),
)
}
},
)
await t.test(
'returns the affected solutions from Docker template changes',
"returns the affected solutions from Docker template changes",
async () => {
const files = ['templates/docker/javascript/package.json']
const files = ["templates/docker/javascript/package.json"]
const solutions = await gitAffected.getAffectedSolutionsFromFiles(files)
assert.deepStrictEqual(
solutions[0],
new Solution({
challenge: new Challenge({ name: 'camel-case' }),
name: 'function',
programmingLanguageName: 'javascript'
})
challenge: new Challenge({ name: "camel-case" }),
name: "function",
programmingLanguageName: "javascript",
}),
)
assert.deepStrictEqual(
solutions[1],
new Solution({
challenge: new Challenge({ name: 'first-non-repeating-character' }),
name: 'function',
programmingLanguageName: 'javascript'
})
challenge: new Challenge({ name: "first-non-repeating-character" }),
name: "function",
programmingLanguageName: "javascript",
}),
)
}
},
)
await t.test(
'returns the affected solutions from input/output files',
"returns the affected solutions from input/output files",
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)
assert.deepStrictEqual(
solutions[0],
new Solution({
challenge: new Challenge({ name: 'hello-world' }),
name: 'function',
programmingLanguageName: 'c'
})
challenge: new Challenge({ name: "hello-world" }),
name: "function",
programmingLanguageName: "c",
}),
)
assert.deepStrictEqual(
solutions[1],
new Solution({
challenge: new Challenge({ name: 'hello-world' }),
name: 'function',
programmingLanguageName: 'cpp'
})
challenge: new Challenge({ name: "hello-world" }),
name: "function",
programmingLanguageName: "cpp",
}),
)
assert.deepStrictEqual(
solutions[2],
new Solution({
challenge: new Challenge({ name: 'hello-world' }),
name: 'function',
programmingLanguageName: 'cs'
})
challenge: new Challenge({ name: "hello-world" }),
name: "function",
programmingLanguageName: "cs",
}),
)
assert.deepStrictEqual(
solutions[3],
new Solution({
challenge: new Challenge({ name: 'hello-world' }),
name: 'function',
programmingLanguageName: 'dart'
})
challenge: new Challenge({ name: "hello-world" }),
name: "function",
programmingLanguageName: "dart",
}),
)
}
},
)
})
})