mirror of
https://github.com/cypress-io/cypress.git
synced 2026-01-25 16:39:04 -06:00
* hacky way to update snapshots * new hack to update snapshots * trying again * hacky fix * ci: snapshots * ci: snapshots * snapshots * mas updates * update spec API * fix test * fix test * update * update test * fix test * update plugin * update spec * webpack optinos * Update launchpad tests * fix screenshot paths * updated snapshot * change pattern * guard * fix smoke test * patch code coverage * update percy config * fix specs * try updating example project * update snapshots * remove old test * remove snapshot hack * add back appveyor * remove old code * update snapshot * Fix tests * wip * revert snapshot * reverted all snaps * remove only * remove commnet * remove old code * reverted file * lint * revert video compression spec * update snapshot * update spec path logic * update snap * updated snap * snaps * snaps * fix spec * rename ignoreTestFiles to ignoreSpecPattern * update screenshot dir for runner-ct * update deprecations * update * upate * fix test * update snaps * update snap * updating snap * added missing snaps * updated cypress run mode integration spec * electron snapshot * update default * rename integration->e2e * rename integration->e2e in packages * spec.ts -> cy.ts * spec.ts -> cy.ts * _spec.js -> .cy.js * .spec.js -> .cy.js * .spec.js -> .cy.js * update config * update config * update * update spec ext * update config * update config * ensure newly scaffold specs are cached * fix launchpad spec * types * update test * transpile based on spec pattern * add back example * remove unnecessary async and nodeVersion * spec.tsx -> cy.tsx * update stop-only config * exclude CT from E2E * removed old test * update spec pattern in angular * update spec pattern in design system * update all specs npm npm/react * update spec name * update spec patterns * remove old script * update tests path * update config * fix test * update snapshots * update examples * update ignore patterns * update snapshots * unit tests * update tests * patch code coverage * revert spec name * rename a lot of speces * update * update spec ext * update spec * update spec * update spec ext * update lint * update rules * update lint * snaps * update spec dir * update paths * remove unused pluginsfile config opt * update smoke test * update create cypress tests * update gitignore * update types * update paths * update spe * update test * update all snaps * update tests * update http request spec * update spec file names * snaps * update snaps * updated snaps * update snaps * spacing * spacing * spacing * spacing * fix perf spec * update * update * revert * update * snaps * snaps * rename spec * update snaps * snapshots * update tests * update tests * update * fix * update test projects * update * updating * update run-ct test * update spec pattern and add defensive check around platform * fix system test script * update snap * snaps * update test * update spe * update for FF * ff * remove unused feature flag * added tests * fix react example * update test * update config * update test projects * update snapshots * correctly remove private prefix on darwin * fix types * rename integration -> e2e * update config * updatec onfig * fixing app scaffold integration tests * remove code * exclude e2e specs from CT * update snapshot * integration->e2e * update path for test file in ts project * update schematic * use updated branch for CI * update config * update config * revert some changes * remove built code * revert changes * update gitignore * include test spec * update scaffold script * wip: renames * script * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * mass rename * rename * rename * fix angular * update spec in create cypress tests * remove old file * fix tests * access specPattern in a more idiomatic fashion * do not duplicate variable * pass correct params to findSpec in files controller * add comment explaining spec finding * remove reference to old file that no longer exist * resolve conflicts * fix types * transpile cypress dir * update circle ymlg * update spec pattern for example project * supportFile: false * fix circle yml * update test glob * rename some specs to use correct .cy ext * more ext renames * rename spec * update extensions * update extensions * update specs Co-authored-by: estrada9166 <estrada9166@hotmail.com> Co-authored-by: Emily Rohrbough <emilyrohrbough@users.noreply.github.com>
183 lines
4.6 KiB
JavaScript
183 lines
4.6 KiB
JavaScript
const _ = require('lodash')
|
|
const fse = require('fs-extra')
|
|
const cp = require('child_process')
|
|
const execa = require('execa')
|
|
const path = require('path')
|
|
const Promise = require('bluebird')
|
|
const os = require('os')
|
|
const verify = require('../../cli/lib/tasks/verify')
|
|
const Fixtures = require('@tooling/system-tests/lib/fixtures')
|
|
|
|
const fs = Promise.promisifyAll(fse)
|
|
|
|
const canRecordVideo = () => {
|
|
return os.platform() !== 'win32'
|
|
}
|
|
|
|
const shouldSkipProjectTest = () => {
|
|
return os.platform() === 'win32'
|
|
}
|
|
|
|
const runSmokeTest = function (buildAppExecutable, timeoutSeconds = 30) {
|
|
const rand = String(_.random(0, 1000))
|
|
|
|
console.log(`executable path ${buildAppExecutable}`)
|
|
console.log(`timeout ${timeoutSeconds} seconds`)
|
|
|
|
const hasRightResponse = function (stdout) {
|
|
// there could be more debug lines in the output, so find 1 line with
|
|
// expected random value
|
|
const lines = stdout.split('\n').map((s) => {
|
|
return s.trim()
|
|
})
|
|
|
|
return lines.includes(rand)
|
|
}
|
|
|
|
const args = []
|
|
|
|
if (verify.needsSandbox()) {
|
|
args.push('--no-sandbox')
|
|
}
|
|
|
|
// separate any Electron command line arguments from Cypress args
|
|
args.push('--')
|
|
args.push('--smoke-test')
|
|
args.push(`--ping=${rand}`)
|
|
|
|
const options = {
|
|
timeout: timeoutSeconds * 1000,
|
|
}
|
|
|
|
return execa(`${buildAppExecutable}`, args, options)
|
|
.catch((err) => {
|
|
console.error('smoke test failed with error %s', err.message)
|
|
throw err
|
|
}).then(({ stdout }) => {
|
|
stdout = stdout.replace(/\s/, '')
|
|
if (!hasRightResponse(stdout)) {
|
|
throw new Error(`Stdout: '${stdout}' did not match the random number: '${rand}'`)
|
|
}
|
|
|
|
console.log('smoke test response', stdout)
|
|
|
|
return console.log('smokeTest passes')
|
|
})
|
|
}
|
|
|
|
const runProjectTest = function (buildAppExecutable, e2e) {
|
|
if (shouldSkipProjectTest()) {
|
|
console.log('skipping project test')
|
|
|
|
return Promise.resolve()
|
|
}
|
|
|
|
return new Promise((resolve, reject) => {
|
|
const env = _.omit(process.env, 'CYPRESS_INTERNAL_ENV')
|
|
|
|
if (!canRecordVideo()) {
|
|
console.log('cannot record video on this platform yet, disabling')
|
|
env.CYPRESS_VIDEO_RECORDING = 'false'
|
|
}
|
|
|
|
const args = [
|
|
`--run-project=${e2e}`,
|
|
`--spec=${e2e}/cypress/e2e/simple_passing.cy.js`,
|
|
]
|
|
|
|
if (verify.needsSandbox()) {
|
|
args.push('--no-sandbox')
|
|
}
|
|
|
|
const options = {
|
|
stdio: 'inherit', env,
|
|
}
|
|
|
|
console.log('running project test')
|
|
console.log(buildAppExecutable, args.join(' '))
|
|
|
|
return cp.spawn(buildAppExecutable, args, options)
|
|
.on('exit', (code) => {
|
|
if (code === 0) {
|
|
return resolve()
|
|
}
|
|
|
|
return reject(new Error(`running project tests failed with: '${code}' errors.`))
|
|
})
|
|
})
|
|
}
|
|
|
|
const runFailingProjectTest = function (buildAppExecutable, e2e) {
|
|
if (shouldSkipProjectTest()) {
|
|
console.log('skipping failing project test')
|
|
|
|
return Promise.resolve()
|
|
}
|
|
|
|
console.log('running failing project test')
|
|
|
|
const verifyScreenshots = function () {
|
|
const screenshot1 = path.join(e2e, 'cypress', 'screenshots', 'simple_failing.cy.js', 'simple failing spec -- fails1 (failed).png')
|
|
const screenshot2 = path.join(e2e, 'cypress', 'screenshots', 'simple_failing.cy.js', 'simple failing spec -- fails2 (failed).png')
|
|
|
|
return Promise.all([
|
|
fs.statAsync(screenshot1),
|
|
fs.statAsync(screenshot2),
|
|
])
|
|
}
|
|
|
|
const spawn = () => {
|
|
return new Promise((resolve, reject) => {
|
|
const env = _.omit(process.env, 'CYPRESS_INTERNAL_ENV')
|
|
|
|
const args = [
|
|
`--run-project=${e2e}`,
|
|
`--spec=${e2e}/cypress/e2e/simple_failing.cy.js`,
|
|
]
|
|
|
|
if (verify.needsSandbox()) {
|
|
args.push('--no-sandbox')
|
|
}
|
|
|
|
const options = {
|
|
stdio: 'inherit',
|
|
env,
|
|
}
|
|
|
|
return cp.spawn(buildAppExecutable, args, options)
|
|
.on('exit', (code) => {
|
|
if (code === 2) {
|
|
return resolve()
|
|
}
|
|
|
|
return reject(new Error(`running project tests failed with: '${code}' errors.`))
|
|
})
|
|
})
|
|
}
|
|
|
|
return spawn()
|
|
.then(verifyScreenshots)
|
|
}
|
|
|
|
const test = async function (buildAppExecutable) {
|
|
await Fixtures.scaffoldCommonNodeModules()
|
|
Fixtures.scaffoldProject('e2e')
|
|
const e2e = Fixtures.projectPath('e2e')
|
|
|
|
await runSmokeTest(buildAppExecutable)
|
|
await runProjectTest(buildAppExecutable, e2e)
|
|
await runFailingProjectTest(buildAppExecutable, e2e)
|
|
Fixtures.remove()
|
|
}
|
|
|
|
module.exports = {
|
|
test,
|
|
}
|
|
|
|
if (require.main === module) {
|
|
const buildAppExecutable = path.join(__dirname, `../../build/${os.platform()}-unpacked/Cypress`)
|
|
|
|
console.log('Script invoked directly, running smoke tests.')
|
|
test(buildAppExecutable)
|
|
}
|