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

Commit df21ee8

Browse files
Merge pull request #9 from cypress-io/issue-8-silent-errors
Fix silent errors
2 parents c60ea9a + 045801e commit df21ee8

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

index.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,24 +92,30 @@ const preprocessor = (options = {}) => {
9292
// is invoked again with the same filePath
9393
bundles[filePath] = latestBundle.promise
9494

95+
const rejectWithErr = (err) => {
96+
err.filePath = filePath
97+
// backup the original stack before it's potentially modified by bluebird
98+
err.originalStack = err.stack
99+
log(`errored bundling ${outputPath}`, err)
100+
latestBundle.reject(err)
101+
}
102+
95103
// this function is called when bundling is finished, once at the start
96104
// and, if watching, each time watching triggers a re-bundle
97105
const handle = (err, stats) => {
98106
if (err) {
99-
err.filePath = filePath
100-
// backup the original stack before it's
101-
// potentially modified from bluebird
102-
err.originalStack = err.stack
103-
log(`errored bundling ${outputPath}`, err)
104-
return latestBundle.reject(err)
107+
return rejectWithErr(err)
105108
}
106109

107-
// these stats are really only useful for debugging
108110
const jsonStats = stats.toJson()
109-
if (jsonStats.errors.length > 0) {
110-
log(`soft errors for ${outputPath}`)
111-
log(jsonStats.errors)
111+
112+
if (stats.hasErrors()) {
113+
err = new Error('Webpack Compilation Error')
114+
err.stack = jsonStats.errors.join('\n\n')
115+
return rejectWithErr(err)
112116
}
117+
118+
// these stats are really only useful for debugging
113119
if (jsonStats.warnings.length > 0) {
114120
log(`warnings for ${outputPath}`)
115121
log(jsonStats.warnings)

test/index_spec.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ describe('webpack preprocessor', function () {
3232
webpack.returns(this.compilerApi)
3333

3434
this.statsApi = {
35+
hasErrors () { return false },
3536
toJson () { return { warnings: [], errors: [] } },
3637
}
3738

@@ -168,13 +169,25 @@ describe('webpack preprocessor', function () {
168169
}
169170
})
170171

171-
it('it rejects with error', function () {
172+
it('it rejects with error when an err', function () {
172173
this.compilerApi.run.yields(this.err)
173174
return this.run().catch((err) => {
174175
expect(err.stack).to.equal(this.err.stack)
175176
})
176177
})
177178

179+
it('it rejects with joined errors when a stats err', function () {
180+
const errs = ['foo', 'bar', 'baz']
181+
this.statsApi = {
182+
hasErrors () { return true },
183+
toJson () { return { errors: errs } },
184+
}
185+
this.compilerApi.run.yields(null, this.statsApi)
186+
return this.run().catch((err) => {
187+
expect(err.stack).to.equal(errs.join('\n\n'))
188+
})
189+
})
190+
178191
it('backs up stack as originalStack', function () {
179192
this.compilerApi.run.yields(this.err)
180193
return this.run().catch((err) => {

0 commit comments

Comments
 (0)