From c96a0c5299c5d9915d799461c4d7902f644a6d65 Mon Sep 17 00:00:00 2001 From: Chris Arter Date: Tue, 22 Aug 2023 08:52:30 -0400 Subject: [PATCH 1/3] supports modules in laravel 10.2.6 --- README.md | 2 +- src/CypressBoilerplateCommand.php | 6 +++--- src/stubs/{cypress.config.js => cypress.config.cjs} | 0 3 files changed, 4 insertions(+), 4 deletions(-) rename src/stubs/{cypress.config.js => cypress.config.cjs} (100%) diff --git a/README.md b/README.md index 8604012..8c3aa8e 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ In the Cypress window that opens, Choose "E2E Testing," and then "Start E2E Test ## Cypress Configuration -We've declared some initial settings in your project's `cypress.config.js` file. Have a quick look now to ensure that everything is in order. In particular, please ensure that the `baseUrl` property is set correctly (we default to your app's `APP_URL` environment setting). +We've declared some initial settings in your project's `cypress.config.cjs` file. Have a quick look now to ensure that everything is in order. In particular, please ensure that the `baseUrl` property is set correctly (we default to your app's `APP_URL` environment setting). ## Environment Handling diff --git a/src/CypressBoilerplateCommand.php b/src/CypressBoilerplateCommand.php index 98d7112..b0916db 100644 --- a/src/CypressBoilerplateCommand.php +++ b/src/CypressBoilerplateCommand.php @@ -11,7 +11,7 @@ class CypressBoilerplateCommand extends Command /** * The name and signature of the console command. */ - protected $signature = 'cypress:boilerplate { --config-path=cypress.config.js } { --force : Recreate existing configuration file }'; + protected $signature = 'cypress:boilerplate { --config-path=cypress.config.cjs } { --force : Recreate existing configuration file }'; /** * The console command description. @@ -90,7 +90,7 @@ protected function copyStubs(): void } /** - * Set the initial cypress.config.js configuration for the project. + * Set the initial cypress.config.cjs configuration for the project. */ protected function createCypressConfig(): void { @@ -118,7 +118,7 @@ protected function defaultCypressConfig(array $config = []): string config('app.url'), $this->cypressPath('', false) ], - $this->files->get(__DIR__ . '/stubs/cypress.config.js') + $this->files->get(__DIR__ . '/stubs/cypress.config.cjs') ); } diff --git a/src/stubs/cypress.config.js b/src/stubs/cypress.config.cjs similarity index 100% rename from src/stubs/cypress.config.js rename to src/stubs/cypress.config.cjs From 42c71fe849601de8f7bd5efa84f1c8f0b2c1f104 Mon Sep 17 00:00:00 2001 From: Chris Arter Date: Tue, 22 Aug 2023 11:40:36 -0400 Subject: [PATCH 2/3] convert stubs to ES modules --- README.md | 2 +- src/CypressBoilerplateCommand.php | 6 +++--- src/stubs/{cypress.config.cjs => cypress.config.js} | 4 ++-- src/stubs/plugins/index.js | 7 ++++--- src/stubs/plugins/swap-env.js | 4 ++-- 5 files changed, 12 insertions(+), 11 deletions(-) rename src/stubs/{cypress.config.cjs => cypress.config.js} (87%) diff --git a/README.md b/README.md index 8c3aa8e..8604012 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ In the Cypress window that opens, Choose "E2E Testing," and then "Start E2E Test ## Cypress Configuration -We've declared some initial settings in your project's `cypress.config.cjs` file. Have a quick look now to ensure that everything is in order. In particular, please ensure that the `baseUrl` property is set correctly (we default to your app's `APP_URL` environment setting). +We've declared some initial settings in your project's `cypress.config.js` file. Have a quick look now to ensure that everything is in order. In particular, please ensure that the `baseUrl` property is set correctly (we default to your app's `APP_URL` environment setting). ## Environment Handling diff --git a/src/CypressBoilerplateCommand.php b/src/CypressBoilerplateCommand.php index b0916db..98d7112 100644 --- a/src/CypressBoilerplateCommand.php +++ b/src/CypressBoilerplateCommand.php @@ -11,7 +11,7 @@ class CypressBoilerplateCommand extends Command /** * The name and signature of the console command. */ - protected $signature = 'cypress:boilerplate { --config-path=cypress.config.cjs } { --force : Recreate existing configuration file }'; + protected $signature = 'cypress:boilerplate { --config-path=cypress.config.js } { --force : Recreate existing configuration file }'; /** * The console command description. @@ -90,7 +90,7 @@ protected function copyStubs(): void } /** - * Set the initial cypress.config.cjs configuration for the project. + * Set the initial cypress.config.js configuration for the project. */ protected function createCypressConfig(): void { @@ -118,7 +118,7 @@ protected function defaultCypressConfig(array $config = []): string config('app.url'), $this->cypressPath('', false) ], - $this->files->get(__DIR__ . '/stubs/cypress.config.cjs') + $this->files->get(__DIR__ . '/stubs/cypress.config.js') ); } diff --git a/src/stubs/cypress.config.cjs b/src/stubs/cypress.config.js similarity index 87% rename from src/stubs/cypress.config.cjs rename to src/stubs/cypress.config.js index 62e724b..9db018b 100644 --- a/src/stubs/cypress.config.cjs +++ b/src/stubs/cypress.config.js @@ -1,6 +1,6 @@ -const { defineConfig } = require('cypress') +import { defineConfig } from 'cypress'; -module.exports = defineConfig({ +export default defineConfig({ chromeWebSecurity: false, retries: 2, defaultCommandTimeout: 5000, diff --git a/src/stubs/plugins/index.js b/src/stubs/plugins/index.js index 0c78445..eeeff9c 100644 --- a/src/stubs/plugins/index.js +++ b/src/stubs/plugins/index.js @@ -1,4 +1,3 @@ -/// // *********************************************************** // This example plugins/index.js can be used to load plugins // @@ -12,12 +11,14 @@ // This function is called when a project is opened or re-opened (e.g. due to // the project's config changing) +import swapEnv from './swap-env.js'; + /** * @type {Cypress.PluginConfig} */ -module.exports = (on, config) => { +export default (on, config) => { // `on` is used to hook into various events Cypress emits // `config` is the resolved Cypress config - on('task', require('./swap-env')); + on('task', swapEnv); }; diff --git a/src/stubs/plugins/swap-env.js b/src/stubs/plugins/swap-env.js index aee03e7..ee7c127 100644 --- a/src/stubs/plugins/swap-env.js +++ b/src/stubs/plugins/swap-env.js @@ -1,6 +1,6 @@ -let fs = require('fs'); +import fs from 'fs'; -module.exports = { +export default { activateCypressEnvFile() { if (fs.existsSync('.env.cypress')) { fs.renameSync('.env', '.env.backup'); From 6c8d76939b793455395429d7757ce30762542262 Mon Sep 17 00:00:00 2001 From: Chris Arter Date: Tue, 22 Aug 2023 12:55:15 -0400 Subject: [PATCH 3/3] update config stub for plugin import --- src/stubs/cypress.config.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/stubs/cypress.config.js b/src/stubs/cypress.config.js index 9db018b..1c5e3ef 100644 --- a/src/stubs/cypress.config.js +++ b/src/stubs/cypress.config.js @@ -1,4 +1,5 @@ import { defineConfig } from 'cypress'; +import plugins from './%cypressPath%/plugins/index.js'; export default defineConfig({ chromeWebSecurity: false, @@ -10,7 +11,7 @@ export default defineConfig({ fixturesFolder: '%cypressPath%/fixture', e2e: { setupNodeEvents(on, config) { - return require('./%cypressPath%/plugins/index.js')(on, config) + return plugins(on, config) }, baseUrl: '%baseUrl%', specPattern: '%cypressPath%/integration/**/*.cy.{js,jsx,ts,tsx}',