-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: move questions-remain into cypress repo (#29542)
* chore: move questions-remain into cypress repo * to js file * SLASH!
- Loading branch information
1 parent
e6b422c
commit ea83415
Showing
6 changed files
with
119 additions
and
18 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
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', | ||
} |
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
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,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 |
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,46 @@ | ||
/* global sinon */ | ||
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') | ||
}) | ||
|
||
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) | ||
}) | ||
|
||
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') | ||
}) | ||
}) | ||
}) |
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
ea83415
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.
Circle has built the
linux arm64
version of the Test Runner.Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version
Run this command to install the pre-release locally:
ea83415
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.
Circle has built the
linux x64
version of the Test Runner.Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version
Run this command to install the pre-release locally:
ea83415
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.
Circle has built the
darwin arm64
version of the Test Runner.Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version
Run this command to install the pre-release locally:
ea83415
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.
Circle has built the
win32 x64
version of the Test Runner.Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version
Run this command to install the pre-release locally:
ea83415
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.
Circle has built the
darwin x64
version of the Test Runner.Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version
Run this command to install the pre-release locally: