Skip to content

Commit 06c2c40

Browse files
committed
feat(integration-testing): choose and scaffold a framework
1 parent 60b0d47 commit 06c2c40

7 files changed

Lines changed: 88 additions & 8 deletions

File tree

src/prompts/question-names.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export const questionNames = {
22
UNIT_TEST_FRAMEWORK: 'unitTestFramework',
3+
INTEGRATION_TEST_FRAMEWORK: 'integrationTestFramework',
34
NODE_VERSION_CATEGORY: 'nodeVersionCategory',
45
PACKAGE_MANAGER: 'packageManager',
56
PACKAGE_BUNDLER: 'packageBundler',

src/testing/integration/prompt.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {prompt} from '@form8ion/overridable-prompts';
2+
import {questionNames} from '../../prompts/question-names.js';
3+
4+
export default async function gatherUnitTestingInput({frameworks, decisions}) {
5+
if (!Object.keys(frameworks).length) return 'Other';
6+
7+
const answers = await prompt([{
8+
name: questionNames.INTEGRATION_TEST_FRAMEWORK,
9+
type: 'list',
10+
message: 'Which integration testing framework should be used?',
11+
choices: [...Object.keys(frameworks), 'Other']
12+
}], decisions);
13+
14+
return answers[questionNames.INTEGRATION_TEST_FRAMEWORK];
15+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as prompts from '@form8ion/overridable-prompts';
2+
3+
import any from '@travi/any';
4+
import {when} from 'vitest-when';
5+
import {describe, expect, it, vi} from 'vitest';
6+
7+
import {questionNames} from '../../prompts/question-names.js';
8+
import prompt from './prompt.js';
9+
10+
vi.mock('@form8ion/overridable-prompts');
11+
12+
describe('integration-test framework prompt', () => {
13+
it('should preset the choice of integration-test framework', async () => {
14+
const chosenType = any.word();
15+
const decisions = any.simpleObject();
16+
const answers = {...any.simpleObject(), [questionNames.INTEGRATION_TEST_FRAMEWORK]: chosenType};
17+
const frameworks = any.simpleObject();
18+
when(prompts.prompt)
19+
.calledWith([{
20+
name: questionNames.INTEGRATION_TEST_FRAMEWORK,
21+
type: 'list',
22+
message: 'Which integration testing framework should be used?',
23+
choices: [...Object.keys(frameworks), 'Other']
24+
}], decisions)
25+
.thenResolve(answers);
26+
27+
expect(await prompt({frameworks, decisions})).toEqual(chosenType);
28+
});
29+
30+
it('should skip the prompt and return `Other` when no options are provided', async () => {
31+
expect(await prompt({frameworks: {}})).toEqual('Other');
32+
});
33+
});
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1-
export default function scaffoldIntegrationTesting() {
2-
return {};
1+
import {scaffoldChoice as scaffoldFrameworkChoice} from '@form8ion/javascript-core';
2+
3+
import chooseFramework from './prompt.js';
4+
5+
export default async function scaffoldIntegrationTesting({
6+
projectRoot,
7+
frameworks: integrationTestFrameworks,
8+
decisions,
9+
dialect
10+
}) {
11+
const chosenFramework = await chooseFramework({frameworks: integrationTestFrameworks, decisions});
12+
13+
return scaffoldFrameworkChoice(integrationTestFrameworks, chosenFramework, {projectRoot, dialect});
314
}
Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
1-
import {describe, it, expect} from 'vitest';
1+
import {scaffoldChoice} from '@form8ion/javascript-core';
22

3+
import {describe, it, expect, vi} from 'vitest';
4+
import {when} from 'vitest-when';
5+
import any from '@travi/any';
6+
7+
import prompt from './prompt.js';
38
import scaffoldIntegrationTesting from './scaffolder.js';
49

10+
vi.mock('@form8ion/javascript-core');
11+
vi.mock('./prompt.js');
12+
513
describe('integration testing scaffolder', () => {
614
it('should scaffold the chosen framework', async () => {
7-
expect(scaffoldIntegrationTesting()).toEqual({});
15+
const projectRoot = any.string();
16+
const decisions = any.simpleObject();
17+
const dialect = any.word();
18+
const chosenFramework = any.word();
19+
const integrationTestFrameworks = any.simpleObject();
20+
const integrationTestFrameworkResults = any.simpleObject();
21+
when(prompt).calledWith({frameworks: integrationTestFrameworks, decisions}).thenResolve(chosenFramework);
22+
when(scaffoldChoice)
23+
.calledWith(integrationTestFrameworks, chosenFramework, {projectRoot, dialect})
24+
.thenResolve(integrationTestFrameworkResults);
25+
26+
expect(await scaffoldIntegrationTesting({projectRoot, frameworks: integrationTestFrameworks, decisions, dialect}))
27+
.toEqual(integrationTestFrameworkResults);
828
});
929
});

src/testing/unit/prompt.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default async function gatherUnitTestingInput({frameworks, decisions}) {
77
const answers = await prompt([{
88
name: questionNames.UNIT_TEST_FRAMEWORK,
99
type: 'list',
10-
message: 'Which type of unit testing framework should be used?',
10+
message: 'Which unit testing framework should be used?',
1111
choices: [...Object.keys(frameworks), 'Other']
1212
}], decisions);
1313

src/testing/unit/prompt.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import prompt from './prompt.js';
99

1010
vi.mock('@form8ion/overridable-prompts');
1111

12-
describe('project-type prompts', () => {
13-
it('should preset the choice of application-type', async () => {
12+
describe('unit-test framework prompts', () => {
13+
it('should preset the choice of unit-test framework', async () => {
1414
const chosenType = any.word();
1515
const decisions = any.simpleObject();
1616
const answers = {...any.simpleObject(), [questionNames.UNIT_TEST_FRAMEWORK]: chosenType};
@@ -19,7 +19,7 @@ describe('project-type prompts', () => {
1919
.calledWith([{
2020
name: questionNames.UNIT_TEST_FRAMEWORK,
2121
type: 'list',
22-
message: 'Which type of unit testing framework should be used?',
22+
message: 'Which unit testing framework should be used?',
2323
choices: [...Object.keys(frameworks), 'Other']
2424
}], decisions)
2525
.thenResolve(answers);

0 commit comments

Comments
 (0)