Skip to content

Commit c9ef76f

Browse files
committed
fix: use plugin fail event, closes #109
1 parent 8d8d5da commit c9ef76f

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ package = "netlify-plugin-cypress"
8686

8787
The following parameters can be used with "onSuccess" tests: `record`, `group`, `tag`, `spec`.
8888

89+
**Note:** if any tests against the deployed URL fail, the Netlify build still considers it a success. Thus if you want to have a test check against the deploy, install [Cypress GitHub App](https://on.cypress.io/github-integration). The app will provide its own failing status check in this case.
90+
8991
### recording
9092

9193
To record test results and artifacts on Cypress Dashboard, set `record: true` plugin input and set `CYPRESS_RECORD_KEY` as an environment variable via Netlify Deploy settings.

src/index.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,13 @@ async function cypressInfo(arg) {
175175
}
176176
}
177177

178-
const processCypressResults = (results, buildUtils) => {
178+
const processCypressResults = (results, errorCallback) => {
179179
if (results.failures) {
180180
// Cypress failed without even running the tests
181181
console.error('Problem running Cypress')
182182
console.error(results.message)
183183

184-
return buildUtils.failBuild('Problem running Cypress', {
184+
return errorCallback('Problem running Cypress', {
185185
error: new Error(results.message),
186186
})
187187
}
@@ -195,7 +195,7 @@ const processCypressResults = (results, buildUtils) => {
195195

196196
// results.totalFailed gives total number of failed tests
197197
if (results.totalFailed) {
198-
return buildUtils.failBuild('Failed Cypress tests', {
198+
return errorCallback('Failed Cypress tests', {
199199
error: new Error(`${results.totalFailed} test(s) failed`),
200200
})
201201
}
@@ -208,7 +208,7 @@ async function postBuild({
208208
group,
209209
tag,
210210
spa,
211-
buildUtils,
211+
errorCallback,
212212
}) {
213213
const port = 8080
214214
let server
@@ -217,7 +217,7 @@ async function postBuild({
217217
server = serveFolder(fullPublishFolder, port, spa)
218218
debug('local server listening on port %d', port)
219219
} catch (err) {
220-
return buildUtils.failBuild(`Could not serve folder ${fullPublishFolder}`, {
220+
return errorCallback(`Could not serve folder ${fullPublishFolder}`, {
221221
error: err,
222222
})
223223
}
@@ -236,7 +236,7 @@ async function postBuild({
236236
})
237237
})
238238

239-
processCypressResults(results, buildUtils)
239+
processCypressResults(results, errorCallback)
240240
}
241241

242242
const hasRecordKey = () => typeof process.env.CYPRESS_RECORD_KEY === 'string'
@@ -313,7 +313,7 @@ module.exports = {
313313
}
314314
const spa = arg.inputs.spa
315315

316-
const buildUtils = arg.utils.build
316+
const errorCallback = arg.utils.build.failBuild.bind(arg.utils.build)
317317

318318
await postBuild({
319319
fullPublishFolder,
@@ -322,7 +322,7 @@ module.exports = {
322322
group,
323323
tag,
324324
spa,
325-
buildUtils,
325+
errorCallback,
326326
})
327327
},
328328

@@ -356,8 +356,10 @@ module.exports = {
356356

357357
debug('onSuccessInputs %s %o', typeof onSuccessInputs, onSuccessInputs)
358358

359+
const errorCallback = utils.build.failPlugin.bind(utils.build)
360+
359361
if (!deployPrimeUrl) {
360-
return utils.build.failBuild('Missing DEPLOY_PRIME_URL')
362+
return errorCallback('Missing DEPLOY_PRIME_URL')
361363
}
362364

363365
// only if the user wants to record the tests and has set the record key
@@ -393,6 +395,6 @@ module.exports = {
393395
group,
394396
tag,
395397
)
396-
processCypressResults(results, utils.build)
398+
processCypressResults(results, errorCallback)
397399
},
398400
}

0 commit comments

Comments
 (0)