Skip to content

Commit

Permalink
implement cypress postinstall functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnC-80 committed Nov 22, 2024
1 parent 0e4d977 commit b69c404
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/commands/test/cypress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 })
Expand Down
8 changes: 8 additions & 0 deletions lib/test/cypress-service.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const fs = require('fs');
const path = require('path');
const os = require('os');

Check warning on line 3 in lib/test/cypress-service.js

View workflow job for this annotation

GitHub Actions / ui / Install and lint / Install and lint

'os' is assigned a value but never used. Allowed unused vars must match /React/u

Check warning on line 3 in lib/test/cypress-service.js

View workflow job for this annotation

GitHub Actions / ui / Install and lint / Install and lint

'os' is assigned a value but never used. Allowed unused vars must match /React/u
const util = require('util');
const exec = util.promisify(require('child_process').exec);

const _pickBy = require('lodash/pickBy');

const { defineConfig, run, open } = require('cypress');
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit b69c404

Please sign in to comment.