mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2025-05-18 12:02:53 +02:00
feat: usage of ESM modules imports (instead of CommonJS) (#14)
This commit is contained in:
@ -1,104 +1,125 @@
|
||||
import tap from 'tap'
|
||||
|
||||
import { Challenge } from '../Challenge.js'
|
||||
import { GitAffected } from '../GitAffected.js'
|
||||
import { Solution } from '../Solution.js'
|
||||
|
||||
const gitAffected = new GitAffected({ isContinuousIntegration: false })
|
||||
|
||||
describe('services/GitAffected - parseGitOutput', () => {
|
||||
it('returns the right output array', () => {
|
||||
expect(gitAffected.parseGitOutput('1.txt\n 2.txt ')).toEqual(['1.txt', '2.txt'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('services/GitAffected - getAffectedSolutionsFromFiles', () => {
|
||||
it('returns the affected solutions', async () => {
|
||||
const files = [
|
||||
'challenges/hello-world/solutions/javascript/function/solution.js',
|
||||
'challenges/is-palindrome/solutions/c/function/input.c'
|
||||
]
|
||||
const solutions = await gitAffected.getAffectedSolutionsFromFiles(files)
|
||||
expect(solutions).toEqual([
|
||||
new Solution({
|
||||
challenge: new Challenge({ name: 'hello-world' }),
|
||||
name: 'function',
|
||||
programmingLanguageName: 'javascript'
|
||||
}),
|
||||
new Solution({
|
||||
challenge: new Challenge({ name: 'is-palindrome' }),
|
||||
name: 'function',
|
||||
programmingLanguageName: 'c'
|
||||
})
|
||||
])
|
||||
await tap.test('services/GitAffected', async (t) => {
|
||||
await t.test('parseGitOutput', async (t) => {
|
||||
await t.test('returns the right output array', async (t) => {
|
||||
t.same(gitAffected.parseGitOutput('1.txt\n 2.txt '), ['1.txt', '2.txt'])
|
||||
})
|
||||
})
|
||||
|
||||
it('returns the affected solutions from Dockerfile changes', async () => {
|
||||
const files = ['templates/docker/javascript/Dockerfile']
|
||||
const solutions = await gitAffected.getAffectedSolutionsFromFiles(files)
|
||||
expect(solutions[0]).toEqual(
|
||||
new Solution({
|
||||
challenge: new Challenge({ name: 'camel-case' }),
|
||||
name: 'function',
|
||||
programmingLanguageName: 'javascript'
|
||||
})
|
||||
)
|
||||
expect(solutions[1]).toEqual(
|
||||
new Solution({
|
||||
challenge: new Challenge({ name: 'first-non-repeating-character' }),
|
||||
name: 'function',
|
||||
programmingLanguageName: 'javascript'
|
||||
})
|
||||
)
|
||||
})
|
||||
await t.test('getAffectedSolutionsFromFiles', async (t) => {
|
||||
await t.test('returns the affected solutions', async (t) => {
|
||||
const files = [
|
||||
'challenges/hello-world/solutions/javascript/function/solution.js',
|
||||
'challenges/is-palindrome/solutions/c/function/input.c'
|
||||
]
|
||||
const solutions = await gitAffected.getAffectedSolutionsFromFiles(files)
|
||||
t.same(solutions, [
|
||||
new Solution({
|
||||
challenge: new Challenge({ name: 'hello-world' }),
|
||||
name: 'function',
|
||||
programmingLanguageName: 'javascript'
|
||||
}),
|
||||
new Solution({
|
||||
challenge: new Challenge({ name: 'is-palindrome' }),
|
||||
name: 'function',
|
||||
programmingLanguageName: 'c'
|
||||
})
|
||||
])
|
||||
})
|
||||
|
||||
it('returns the affected solutions from Docker template changes', async () => {
|
||||
const files = ['templates/docker/javascript/package.json']
|
||||
const solutions = await gitAffected.getAffectedSolutionsFromFiles(files)
|
||||
expect(solutions[0]).toEqual(
|
||||
new Solution({
|
||||
challenge: new Challenge({ name: 'camel-case' }),
|
||||
name: 'function',
|
||||
programmingLanguageName: 'javascript'
|
||||
})
|
||||
await t.test(
|
||||
'returns the affected solutions from Dockerfile changes',
|
||||
async (t) => {
|
||||
const files = ['templates/docker/javascript/Dockerfile']
|
||||
const solutions = await gitAffected.getAffectedSolutionsFromFiles(files)
|
||||
t.same(
|
||||
solutions[0],
|
||||
new Solution({
|
||||
challenge: new Challenge({ name: 'camel-case' }),
|
||||
name: 'function',
|
||||
programmingLanguageName: 'javascript'
|
||||
})
|
||||
)
|
||||
t.same(
|
||||
solutions[1],
|
||||
new Solution({
|
||||
challenge: new Challenge({ name: 'first-non-repeating-character' }),
|
||||
name: 'function',
|
||||
programmingLanguageName: 'javascript'
|
||||
})
|
||||
)
|
||||
}
|
||||
)
|
||||
expect(solutions[1]).toEqual(
|
||||
new Solution({
|
||||
challenge: new Challenge({ name: 'first-non-repeating-character' }),
|
||||
name: 'function',
|
||||
programmingLanguageName: 'javascript'
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it('returns the affected solutions from input/output files', async () => {
|
||||
const files = ['challenges/hello-world/test/1/input.txt']
|
||||
const solutions = await gitAffected.getAffectedSolutionsFromFiles(files)
|
||||
expect(solutions[0]).toEqual(
|
||||
new Solution({
|
||||
challenge: new Challenge({ name: 'hello-world' }),
|
||||
name: 'function',
|
||||
programmingLanguageName: 'c'
|
||||
})
|
||||
await t.test(
|
||||
'returns the affected solutions from Docker template changes',
|
||||
async (t) => {
|
||||
const files = ['templates/docker/javascript/package.json']
|
||||
const solutions = await gitAffected.getAffectedSolutionsFromFiles(files)
|
||||
t.same(
|
||||
solutions[0],
|
||||
new Solution({
|
||||
challenge: new Challenge({ name: 'camel-case' }),
|
||||
name: 'function',
|
||||
programmingLanguageName: 'javascript'
|
||||
})
|
||||
)
|
||||
t.same(
|
||||
solutions[1],
|
||||
new Solution({
|
||||
challenge: new Challenge({ name: 'first-non-repeating-character' }),
|
||||
name: 'function',
|
||||
programmingLanguageName: 'javascript'
|
||||
})
|
||||
)
|
||||
}
|
||||
)
|
||||
expect(solutions[1]).toEqual(
|
||||
new Solution({
|
||||
challenge: new Challenge({ name: 'hello-world' }),
|
||||
name: 'function',
|
||||
programmingLanguageName: 'cpp'
|
||||
})
|
||||
)
|
||||
expect(solutions[2]).toEqual(
|
||||
new Solution({
|
||||
challenge: new Challenge({ name: 'hello-world' }),
|
||||
name: 'function',
|
||||
programmingLanguageName: 'cs'
|
||||
})
|
||||
)
|
||||
expect(solutions[3]).toEqual(
|
||||
new Solution({
|
||||
challenge: new Challenge({ name: 'hello-world' }),
|
||||
name: 'function',
|
||||
programmingLanguageName: 'dart'
|
||||
})
|
||||
|
||||
await t.test(
|
||||
'returns the affected solutions from input/output files',
|
||||
async (t) => {
|
||||
const files = ['challenges/hello-world/test/1/input.txt']
|
||||
const solutions = await gitAffected.getAffectedSolutionsFromFiles(files)
|
||||
t.same(
|
||||
solutions[0],
|
||||
new Solution({
|
||||
challenge: new Challenge({ name: 'hello-world' }),
|
||||
name: 'function',
|
||||
programmingLanguageName: 'c'
|
||||
})
|
||||
)
|
||||
t.same(
|
||||
solutions[1],
|
||||
new Solution({
|
||||
challenge: new Challenge({ name: 'hello-world' }),
|
||||
name: 'function',
|
||||
programmingLanguageName: 'cpp'
|
||||
})
|
||||
)
|
||||
t.same(
|
||||
solutions[2],
|
||||
new Solution({
|
||||
challenge: new Challenge({ name: 'hello-world' }),
|
||||
name: 'function',
|
||||
programmingLanguageName: 'cs'
|
||||
})
|
||||
)
|
||||
t.same(
|
||||
solutions[3],
|
||||
new Solution({
|
||||
challenge: new Challenge({ name: 'hello-world' }),
|
||||
name: 'function',
|
||||
programmingLanguageName: 'dart'
|
||||
})
|
||||
)
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user