Skip to content
This repository was archived by the owner on Oct 1, 2020. It is now read-only.

fix: fix compilation error message #63

Merged
merged 3 commits into from
Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions __snapshots__/e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Oops...we found an error preparing this test file:

The error was:

Error: Webpack Compilation Error
./cypress/tests/e2e/compile-error.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /[cwd]/cypress/tests/e2e/compile-error.js: Unexpected token, expected "," (12:27)
Expand All @@ -35,6 +36,7 @@ SyntaxError: /[cwd]/cypress/tests/e2e/compile-error.js: Unexpected token, expect

@ multi ./cypress/tests/e2e/compile-error.js main[0]


This occurred while Cypress was compiling and bundling your test code. This is usually caused by:

- A missing file or dependency
Expand Down
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ const preprocessor = (options = {}) => {

const rejectWithErr = (err) => {
err.filePath = filePath
// backup the original stack before it's potentially modified by bluebird
err.originalStack = err.stack
debug(`errored bundling ${outputPath}`, err)
latestBundle.reject(err)
}
Expand All @@ -125,7 +123,11 @@ const preprocessor = (options = {}) => {

if (stats.hasErrors()) {
err = new Error('Webpack Compilation Error')
err.stack = jsonStats.errors.join('\n\n')
err.message += `\n${jsonStats.errors
// remove stack trace lines since they're useless for debugging
.map((err) => err.replace(/\n\s*at.*/g, '').replace(/From previous event:\n?/g, ''))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this same logic is used in test runner to strip stack trace lines, so we're just moving this logic up
https://github.com/cypress-io/cypress/blob/master/packages/server/lib/plugins/preprocessor.coffee#L16

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ughh, this is so so weird - why have 3 lines of code inside a string template?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eslint auto-fixed to that when i tried to add '\n'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

// multiple errors separated by newline
.join('\n\n')}`

return rejectWithErr(err)
}
Expand Down