Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions _gulp/modules/setupQuestions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { questions } from './setupQuestions';
import { markupChoices, scriptChoices, styleChoices } from './userChoicesValidation';

function questionByName(name: string): Record<string, unknown> {
const question = questions.find((item) => item.name === name);
assert.ok(question, `Expected question '${name}' to exist`);
return question as Record<string, unknown>;
}

test('setup questions expose strict script/style/markup choice lists', () => {
const scriptQuestion = questionByName('script');
const styleQuestion = questionByName('style');
const markupQuestion = questionByName('markup');

assert.deepEqual(scriptQuestion.choices, [...scriptChoices]);
assert.deepEqual(styleQuestion.choices, [...styleChoices]);
assert.deepEqual(markupQuestion.choices, [...markupChoices]);
});

test('setup questions include boolean toggles with safe defaults', () => {
const addNormalizeQuestion = questionByName('addNormalize');
const addResetQuestion = questionByName('addReset');

assert.equal(addNormalizeQuestion.type, 'confirm');
assert.equal(addNormalizeQuestion.default, false);

assert.equal(addResetQuestion.type, 'confirm');
assert.equal(addResetQuestion.default, false);
});
9 changes: 5 additions & 4 deletions _gulp/modules/setupQuestions.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import inquirer from 'inquirer';
import { UserChoices } from '../types';
import { markupChoices, scriptChoices, styleChoices } from './userChoicesValidation';

export const questions = [
{ type: 'list', name: 'script', message: 'Choose JavaScript or TypeScript:', choices: ['JavaScript', 'TypeScript'] },
{ type: 'list', name: 'style', message: 'Choose Sass or SCSS:', choices: ['Sass', 'SCSS'] },
{ type: 'list', name: 'markup', message: 'Choose HTML or Pug:', choices: ['HTML', 'Pug'] },
{ type: 'list', name: 'script', message: 'Choose JavaScript or TypeScript:', choices: [...scriptChoices] },
{ type: 'list', name: 'style', message: 'Choose Sass or SCSS:', choices: [...styleChoices] },
{ type: 'list', name: 'markup', message: 'Choose HTML or Pug:', choices: [...markupChoices] },
{ type: 'confirm', name: 'addNormalize', message: 'Add normalize.css?', default: false },
{ type: 'confirm', name: 'addReset', message: 'Add reset.css?', default: false }
];
Expand All @@ -18,4 +19,4 @@ export async function confirmProjectDeletion(): Promise<boolean> {
{ type: 'confirm', name: 'deleteProject', message: 'DELETE existing project and start new?', default: false }
]);
return deleteProject;
}
}
10 changes: 7 additions & 3 deletions _gulp/modules/userChoicesValidation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { UserChoices } from '../types';

const validScripts = new Set<UserChoices['script']>(['JavaScript', 'TypeScript']);
const validStyles = new Set<UserChoices['style']>(['Sass', 'SCSS']);
const validMarkups = new Set<UserChoices['markup']>(['HTML', 'Pug']);
export const scriptChoices = ['JavaScript', 'TypeScript'] as const;
export const styleChoices = ['Sass', 'SCSS'] as const;
export const markupChoices = ['HTML', 'Pug'] as const;

const validScripts = new Set<UserChoices['script']>(scriptChoices);
const validStyles = new Set<UserChoices['style']>(styleChoices);
const validMarkups = new Set<UserChoices['markup']>(markupChoices);

function isObjectRecord(value: unknown): value is Record<string, unknown> {
return typeof value === 'object' && value !== null;
Expand Down
Loading