|
1 | 1 | # Cypress dotenv |
2 | 2 |
|
3 | | -Cypress plugin that enables compatability with [dotenv](https://www.npmjs.com/package/dotenv). |
| 3 | +Cypress plugin that enables compatibility with [dotenv](https://www.npmjs.com/package/dotenv). |
| 4 | + |
| 5 | +> [!NOTE] |
| 6 | +> If you need support for Cypress v9 or below, please use [v2.x of this plugin](https://github.com/morficus/cypress-dotenv/tree/v2.0.2) |
| 7 | +
|
4 | 8 |
|
5 | 9 | [](https://travis-ci.org/morficus/cypress-dotenv) |
6 | 10 | [](https://codeclimate.com/github/morficus/cypress-dotenv/maintainability) |
@@ -35,41 +39,33 @@ yarn add --dev dotenv cypress-dotenv |
35 | 39 |
|
36 | 40 | ## Configure |
37 | 41 |
|
38 | | -Cypress (< 10.0.0) |
39 | | - |
40 | | -Since this is a plugin, you will need to modify your file `cypress/plugins/index.js` to look something like this: |
41 | | - |
42 | | -```javascript |
43 | | -const dotenvPlugin = require('cypress-dotenv'); |
44 | | -module.exports = (on, config) => { |
45 | | - config = dotenvPlugin(config) |
46 | | - return config |
47 | | -} |
48 | | -``` |
| 42 | +Version 3.x of this plugin only supports Cypress v10+. For instructions on how to set up this plugin with older versions of Cypress, please refer to the [v2.x README](https://github.com/morficus/cypress-dotenv/tree/v2.0.2?tab=readme-ov-file#configure) |
49 | 43 |
|
50 | | -Cypress (>= 10.0.0) |
51 | 44 |
|
52 | | -According to [Migration Guide](https://docs.cypress.io/guides/references/migration-guide#Plugins-File-Removed): |
53 | | -The setupNodeEvents() config option is functionally equivalent to the function exported from the plugins file |
| 45 | +Since this is a plugin, you will need to modify your `cypress.config.js` to look something like this |
54 | 46 |
|
55 | | -```javascript |
| 47 | +```typescript |
56 | 48 | import { defineConfig } from 'cypress' |
57 | 49 | import dotenvPlugin from 'cypress-dotenv' |
58 | 50 |
|
59 | 51 | export default defineConfig({ |
60 | | - e2e: { |
61 | | - ... |
62 | | - setupNodeEvents(on, config) { |
63 | | - return dotenvPlugin(config) |
64 | | - }, |
| 52 | + e2e: { |
| 53 | + ... |
| 54 | + setupNodeEvents(on, config) { |
| 55 | + const updatedConfig = dotenvPlugin(config, null, true) |
| 56 | + // continue loading other plugins |
| 57 | + return updatedConfig |
| 58 | + }, |
65 | 59 | }, |
66 | 60 | ... |
67 | 61 | }) |
68 | 62 | ``` |
69 | 63 |
|
70 | | -## Options |
71 | | -This plugin takes three paramaters. The first parameter (which is mandatory) is the Cypress config object. |
72 | 64 |
|
73 | | -The second is an optional [dotenv](https://www.npmjs.com/package/dotenv#config) config object. |
74 | 65 |
|
75 | | -The third is an optional [all] boolean parameter, which is set to false by default. If set to true, it returns all available environmental variables, not limited to those prefixed with CYPRESS_. |
| 66 | +## Options |
| 67 | +This plugin takes three parameters: |
| 68 | + |
| 69 | +1. The first parameter (which is mandatory) is the Cypress config object. |
| 70 | +1. The second is an optional [dotenv](https://www.npmjs.com/package/dotenv#config) config object. |
| 71 | +1. The third (called `all`) is an optional boolean parameter, which is set to false by default. If set to true, it returns all available environmental variables, not limited to those prefixed with CYPRESS_. |
0 commit comments