-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: move questions-remain into cypress repo #29542
Changes from all commits
42b1a88
e508291
f249d5b
30106ea
eca4acd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
exports['questions-remain returns object if all questions have been answered 1'] = { | ||
'foo': 'foo is specified', | ||
'bar': 'so is bar', | ||
} | ||
|
||
exports['questions-remain asks questions for missing options 1'] = { | ||
'foo': 'foo is specified', | ||
'bar': 'bar user answer', | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const la = require('lazy-ass') | ||
const is = require('check-more-types') | ||
const bluebird = require('bluebird') | ||
|
||
// goes through the list of properties and asks relevant question | ||
// resolves with all relevant options set | ||
// if the property already exists, skips the question | ||
function askMissingOptions (propertiesToQuestions) { | ||
la(is.object(propertiesToQuestions), 'expected object property:question') | ||
|
||
// options are collected from the CLI | ||
return (options = {}) => { | ||
const reducer = (memo, property) => { | ||
if (is.has(memo, property)) { | ||
return memo | ||
} | ||
|
||
const question = propertiesToQuestions[property] | ||
|
||
if (!is.fn(question)) { | ||
return memo | ||
} | ||
|
||
la(is.fn(question), 'cannot find question for property', property) | ||
|
||
return question(memo[property]).then((answer) => { | ||
memo[property] = answer | ||
|
||
return memo | ||
}) | ||
} | ||
|
||
const properties = Object.keys(propertiesToQuestions) | ||
|
||
return bluebird.reduce(properties, reducer, options) | ||
} | ||
} | ||
|
||
module.exports = askMissingOptions |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* global sinon */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
const questionsRemain = require('../../../binary/util/questions-remain') | ||
const la = require('lazy-ass') | ||
const snapshot = require('snap-shot-it') | ||
|
||
describe('questions-remain', () => { | ||
const dontAsk = () => { | ||
throw new Error('Should not ask!') | ||
} | ||
|
||
it('is a function', () => { | ||
if (typeof questionsRemain !== 'function') throw new Error('questionsRemain is not a function') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed the |
||
}) | ||
|
||
it('returns object if all questions have been answered', () => { | ||
const propertiesToQuestions = { | ||
foo: dontAsk, | ||
bar: dontAsk, | ||
} | ||
const options = { | ||
foo: 'foo is specified', | ||
bar: 'so is bar', | ||
} | ||
|
||
// console.log(questionsRemain(propertiesToQuestions)(options)) | ||
return questionsRemain(propertiesToQuestions)(options).then(snapshot) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are promises, so chain |
||
}) | ||
|
||
it('asks questions for missing options', () => { | ||
const barStub = sinon.stub().resolves('bar user answer') | ||
const propertiesToQuestions = { | ||
foo: dontAsk, | ||
bar: barStub, | ||
} | ||
const options = { | ||
foo: 'foo is specified', | ||
// notice bar is missing! | ||
} | ||
|
||
return questionsRemain(propertiesToQuestions)(options) | ||
.then(snapshot) | ||
.then(() => { | ||
la(barStub.called, 'bar stub has not been called') | ||
}) | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was having issues with snapshot and though this would fix it. Seems like a good change even though it's not needed for this update.