-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial smoke for usage of jest (#17)
* Initial smoke for usage of jest * Exclude definition files and helpers * Allow using Omit * Isolated modules (for babel typescript) * Update parser to match typescript version * Explicitely define type files * Actual smoke test * 💥 move file I don't know why, but vscode complains unless it lives here
- Loading branch information
1 parent
8c869f6
commit 86324e4
Showing
15 changed files
with
2,364 additions
and
1,394 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"presets": [ | ||
["@babel/preset-env", { "targets": { "node": "current" } } ], | ||
"@babel/preset-typescript", | ||
] | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module.exports = { | ||
verbose: true, | ||
projects: [ | ||
'<rootDir>' | ||
], | ||
testMatch: [ | ||
"**/__tests__/**/*.[jt]s?(x)", | ||
"**/test/**/*.[jt]s?(x)", | ||
"**/?(*.)+(spec|test).[jt]s?(x)" | ||
], | ||
testPathIgnorePatterns: [ | ||
'/node_modules/', | ||
'.d.ts$', | ||
'<rootDir>/test/fixtures', | ||
'<rootDir>/test/helpers' | ||
], | ||
transform: { | ||
'^.+\\.[jt]sx?$': 'babel-jest', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ExecutionOptions } from "../../src/utils/execution_options"; | ||
import { Exercise } from "../../src/exercise"; | ||
import { set as setGlobalLogger, Logger } from "../../src/utils/logger"; | ||
import { BootstrapResult } from "../../dist/utils/bootstrap"; | ||
|
||
export function bootstrap({ exercise, ...overrides }: { exercise: string } & Partial<ExecutionOptions>): Omit<BootstrapResult, 'solution'> { | ||
const options = new ExecutionOptions({ | ||
debug: false, | ||
console: false, | ||
output: '__fake__', | ||
inputDir: '__fake__', | ||
dry: true, | ||
templates: true, | ||
exercise, | ||
...overrides | ||
}) | ||
|
||
const logger = setGlobalLogger(new Logger(options)) | ||
|
||
return { | ||
options, | ||
exercise: new Exercise(exercise), | ||
logger | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Solution } from "../../src/solution"; | ||
import { Exercise } from "../../src/exercise"; | ||
|
||
export class InlineSolution extends Solution { | ||
/** | ||
* Create a new solution reference | ||
* | ||
* @param rootDir the path to the root directory of the solution | ||
* @param exercise the exercise this solution belongs to | ||
*/ | ||
constructor(private readonly solutionFiles: string[], exercise: Exercise) { | ||
super('__fake__', exercise) | ||
} | ||
|
||
/** | ||
* Read the solution file(s) | ||
* | ||
* @param n number of files to return | ||
* @returns promise that resolves all the files at once | ||
*/ | ||
public async read(n = 1): Promise<Buffer[]> { | ||
|
||
return Promise.all( | ||
Object.keys(this.solutionFiles) | ||
.slice(0, n) | ||
.map(name => Buffer.from(this.solutionFiles[name], 'utf8')) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { Runner } from '../src/runner' | ||
import { Analyzers } from '../src/analyzers' | ||
import { TwoFerAnalyzer } from '../src/analyzers/two-fer' | ||
import { InlineSolution } from './helpers/inline-solution' | ||
import { bootstrap } from './helpers/bootstrap' | ||
|
||
const { options, exercise } = bootstrap({ exercise: 'two-fer' }) | ||
|
||
|
||
describe('When running analysis', () => { | ||
it('can approve as optimal', async () => { | ||
|
||
const solutionContent = ` | ||
export const twoFer = (name = 'you') => { | ||
return \`One for \${name}, one for me.\`; | ||
}; | ||
`.trim() | ||
|
||
const solution = new InlineSolution([solutionContent], exercise) | ||
const analyzer = new TwoFerAnalyzer(solution) | ||
|
||
const output = await Runner.call(analyzer, options); | ||
expect(output.status).toBe('approve_as_optimal'); | ||
expect(output.comments.length).toBe(0); | ||
}) | ||
|
||
it('can approve with comment', async () => { | ||
|
||
const solutionContent = ` | ||
const twoFer = (name = 'you') => { | ||
return \`One for \${name}, one for me.\`; | ||
}; | ||
export { twoFer } | ||
`.trim() | ||
|
||
const solution = new InlineSolution([solutionContent], exercise) | ||
const analyzer = new TwoFerAnalyzer(solution) | ||
|
||
const output = await Runner.call(analyzer, options); | ||
expect(output.status).toBe('approve_with_comment'); | ||
expect(output.comments.length).toBeGreaterThanOrEqual(1); | ||
}) | ||
|
||
it('can dissapprove with comment', async () => { | ||
|
||
const solutionContent = ` | ||
export const twoFer = (name) => { | ||
return \`One for \${name || 'you'}, one for me.\`; | ||
}; | ||
`.trim() | ||
|
||
const solution = new InlineSolution([solutionContent], exercise) | ||
const analyzer = new TwoFerAnalyzer(solution) | ||
|
||
const output = await Runner.call(analyzer, options); | ||
expect(output.status).toBe('disapprove_with_comment'); | ||
expect(output.comments.length).toBeGreaterThanOrEqual(1); | ||
}) | ||
|
||
it('can refer to mentor', async () => { | ||
|
||
const solutionContent = ` | ||
const whomst = 'for' | ||
export const twoFer = (name = 'you') => { | ||
return \`One \${whomst} \${name}, one \${whomst} me.\`; | ||
}; | ||
`.trim() | ||
|
||
const solution = new InlineSolution([solutionContent], exercise) | ||
const analyzer = new TwoFerAnalyzer(solution) | ||
|
||
const output = await Runner.call(analyzer, options); | ||
expect(output.status).toBe('refer_to_mentor'); | ||
}) | ||
}) | ||
|
||
describe('When autoloading analyzers', () => { | ||
it('can find an analyzer based on an exercise', () => { | ||
const ActualAnalyzer = Analyzers.find(exercise) | ||
expect(ActualAnalyzer).toBe(TwoFerAnalyzer) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
type Omit<T, K> = Pick<T, Exclude<keyof T, K>>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.