Skip to content

Commit ea83415

Browse files
chore: move questions-remain into cypress repo (#29542)
* chore: move questions-remain into cypress repo * to js file * SLASH!
1 parent e6b422c commit ea83415

File tree

6 files changed

+119
-18
lines changed

6 files changed

+119
-18
lines changed

Diff for: __snapshots__/questions-remain-spec.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
exports['questions-remain returns object if all questions have been answered 1'] = {
2+
'foo': 'foo is specified',
3+
'bar': 'so is bar',
4+
}
5+
6+
exports['questions-remain asks questions for missing options 1'] = {
7+
'foo': 'foo is specified',
8+
'bar': 'bar user answer',
9+
}

Diff for: package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@
7474
"@aws-sdk/client-s3": "3.485.0",
7575
"@aws-sdk/credential-providers": "3.53.0",
7676
"@babel/eslint-parser": "7.24.1",
77-
"@cypress/questions-remain": "1.0.1",
7877
"@cypress/request": "^3.0.0",
7978
"@cypress/request-promise": "^5.0.0",
8079
"@electron/fuses": "1.6.1",
@@ -197,7 +196,7 @@
197196
"semver": "7.5.3",
198197
"shelljs": "0.8.5",
199198
"sinon": "7.3.2",
200-
"snap-shot-it": "7.9.3",
199+
"snap-shot-it": "7.9.10",
201200
"stop-only": "3.0.1",
202201
"strip-ansi": "6.0.0",
203202
"tar": "6.1.15",

Diff for: scripts/binary/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ const minimist = require('minimist')
1111
const la = require('lazy-ass')
1212
const check = require('check-more-types')
1313
const debug = require('debug')('cypress:binary')
14-
const questionsRemain = require('@cypress/questions-remain')
1514
const rp = require('@cypress/request-promise')
1615

1716
const zip = require('./zip')
1817
const ask = require('./ask')
1918
const meta = require('./meta')
2019
const build = require('./build')
2120
const upload = require('./upload')
21+
const questionsRemain = require('./util/questions-remain')
2222
const uploadUtils = require('./util/upload')
2323
const { uploadArtifactToS3 } = require('./upload-build-artifact')
2424
const { moveBinaries } = require('./move-binaries')

Diff for: scripts/binary/util/questions-remain.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const la = require('lazy-ass')
2+
const is = require('check-more-types')
3+
const bluebird = require('bluebird')
4+
5+
// goes through the list of properties and asks relevant question
6+
// resolves with all relevant options set
7+
// if the property already exists, skips the question
8+
function askMissingOptions (propertiesToQuestions) {
9+
la(is.object(propertiesToQuestions), 'expected object property:question')
10+
11+
// options are collected from the CLI
12+
return (options = {}) => {
13+
const reducer = (memo, property) => {
14+
if (is.has(memo, property)) {
15+
return memo
16+
}
17+
18+
const question = propertiesToQuestions[property]
19+
20+
if (!is.fn(question)) {
21+
return memo
22+
}
23+
24+
la(is.fn(question), 'cannot find question for property', property)
25+
26+
return question(memo[property]).then((answer) => {
27+
memo[property] = answer
28+
29+
return memo
30+
})
31+
}
32+
33+
const properties = Object.keys(propertiesToQuestions)
34+
35+
return bluebird.reduce(properties, reducer, options)
36+
}
37+
}
38+
39+
module.exports = askMissingOptions

Diff for: scripts/unit/binary/util/questions-remain-spec.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* global sinon */
2+
const questionsRemain = require('../../../binary/util/questions-remain')
3+
const la = require('lazy-ass')
4+
const snapshot = require('snap-shot-it')
5+
6+
describe('questions-remain', () => {
7+
const dontAsk = () => {
8+
throw new Error('Should not ask!')
9+
}
10+
11+
it('is a function', () => {
12+
if (typeof questionsRemain !== 'function') throw new Error('questionsRemain is not a function')
13+
})
14+
15+
it('returns object if all questions have been answered', () => {
16+
const propertiesToQuestions = {
17+
foo: dontAsk,
18+
bar: dontAsk,
19+
}
20+
const options = {
21+
foo: 'foo is specified',
22+
bar: 'so is bar',
23+
}
24+
25+
// console.log(questionsRemain(propertiesToQuestions)(options))
26+
return questionsRemain(propertiesToQuestions)(options).then(snapshot)
27+
})
28+
29+
it('asks questions for missing options', () => {
30+
const barStub = sinon.stub().resolves('bar user answer')
31+
const propertiesToQuestions = {
32+
foo: dontAsk,
33+
bar: barStub,
34+
}
35+
const options = {
36+
foo: 'foo is specified',
37+
// notice bar is missing!
38+
}
39+
40+
return questionsRemain(propertiesToQuestions)(options)
41+
.then(snapshot)
42+
.then(() => {
43+
la(barStub.called, 'bar stub has not been called')
44+
})
45+
})
46+
})

Diff for: yarn.lock

+23-15
Original file line numberDiff line numberDiff line change
@@ -2942,15 +2942,6 @@
29422942
mkdirp "^0.5.1"
29432943
npm-run-all "^4.1.5"
29442944

2945-
"@cypress/[email protected]":
2946-
version "1.0.1"
2947-
resolved "https://registry.yarnpkg.com/@cypress/questions-remain/-/questions-remain-1.0.1.tgz#334dc830323192995b43d7bbae9dd6db5e551a22"
2948-
integrity sha1-M03IMDIxkplbQ9e7rp3W215VGiI=
2949-
dependencies:
2950-
bluebird "3.5.0"
2951-
check-more-types "2.24.0"
2952-
lazy-ass "1.6.0"
2953-
29542945
"@cypress/[email protected]":
29552946
version "0.5.3"
29562947
resolved "https://registry.yarnpkg.com/@cypress/react-tooltip/-/react-tooltip-0.5.3.tgz#3e0635304b2bf7dab5b7c251eb1ad23048b05dac"
@@ -10817,11 +10808,6 @@ [email protected]:
1081710808
resolved "https://registry.yarnpkg.com/bluebird-retry/-/bluebird-retry-0.11.0.tgz#1289ab22cbbc3a02587baad35595351dd0c1c047"
1081810809
integrity sha1-EomrIsu8OgJYe6rTVZU1HdDBwEc=
1081910810

10820-
10821-
version "3.5.0"
10822-
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.0.tgz#791420d7f551eea2897453a8a77653f96606d67c"
10823-
integrity sha1-eRQg1/VR7qKJdFOop3ZT+WYG1nw=
10824-
1082510811
1082610812
version "3.5.3"
1082710813
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.3.tgz#7d01c6f9616c9a51ab0f8c549a79dfe6ec33efa7"
@@ -26097,6 +26083,11 @@ [email protected], ramda@^0.27.1:
2609726083
resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.27.1.tgz#66fc2df3ef873874ffc2da6aa8984658abacf5c9"
2609826084
integrity sha512-PgIdVpn5y5Yns8vqb8FzBUEYn98V3xcPgawAkkgj0YJ0qDsnHCiNmZYfOGMgOvoB0eWFLpYbhxUR3mxfDIMvpw==
2609926085

26086+
26087+
version "0.28.0"
26088+
resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.28.0.tgz#acd785690100337e8b063cab3470019be427cc97"
26089+
integrity sha512-9QnLuG/kPVgWvMQ4aODhsBUFKOUmnbUnsSXACv+NCQZcHbeb+v8Lodp8OVxtRULN1/xOyYLLaL6npE6dMq5QTA==
26090+
2610026091
2610126092
version "0.5.3"
2610226093
resolved "https://registry.yarnpkg.com/randexp/-/randexp-0.5.3.tgz#f31c2de3148b30bdeb84b7c3f59b0ebb9fec3738"
@@ -28458,6 +28449,23 @@ [email protected]:
2845828449
quote "0.4.0"
2845928450
ramda "0.27.1"
2846028451

28452+
[email protected], snap-shot-it@^7.9.6:
28453+
version "7.9.10"
28454+
resolved "https://registry.yarnpkg.com/snap-shot-it/-/snap-shot-it-7.9.10.tgz#6198a19f6281fa701254fabfa7c895783cee09b1"
28455+
integrity sha512-9USmsI2jc2kQslRhqkzFX+2K23o6v3VEzlQHwUNpZbbnEdU0ommReg2+Px7260sd+P/6CtaDx+LXadzt4caMVQ==
28456+
dependencies:
28457+
"@bahmutov/data-driven" "1.0.0"
28458+
check-more-types "2.24.0"
28459+
common-tags "1.8.2"
28460+
debug "4.3.4"
28461+
has-only "1.1.1"
28462+
its-name "1.0.0"
28463+
lazy-ass "1.6.0"
28464+
pluralize "8.0.0"
28465+
ramda "0.28.0"
28466+
snap-shot-compare "3.0.0"
28467+
snap-shot-core "10.2.4"
28468+
2846128469
2846228470
version "7.9.2"
2846328471
resolved "https://registry.yarnpkg.com/snap-shot-it/-/snap-shot-it-7.9.2.tgz#575302f8b3881fde851bdaa99c65e1fd9760bb98"
@@ -28492,7 +28500,7 @@ [email protected]:
2849228500
snap-shot-compare "3.0.0"
2849328501
snap-shot-core "10.2.0"
2849428502

28495-
[email protected], snap-shot-it@^7.9.6:
28503+
2849628504
version "7.9.6"
2849728505
resolved "https://registry.yarnpkg.com/snap-shot-it/-/snap-shot-it-7.9.6.tgz#042c168980a1dc3ba7ffe2bb2beeaa8e9512772d"
2849828506
integrity sha512-t/ADZfQ8EUk4J76S5cmynye7qg1ecUFqQfANiOMNy0sFmYUaqfx9K/AWwpdcpr3vFsDptM+zSuTtKD0A1EOLqA==

0 commit comments

Comments
 (0)