Skip to content

Commit

Permalink
⬆️ Update eslint to the latest version (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
greenkeeper[bot] authored and kefranabg committed Jun 23, 2019
1 parent e0d66c0 commit 88c96ac
Show file tree
Hide file tree
Showing 12 changed files with 258 additions and 213 deletions.
12 changes: 11 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@ module.exports = {
},
extends: ['airbnb-base', 'eslint:recommended'],
rules: {
semi: ['error', 'never'],
'no-use-before-define': ['error', { functions: false }],
'comma-dangle': 0,
'no-var': 2,
'prefer-const': 2
'prefer-const': 2,
'operator-linebreak': 0,
'no-confusing-arrow': 0,
'implicit-arrow-linebreak': 0,
indent: 0,
'no-param-reassign': 0,
'function-paren-newline': 0,
'arrow-parens': 0
},
parserOptions: {
parser: 'babel-eslint'
Expand Down
75 changes: 44 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"devDependencies": {
"all-contributors-cli": "^6.7.0",
"codecov": "^3.5.0",
"eslint": "^5.3.0",
"eslint": "^6.0.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.17.3",
"jest": "^24.8.0",
Expand Down
38 changes: 38 additions & 0 deletions src/ask-questions.js
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
}
}
80 changes: 80 additions & 0 deletions src/ask-questions.spec.js
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
})
})
})
Loading

0 comments on commit 88c96ac

Please sign in to comment.