-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⬆️ Update eslint to the latest version (#70)
- Loading branch information
1 parent
e0d66c0
commit 88c96ac
Showing
12 changed files
with
258 additions
and
213 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,38 @@ | ||
const inquirer = require('inquirer') | ||
|
||
const questionsBuilders = require('./questions') | ||
const utils = require('./utils') | ||
|
||
/** | ||
* Get questions | ||
* | ||
* @param {Object} projectInfos | ||
*/ | ||
const getQuestions = projectInfos => | ||
Object.values(questionsBuilders).reduce( | ||
(questions, questionBuilder) => [ | ||
...questions, | ||
questionBuilder(projectInfos) | ||
], | ||
[] | ||
) | ||
|
||
/** | ||
* Ask user questions and return context to generate a README | ||
* | ||
* @param {Object} projectInfos | ||
*/ | ||
module.exports = async (projectInfos, skipQuestions) => { | ||
const questions = getQuestions(projectInfos) | ||
|
||
const answersContext = skipQuestions | ||
? utils.getDefaultAnswers(questions) | ||
: await inquirer.prompt(questions) | ||
|
||
return { | ||
isGithubRepos: projectInfos.isGithubRepos, | ||
repositoryUrl: projectInfos.repositoryUrl, | ||
projectPrerequisites: undefined, | ||
...answersContext | ||
} | ||
} |
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,80 @@ | ||
const inquirer = require('inquirer') | ||
|
||
const questions = require('./questions') | ||
const askQuestions = require('./ask-questions') | ||
|
||
inquirer.prompt = jest.fn(items => | ||
Promise.resolve( | ||
items.reduce((result, item) => { | ||
result[item.name] = 'value' | ||
return result | ||
}, {}) | ||
) | ||
) | ||
|
||
jest.mock('./questions', () => ({ | ||
askProjectName: jest.fn(() => ({ | ||
name: 'projectName', | ||
type: 'input', | ||
default: 'defaultProjectName' | ||
})), | ||
askProjectVersion: jest.fn(() => ({ | ||
name: 'projectVersion', | ||
type: 'input' | ||
})), | ||
askProjectDescription: jest.fn(() => ({ | ||
name: 'projectDescription', | ||
type: 'checkbox', | ||
choices: [ | ||
{ value: { name: 'choiceOne', value: 1 }, checked: true }, | ||
{ value: { name: 'choiceTwo', value: 2 }, checked: false } | ||
] | ||
})) | ||
})) | ||
|
||
describe('ask-questions', () => { | ||
beforeEach(() => { | ||
inquirer.prompt.mockClear() | ||
}) | ||
|
||
it('should call all builder functions exported by questions', async () => { | ||
const projectInfos = { name: 'readme-md-generator' } | ||
|
||
await askQuestions(projectInfos) | ||
|
||
expect(questions.askProjectName).toHaveBeenCalledTimes(1) | ||
expect(questions.askProjectVersion).toHaveBeenCalledTimes(1) | ||
expect(questions.askProjectDescription).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
it('should use default values with --yes option', async () => { | ||
const projectInfos = { name: 'readme-md-generator' } | ||
|
||
const result = await askQuestions(projectInfos, true) | ||
|
||
expect(inquirer.prompt).not.toHaveBeenCalled() | ||
expect(result).toEqual({ | ||
projectName: 'defaultProjectName', | ||
projectVersion: '', | ||
projectDescription: [{ name: 'choiceOne', value: 1 }], | ||
isGithubRepos: undefined, | ||
repositoryUrl: undefined, | ||
projectPrerequisites: undefined | ||
}) | ||
}) | ||
|
||
it('should return merged contexts', async () => { | ||
const projectInfos = { name: 'readme-md-generator' } | ||
|
||
const context = await askQuestions(projectInfos) | ||
|
||
expect(context).toEqual({ | ||
projectName: 'value', | ||
projectVersion: 'value', | ||
projectDescription: 'value', | ||
isGithubRepos: undefined, | ||
repositoryUrl: undefined, | ||
projectPrerequisites: undefined | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.