mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2025-05-18 12:02:53 +02:00
@ -5,7 +5,7 @@ import sinon from 'sinon'
|
||||
import chalk from 'chalk'
|
||||
|
||||
import { cli } from '../../../cli.js'
|
||||
import { Test } from '../../../services/Test.js'
|
||||
import { SolutionTestsResult } from '../../../services/SolutionTestsResult.js'
|
||||
|
||||
const input = ['run', 'test']
|
||||
const challenge = 'hello-world'
|
||||
@ -46,7 +46,7 @@ await tap.test('programming-challenges run test', async (t) => {
|
||||
),
|
||||
true
|
||||
)
|
||||
t.equal(consoleLogSpy.calledWith(Test.SUCCESS_MESSAGE), true)
|
||||
t.equal(consoleLogSpy.calledWith(SolutionTestsResult.SUCCESS_MESSAGE), true)
|
||||
})
|
||||
|
||||
await t.test("fails with solution that doesn't exist", async (t) => {
|
||||
|
@ -8,6 +8,7 @@ import chalk from 'chalk'
|
||||
import { isExistingPath } from '../../utils/isExistingPath.js'
|
||||
import { template } from '../../services/Template.js'
|
||||
import { Solution } from '../../services/Solution.js'
|
||||
import { TemporaryFolder } from '../../services/TemporaryFolder.js'
|
||||
|
||||
export class RunSolutionCommand extends Command {
|
||||
static paths = [['run', 'solution']]
|
||||
@ -47,6 +48,7 @@ export class RunSolutionCommand extends Command {
|
||||
async execute(): Promise<number> {
|
||||
console.log()
|
||||
try {
|
||||
await TemporaryFolder.cleanAll()
|
||||
await template.verifySupportedProgrammingLanguage(
|
||||
this.programmingLanguage
|
||||
)
|
||||
@ -61,11 +63,13 @@ export class RunSolutionCommand extends Command {
|
||||
}
|
||||
const input = await fs.promises.readFile(inputPath, { encoding: 'utf-8' })
|
||||
await solution.run(input, this.output)
|
||||
await TemporaryFolder.cleanAll()
|
||||
return 0
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
console.error(`${chalk.bold.red('Error:')} ${error.message}`)
|
||||
}
|
||||
await TemporaryFolder.cleanAll()
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ import { Solution } from '../../services/Solution.js'
|
||||
import { GitAffected } from '../../services/GitAffected.js'
|
||||
import { template } from '../../services/Template.js'
|
||||
import { Test } from '../../services/Test.js'
|
||||
import { SolutionTestsResult } from '../../services/SolutionTestsResult.js'
|
||||
import { TemporaryFolder } from '../../services/TemporaryFolder.js'
|
||||
|
||||
export class RunTestCommand extends Command {
|
||||
static paths = [['run', 'test']]
|
||||
@ -38,10 +40,6 @@ export class RunTestCommand extends Command {
|
||||
description: 'Run the tests for all the solutions.'
|
||||
})
|
||||
|
||||
public isContinuousIntegration = Option.Boolean('--ci', false, {
|
||||
description: 'Run the tests for the Continuous Integration (CI).'
|
||||
})
|
||||
|
||||
public base = Option.String('--base', {
|
||||
description: 'Base of the current branch (usually master)'
|
||||
})
|
||||
@ -49,17 +47,20 @@ export class RunTestCommand extends Command {
|
||||
async execute(): Promise<number> {
|
||||
console.log()
|
||||
try {
|
||||
await TemporaryFolder.cleanAll()
|
||||
if (this.programmingLanguage != null) {
|
||||
await template.verifySupportedProgrammingLanguage(
|
||||
this.programmingLanguage
|
||||
)
|
||||
}
|
||||
if (this.all) {
|
||||
return await Test.runAllTests(this.programmingLanguage)
|
||||
const solutions = await Solution.getManyByProgrammingLanguages(
|
||||
this.programmingLanguage != null ? [this.programmingLanguage] : undefined
|
||||
)
|
||||
return await Test.runManyWithSolutions(solutions)
|
||||
}
|
||||
if (this.affected) {
|
||||
const gitAffected = new GitAffected({
|
||||
isContinuousIntegration: this.isContinuousIntegration,
|
||||
base: this.base
|
||||
})
|
||||
const solutions = await gitAffected.getAffectedSolutionsFromGit()
|
||||
@ -79,13 +80,22 @@ export class RunTestCommand extends Command {
|
||||
challengeName: this.challenge,
|
||||
programmingLanguageName: this.programmingLanguage
|
||||
})
|
||||
await solution.test()
|
||||
console.log(Test.SUCCESS_MESSAGE)
|
||||
return 0
|
||||
const result = await solution.test()
|
||||
result.print({
|
||||
shouldPrintBenchmark: true,
|
||||
shouldPrintTableResult: true
|
||||
})
|
||||
await TemporaryFolder.cleanAll()
|
||||
if (result.isSuccess) {
|
||||
console.log(SolutionTestsResult.SUCCESS_MESSAGE)
|
||||
return 0
|
||||
}
|
||||
return 1
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
console.error(`${chalk.bold.red('Error:')} ${error.message}`)
|
||||
}
|
||||
await TemporaryFolder.cleanAll()
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user