Skip to content

Commit a4099d8

Browse files
committed
test(unit): migrate the base questions tests from mocha to vitest
for #767
1 parent 69c015e commit a4099d8

5 files changed

Lines changed: 135 additions & 135 deletions

File tree

.eslintrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
extends:
22
- '@form8ion'
33
- '@form8ion/mocha'
4+
- '@form8ion/vitest'
45
- '@form8ion/cucumber'
56

67
overrides:

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
"@form8ion/eslint-config": "8.0.0-beta.1",
7979
"@form8ion/eslint-config-cucumber": "1.4.1",
8080
"@form8ion/eslint-config-mocha": "3.0.6",
81+
"@form8ion/eslint-config-vitest": "1.1.0",
8182
"@form8ion/remark-lint-preset": "6.0.7",
8283
"@rollup/plugin-babel": "7.0.0",
8384
"@travi/any": "3.3.0",

src/prompts/questions-test.js

Lines changed: 0 additions & 135 deletions
This file was deleted.

src/prompts/questions.test.js

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import {basename} from 'node:path';
2+
3+
import {describe, expect, it, vi, beforeEach} from 'vitest';
4+
import {when} from 'vitest-when';
5+
import any from '@travi/any';
6+
7+
import {questionNames as coreQuestionNames} from './question-names.js';
8+
import * as predicates from './predicates.js';
9+
import {visibilityOptions} from './visibility-options.js';
10+
import mapOptionsToChoices from './options-to-choices-mapper.js';
11+
import buildLicenseChoices from './license-choices-builder.js';
12+
import {questionsForBaseDetails} from './questions.js';
13+
14+
vi.mock('node:path');
15+
vi.mock('./options-to-choices-mapper.js');
16+
17+
describe('base project questions', () => {
18+
const projectPath = any.string();
19+
const decisions = any.simpleObject();
20+
const visibilityChoices = any.listOf(any.simpleObject);
21+
22+
beforeEach(() => {
23+
when(mapOptionsToChoices).calledWith(visibilityOptions).thenReturn(visibilityChoices);
24+
});
25+
26+
it('should define the questions for gathering base details about a project', async () => {
27+
const directoryName = any.string();
28+
const copyrightHolder = any.string();
29+
when(basename).calledWith(projectPath).thenReturn(directoryName);
30+
31+
expect(await questionsForBaseDetails(decisions, projectPath, copyrightHolder)).toEqual([
32+
{name: coreQuestionNames.PROJECT_NAME, message: 'What is the name of this project?', default: directoryName},
33+
{
34+
name: coreQuestionNames.DESCRIPTION,
35+
message: 'How should this project be described?'
36+
},
37+
{
38+
name: coreQuestionNames.VISIBILITY,
39+
message: 'What is the contribution model for this project?',
40+
type: 'list',
41+
validate: predicates.visibilityIsValid,
42+
choices: visibilityChoices
43+
},
44+
{
45+
name: coreQuestionNames.UNLICENSED,
46+
message: 'Since this is a private project, should it be unlicensed?',
47+
type: 'confirm',
48+
when: predicates.unlicensedConfirmationShouldBePresented,
49+
default: true
50+
},
51+
{
52+
name: coreQuestionNames.LICENSE,
53+
message: 'How should this this project be licensed (https://choosealicense.com/)?',
54+
type: 'list',
55+
when: predicates.licenseChoicesShouldBePresented,
56+
choices: buildLicenseChoices,
57+
default: 'MIT'
58+
},
59+
{
60+
name: coreQuestionNames.COPYRIGHT_HOLDER,
61+
message: 'Who is the copyright holder of this project?',
62+
when: predicates.copyrightInformationShouldBeRequested,
63+
default: copyrightHolder
64+
},
65+
{
66+
name: coreQuestionNames.COPYRIGHT_YEAR,
67+
message: 'What is the copyright year?',
68+
when: predicates.copyrightInformationShouldBeRequested,
69+
default: new Date().getFullYear()
70+
}
71+
]);
72+
});
73+
74+
it('should not require `projectPath`', async () => {
75+
const copyrightHolder = any.string();
76+
when(basename)
77+
.calledWith(undefined)
78+
.thenThrow(new Error('The "path" argument must be of type string. Received undefined'));
79+
80+
expect(await questionsForBaseDetails(decisions, undefined, copyrightHolder)).toEqual([
81+
{name: coreQuestionNames.PROJECT_NAME, message: 'What is the name of this project?', default: undefined},
82+
{
83+
name: coreQuestionNames.DESCRIPTION,
84+
message: 'How should this project be described?'
85+
},
86+
{
87+
name: coreQuestionNames.VISIBILITY,
88+
message: 'What is the contribution model for this project?',
89+
type: 'list',
90+
validate: predicates.visibilityIsValid,
91+
choices: visibilityChoices
92+
},
93+
{
94+
name: coreQuestionNames.UNLICENSED,
95+
message: 'Since this is a private project, should it be unlicensed?',
96+
type: 'confirm',
97+
when: predicates.unlicensedConfirmationShouldBePresented,
98+
default: true
99+
},
100+
{
101+
name: coreQuestionNames.LICENSE,
102+
message: 'How should this this project be licensed (https://choosealicense.com/)?',
103+
type: 'list',
104+
when: predicates.licenseChoicesShouldBePresented,
105+
choices: buildLicenseChoices,
106+
default: 'MIT'
107+
},
108+
{
109+
name: coreQuestionNames.COPYRIGHT_HOLDER,
110+
message: 'Who is the copyright holder of this project?',
111+
when: predicates.copyrightInformationShouldBeRequested,
112+
default: copyrightHolder
113+
},
114+
{
115+
name: coreQuestionNames.COPYRIGHT_YEAR,
116+
message: 'What is the copyright year?',
117+
when: predicates.copyrightInformationShouldBeRequested,
118+
default: new Date().getFullYear()
119+
}
120+
]);
121+
});
122+
});

0 commit comments

Comments
 (0)