forked from cypress-io/netlify-plugin-cypress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathonSuccess.js
83 lines (70 loc) · 2.46 KB
/
onSuccess.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// @ts-check
const R = require('ramda')
const debug = require('debug')('netlify-plugin-cypress')
const debugVerbose = require('debug')('netlify-plugin-cypress:verbose')
const {
runCypressTests,
processCypressResults,
hasRecordKey,
} = require('./utils')
const { DEFAULT_BROWSER } = require('./constants')
module.exports = async ({ utils, inputs, constants }) => {
debugVerbose('onSuccess arg %o', { utils, inputs, constants })
// extract test run parameters
const onSuccessInputs = R.omit(['preBuild', 'postBuild'], inputs || {})
debug('onSuccess inputs %o', onSuccessInputs)
const isLocal = constants.IS_LOCAL
const siteName = process.env.SITE_NAME
const deployUrl = process.env[onSuccessInputs.deployUrlEnvVar] || process.env.DEPLOY_PRIME_URL;
debug('onSuccess against %o', {
siteName,
deployUrl,
isLocal,
})
const enableOnSuccessTests = Boolean(onSuccessInputs.enable)
if (!enableOnSuccessTests) {
debug('Skipping onSuccess tests')
return
}
debug('onSuccessInputs %s %o', typeof onSuccessInputs, onSuccessInputs)
const errorCallback = utils.build.failPlugin.bind(utils.build)
const summaryCallback = utils.status.show.bind(utils.status)
if (!deployUrl) {
return errorCallback('Missing Deploy URL. Please set a valid Netlify environment variable to pull the deploy URL from to set as the baseUrl in your cypress configuration. For example, set deployUrlEnvVar to DEPLOY_PRIME_URL.\nSee https://docs.netlify.com/configure-builds/environment-variables/#deploy-urls-and-metadata for more details on which ENVs can be used')
}
const browser = onSuccessInputs.browser || DEFAULT_BROWSER
// only if the user wants to record the tests and has set the record key
// then we should attempt recording
const hasKey = hasRecordKey()
const record = hasKey && Boolean(onSuccessInputs.record)
const spec = onSuccessInputs.spec
let group
let tag
if (record) {
group = onSuccessInputs.group || 'onSuccess'
if (onSuccessInputs.tag) {
tag = onSuccessInputs.tag
} else {
tag = process.env.CONTEXT
}
}
debug('deployed url test parameters %o', {
hasRecordKey: hasKey,
record,
spec,
group,
tag,
})
const configFile = onSuccessInputs.configFile
console.log('testing deployed url %s', deployUrl)
const results = await runCypressTests(
deployUrl,
record,
spec,
group,
tag,
browser,
configFile,
)
processCypressResults(results, errorCallback, summaryCallback)
}