Skip to content

Commit c36eb7f

Browse files
authored
Merge branch 'develop' into tbiethman/chore/issue-21068-electron-bump
2 parents 07a8c4f + 546ed16 commit c36eb7f

File tree

5 files changed

+79
-25
lines changed

5 files changed

+79
-25
lines changed

cli/__snapshots__/errors_spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ exports['errors individual has the following errors 1'] = [
3232
"childProcessKilled",
3333
"failedDownload",
3434
"failedUnzip",
35+
"failedUnzipWindowsMaxPathLength",
3536
"incompatibleHeadlessFlags",
3637
"invalidCacheDirectory",
3738
"invalidCypressEnv",

cli/__snapshots__/unzip_spec.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
exports['unzip error 1'] = `
1+
exports['lib/tasks/unzip throws when cannot unzip 1'] = `
22
Error: The Cypress App could not be unzipped.
33
44
Search for an existing issue or open a GitHub issue at
@@ -15,3 +15,21 @@ Platform: darwin-x64 (Foo-OsVersion)
1515
Cypress Version: 1.2.3
1616
1717
`
18+
19+
exports['lib/tasks/unzip throws max path length error when cannot unzip due to realpath ENOENT on windows 1'] = `
20+
Error: The Cypress App could not be unzipped.
21+
22+
This is most likely because the maximum path length is being exceeded on your system.
23+
24+
Read here for solutions to this problem: https://on.cypress.io/win-max-path-length-error
25+
26+
----------
27+
28+
Error: failed
29+
30+
----------
31+
32+
Platform: win32-x64 (Foo-OsVersion)
33+
Cypress Version: 1.2.3
34+
35+
`

cli/lib/errors.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ const failedUnzip = {
5858
solution: genericErrorSolution,
5959
}
6060

61+
const failedUnzipWindowsMaxPathLength = {
62+
description: 'The Cypress App could not be unzipped.',
63+
solution: `This is most likely because the maximum path length is being exceeded on your system.
64+
65+
Read here for solutions to this problem: https://on.cypress.io/win-max-path-length-error`,
66+
}
67+
6168
const missingApp = (binaryDir) => {
6269
return {
6370
description: `No version of Cypress is installed in: ${chalk.cyan(
@@ -404,6 +411,7 @@ module.exports = {
404411
unexpected,
405412
failedDownload,
406413
failedUnzip,
414+
failedUnzipWindowsMaxPathLength,
407415
invalidCypressEnv,
408416
invalidCacheDirectory,
409417
CYPRESS_RUN_BINARY,

cli/lib/tasks/unzip.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,26 +195,35 @@ const unzip = ({ zipFilePath, installDir, progress }) => {
195195
})
196196
}
197197

198-
const start = ({ zipFilePath, installDir, progress }) => {
198+
function isMaybeWindowsMaxPathLengthError (err) {
199+
return os.platform() === 'win32' && err.code === 'ENOENT' && err.syscall === 'realpath'
200+
}
201+
202+
const start = async ({ zipFilePath, installDir, progress }) => {
199203
la(is.unemptyString(installDir), 'missing installDir')
200204
if (!progress) {
201205
progress = { onProgress: () => {
202206
return {}
203207
} }
204208
}
205209

206-
return fs.pathExists(installDir)
207-
.then((exists) => {
208-
if (exists) {
210+
try {
211+
const installDirExists = await fs.pathExists(installDir)
212+
213+
if (installDirExists) {
209214
debug('removing existing unzipped binary', installDir)
210215

211-
return fs.removeAsync(installDir)
216+
await fs.removeAsync(installDir)
212217
}
213-
})
214-
.then(() => {
215-
return unzip({ zipFilePath, installDir, progress })
216-
})
217-
.catch(throwFormErrorText(errors.failedUnzip))
218+
219+
await unzip({ zipFilePath, installDir, progress })
220+
} catch (err) {
221+
const errorTemplate = isMaybeWindowsMaxPathLengthError(err) ?
222+
errors.failedUnzipWindowsMaxPathLength
223+
: errors.failedUnzip
224+
225+
await throwFormErrorText(errorTemplate)(err)
226+
}
218227
}
219228

220229
module.exports = {

cli/test/lib/tasks/unzip_spec.js

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,44 @@ describe('lib/tasks/unzip', function () {
3030

3131
afterEach(function () {
3232
stdout.restore()
33+
})
34+
35+
it('throws when cannot unzip', async function () {
36+
try {
37+
await unzip.start({
38+
zipFilePath: path.join('test', 'fixture', 'bad_example.zip'),
39+
installDir,
40+
})
41+
} catch (err) {
42+
logger.error(err)
3343

34-
// return fs.removeAsync(installationDir)
44+
return snapshot(normalize(this.stdout.toString()))
45+
}
46+
47+
throw new Error('should have failed')
3548
})
3649

37-
it('throws when cannot unzip', function () {
38-
const ctx = this
50+
it('throws max path length error when cannot unzip due to realpath ENOENT on windows', async function () {
51+
const err = new Error('failed')
3952

40-
return unzip
41-
.start({
42-
zipFilePath: path.join('test', 'fixture', 'bad_example.zip'),
43-
installDir,
44-
})
45-
.then(() => {
46-
throw new Error('should have failed')
47-
})
48-
.catch((err) => {
53+
err.code = 'ENOENT'
54+
err.syscall = 'realpath'
55+
56+
os.platform.returns('win32')
57+
sinon.stub(fs, 'ensureDirAsync').rejects(err)
58+
59+
try {
60+
await unzip.start({
61+
zipFilePath: path.join('test', 'fixture', 'bad_example.zip'),
62+
installDir,
63+
})
64+
} catch (err) {
4965
logger.error(err)
5066

51-
snapshot('unzip error 1', normalize(ctx.stdout.toString()))
52-
})
67+
return snapshot(normalize(this.stdout.toString()))
68+
}
69+
70+
throw new Error('should have failed')
5371
})
5472

5573
it('can really unzip', function () {

0 commit comments

Comments
 (0)