|
| 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