-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(INT-701): add support for return and throw
- Loading branch information
Showing
10 changed files
with
129 additions
and
40 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
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,42 @@ | ||
import { join } from 'path'; | ||
import { Command } from 'commander'; | ||
import { Scenario } from './types'; | ||
import { ScenarioUtils } from './utils'; | ||
|
||
// Run: npm run test:scenario -- --scenario=arrays --index=1 | ||
const command = new Command(); | ||
command | ||
.allowUnknownOption() | ||
.option('-s, --scenario <string>', 'Enter Scenario Name') | ||
.option('-i, --index <number>', 'Enter Test case index') | ||
.parse(); | ||
|
||
const opts = command.opts(); | ||
const scenarioName = opts.scenario || 'none'; | ||
const index = +(opts.index || 0); | ||
|
||
describe(`${scenarioName}:`, () => { | ||
it(`Scenario ${index}`, async () => { | ||
if (scenarioName === 'none') { | ||
return; | ||
} | ||
const scenarioDir = join(__dirname, 'scenarios', scenarioName); | ||
const scenarios = ScenarioUtils.extractScenarios(scenarioDir); | ||
const scenario: Scenario = scenarios[index] || scenarios[0]; | ||
let result; | ||
try { | ||
console.log( | ||
`Executing scenario: ${scenarioName}, test: ${index}, template: ${ | ||
scenario.templatePath || 'template.jt' | ||
}`, | ||
); | ||
const templateEngine = ScenarioUtils.createTemplateEngine(scenarioDir, scenario); | ||
result = await ScenarioUtils.evaluateScenario(templateEngine, scenario); | ||
expect(result).toEqual(scenario.output); | ||
} catch (error: any) { | ||
console.log('Actual result', JSON.stringify(result, null, 2)); | ||
console.log('Expected result', JSON.stringify(scenario.output, null, 2)); | ||
expect(error.message).toEqual(scenario.error); | ||
} | ||
}); | ||
}); |
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,12 @@ | ||
import { Scenario } from '../../types'; | ||
|
||
export const data: Scenario[] = [ | ||
{ | ||
input: 3, | ||
output: 1, | ||
}, | ||
{ | ||
input: 2, | ||
output: 1, | ||
}, | ||
]; |
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,2 @@ | ||
(. % 2 === 0) ? return ./2; | ||
(. - 1)/2; |
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,12 @@ | ||
import { Scenario } from '../../types'; | ||
|
||
export const data: Scenario[] = [ | ||
{ | ||
input: 3, | ||
error: 'num must be even', | ||
}, | ||
{ | ||
input: 2, | ||
output: 1, | ||
}, | ||
]; |
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 @@ | ||
(. % 2 !== 0) ? throw new Error("num must be even") : ./2; |
This file was deleted.
Oops, something went wrong.