diff --git a/lib/commands/test/cypress.js b/lib/commands/test/cypress.js index 33b4f14..79bfff2 100644 --- a/lib/commands/test/cypress.js +++ b/lib/commands/test/cypress.js @@ -55,7 +55,11 @@ function cypressCommand(argv) { webpackConfig.mode = 'none'; const cypressService = new CypressService(context.cwd); - cypressService.runCypressTests(webpackConfig, Object.assign({}, argv.cypress, { watch: argv.watch, cache: argv.cache }), context); + if (argv.cypress?.install) { + cypressService.installAndRun(webpackConfig, Object.assign({}, argv.cypress, { watch: argv.watch, cache: argv.cache }), context); + } else { + cypressService.runCypressTests(webpackConfig, Object.assign({}, argv.cypress, { watch: argv.watch, cache: argv.cache }), context); + } } module.exports = { @@ -80,6 +84,7 @@ module.exports = { .option('cypress', { describe: 'Options passed to Cypress using dot-notation and camelCase: --cypress.browsers=Chrome --cypress.singleRun', }) + .option('cypress.install', { type: 'boolean', describe: 'install cypress manually to account for ignore-scripts' }) .option('cypress.open', { type: 'boolean', describe: 'run cypress in ui mode' }) .option('cypress.browsers', { type: 'array', hidden: true }) // defined but hidden so yargs will parse as an array .option('cypress.reporters', { type: 'array', hidden: true }) diff --git a/lib/test/cypress-service.js b/lib/test/cypress-service.js index b868706..a6fb7a9 100644 --- a/lib/test/cypress-service.js +++ b/lib/test/cypress-service.js @@ -1,6 +1,9 @@ const fs = require('fs'); const path = require('path'); const os = require('os'); +const util = require('util'); +const exec = util.promisify(require('child_process').exec); + const _pickBy = require('lodash/pickBy'); const { defineConfig, run, open } = require('cypress'); @@ -208,6 +211,11 @@ class CypressService { logger.log('Error running cypress tests:', e); } } + + async installAndRun(...args) { + await exec('npx cypress install'); + this.runCypressTests(args); + } } module.exports = {