chore: move questions-remain into cypress repo (#29542)

* chore: move questions-remain into cypress repo

* to js file

* SLASH!
This commit is contained in:
Jennifer Shehane
2024-06-03 07:42:55 -07:00
committed by GitHub
parent e6b422cd25
commit ea83415637
6 changed files with 119 additions and 18 deletions
+9
View File
@@ -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',
}
+1 -2
View File
@@ -74,7 +74,6 @@
"@aws-sdk/client-s3": "3.485.0",
"@aws-sdk/credential-providers": "3.53.0",
"@babel/eslint-parser": "7.24.1",
"@cypress/questions-remain": "1.0.1",
"@cypress/request": "^3.0.0",
"@cypress/request-promise": "^5.0.0",
"@electron/fuses": "1.6.1",
@@ -197,7 +196,7 @@
"semver": "7.5.3",
"shelljs": "0.8.5",
"sinon": "7.3.2",
"snap-shot-it": "7.9.3",
"snap-shot-it": "7.9.10",
"stop-only": "3.0.1",
"strip-ansi": "6.0.0",
"tar": "6.1.15",
+1 -1
View File
@@ -11,7 +11,6 @@ const minimist = require('minimist')
const la = require('lazy-ass')
const check = require('check-more-types')
const debug = require('debug')('cypress:binary')
const questionsRemain = require('@cypress/questions-remain')
const rp = require('@cypress/request-promise')
const zip = require('./zip')
@@ -19,6 +18,7 @@ const ask = require('./ask')
const meta = require('./meta')
const build = require('./build')
const upload = require('./upload')
const questionsRemain = require('./util/questions-remain')
const uploadUtils = require('./util/upload')
const { uploadArtifactToS3 } = require('./upload-build-artifact')
const { moveBinaries } = require('./move-binaries')
+39
View File
@@ -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
@@ -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')
})
})
})
+23 -15
View File
@@ -2942,15 +2942,6 @@
mkdirp "^0.5.1"
npm-run-all "^4.1.5"
"@cypress/questions-remain@1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@cypress/questions-remain/-/questions-remain-1.0.1.tgz#334dc830323192995b43d7bbae9dd6db5e551a22"
integrity sha1-M03IMDIxkplbQ9e7rp3W215VGiI=
dependencies:
bluebird "3.5.0"
check-more-types "2.24.0"
lazy-ass "1.6.0"
"@cypress/react-tooltip@0.5.3":
version "0.5.3"
resolved "https://registry.yarnpkg.com/@cypress/react-tooltip/-/react-tooltip-0.5.3.tgz#3e0635304b2bf7dab5b7c251eb1ad23048b05dac"
@@ -10817,11 +10808,6 @@ bluebird-retry@0.11.0:
resolved "https://registry.yarnpkg.com/bluebird-retry/-/bluebird-retry-0.11.0.tgz#1289ab22cbbc3a02587baad35595351dd0c1c047"
integrity sha1-EomrIsu8OgJYe6rTVZU1HdDBwEc=
bluebird@3.5.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.0.tgz#791420d7f551eea2897453a8a77653f96606d67c"
integrity sha1-eRQg1/VR7qKJdFOop3ZT+WYG1nw=
bluebird@3.5.3:
version "3.5.3"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.3.tgz#7d01c6f9616c9a51ab0f8c549a79dfe6ec33efa7"
@@ -26097,6 +26083,11 @@ ramda@0.27.1, ramda@^0.27.1:
resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.27.1.tgz#66fc2df3ef873874ffc2da6aa8984658abacf5c9"
integrity sha512-PgIdVpn5y5Yns8vqb8FzBUEYn98V3xcPgawAkkgj0YJ0qDsnHCiNmZYfOGMgOvoB0eWFLpYbhxUR3mxfDIMvpw==
ramda@0.28.0:
version "0.28.0"
resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.28.0.tgz#acd785690100337e8b063cab3470019be427cc97"
integrity sha512-9QnLuG/kPVgWvMQ4aODhsBUFKOUmnbUnsSXACv+NCQZcHbeb+v8Lodp8OVxtRULN1/xOyYLLaL6npE6dMq5QTA==
randexp@0.5.3:
version "0.5.3"
resolved "https://registry.yarnpkg.com/randexp/-/randexp-0.5.3.tgz#f31c2de3148b30bdeb84b7c3f59b0ebb9fec3738"
@@ -28458,6 +28449,23 @@ snap-shot-core@10.2.4:
quote "0.4.0"
ramda "0.27.1"
snap-shot-it@7.9.10, snap-shot-it@^7.9.6:
version "7.9.10"
resolved "https://registry.yarnpkg.com/snap-shot-it/-/snap-shot-it-7.9.10.tgz#6198a19f6281fa701254fabfa7c895783cee09b1"
integrity sha512-9USmsI2jc2kQslRhqkzFX+2K23o6v3VEzlQHwUNpZbbnEdU0ommReg2+Px7260sd+P/6CtaDx+LXadzt4caMVQ==
dependencies:
"@bahmutov/data-driven" "1.0.0"
check-more-types "2.24.0"
common-tags "1.8.2"
debug "4.3.4"
has-only "1.1.1"
its-name "1.0.0"
lazy-ass "1.6.0"
pluralize "8.0.0"
ramda "0.28.0"
snap-shot-compare "3.0.0"
snap-shot-core "10.2.4"
snap-shot-it@7.9.2:
version "7.9.2"
resolved "https://registry.yarnpkg.com/snap-shot-it/-/snap-shot-it-7.9.2.tgz#575302f8b3881fde851bdaa99c65e1fd9760bb98"
@@ -28492,7 +28500,7 @@ snap-shot-it@7.9.3:
snap-shot-compare "3.0.0"
snap-shot-core "10.2.0"
snap-shot-it@7.9.6, snap-shot-it@^7.9.6:
snap-shot-it@7.9.6:
version "7.9.6"
resolved "https://registry.yarnpkg.com/snap-shot-it/-/snap-shot-it-7.9.6.tgz#042c168980a1dc3ba7ffe2bb2beeaa8e9512772d"
integrity sha512-t/ADZfQ8EUk4J76S5cmynye7qg1ecUFqQfANiOMNy0sFmYUaqfx9K/AWwpdcpr3vFsDptM+zSuTtKD0A1EOLqA==