Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
29 changes: 4 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@
],
"license": "ISC",
"dependencies": {
"argument-vector": "1.0.2",
"check-more-types": "2.24.0",
"debug": "4.1.1",
"ecstatic": "4.1.2",
"got": "9.6.0",
"lazy-ass": "1.6.0"
"got": "9.6.0"
},
"repository": {
"type": "git",
Expand Down
28 changes: 11 additions & 17 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ const ecstatic = require('ecstatic')
const http = require('http')
const debug = require('debug')('netlify-plugin-cypress')
const debugVerbose = require('debug')('netlify-plugin-cypress:verbose')
const la = require('lazy-ass')
const is = require('check-more-types')
const { ping } = require('./utils')

function serveFolder (folder, port) {
Expand Down Expand Up @@ -33,7 +31,7 @@ function startServerMaybe (run, options = {}) {
}
}

async function waitOnMaybe (failPlugin, options = {}) {
async function waitOnMaybe (buildUtils, options = {}) {
const waitOnUrl = options['wait-on']
if (!waitOnUrl) {
debug('no wait-on defined')
Expand All @@ -56,7 +54,7 @@ async function waitOnMaybe (failPlugin, options = {}) {
} catch (err) {
debug('pinging %s for %d ms failed', waitOnUrl, waitTimeoutMs)
debug(err)
failPlugin(`Pinging ${waitOnUrl} for ${waitTimeoutMs} failed`, { error: err })
return buildUtils.failBuild(`Pinging ${waitOnUrl} for ${waitTimeoutMs} failed`, { error: err })
}
}

Expand Down Expand Up @@ -95,13 +93,13 @@ async function onInit(arg) {
await arg.utils.run('cypress', ['install'], runOptions)
}

const processCypressResults = (results, failPlugin) => {
const processCypressResults = (results, buildUtils) => {
if (results.failures) {
// Cypress failed without even running the tests
console.error('Problem running Cypress')
console.error(results.message)

return failPlugin('Problem running Cypress', {
return buildUtils.failPlugin('Problem running Cypress', {
error: new Error(results.message)
})
}
Expand All @@ -115,13 +113,13 @@ const processCypressResults = (results, failPlugin) => {

// results.totalFailed gives total number of failed tests
if (results.totalFailed) {
return failPlugin('Failed Cypress tests', {
return buildUtils.failBuild('Failed Cypress tests', {
error: new Error(`${results.totalFailed} test(s) failed`)
})
}
}

async function postBuild({ fullPublishFolder, record, spec, group, tag, failPlugin }) {
async function postBuild({ fullPublishFolder, record, spec, group, tag, buildUtils }) {
const port = 8080
const server = serveFolder(fullPublishFolder, port)
debug('local server listening on port %d', port)
Expand All @@ -140,7 +138,7 @@ async function postBuild({ fullPublishFolder, record, spec, group, tag, failPlug
})
})

processCypressResults(results, failPlugin)
processCypressResults(results, buildUtils)
}

const hasRecordKey = () => typeof process.env.CYPRESS_RECORD_KEY === 'string'
Expand All @@ -155,11 +153,8 @@ module.exports = {
return
}

const failPlugin = arg.utils && arg.utils.build && arg.utils.build.failPlugin
la(is.fn(failPlugin), 'expected failPlugin function inside', arg.utils)

const closeServer = startServerMaybe(arg.utils.run, preBuildInputs)
await waitOnMaybe(failPlugin, preBuildInputs)
await waitOnMaybe(arg.utils.build, preBuildInputs)

const baseUrl = preBuildInputs['wait-on']
const record = hasRecordKey() && Boolean(preBuildInputs.record)
Expand All @@ -183,7 +178,7 @@ module.exports = {
closeServer()
}

processCypressResults(results, failPlugin)
processCypressResults(results, arg.utils.build)
},

onPostBuild: async (arg) => {
Expand All @@ -210,16 +205,15 @@ module.exports = {
}
}

const failPlugin = arg.utils && arg.utils.build && arg.utils.build.failPlugin
la(is.fn(failPlugin), 'expected failPlugin function inside', arg.utils)
const buildUtils = arg.utils.build

await postBuild({
fullPublishFolder,
record,
spec,
group,
tag,
failPlugin
buildUtils,
})
}
}