I am encountering an issue with retrieving variable values from the process.env file in my Cypress test. I have followed the instructions provided here: https://docs.cypress.io/guides/guides/environment-variables#Option-5-Plugins. However, I keep getting an undefined error when attempting to use variables from the process env file.
This is my index.js file:
const { preprocessTypescript } = require('@nrwl/cypress/plugins/preprocessor');
require('dotenv').config();
module.exports = (on, config) => {
on('file:preprocessor', preprocessTypescript(config));
[
'DB_USER',
'DB_PASS',
'DB_SNOWFLAKE_ACCOUNT',
'DB_SNOWFLAKE_DATABASE',
'DB_SNOWFLAKE_ROLE',
'DB_SNOWFLAKE_SCHEMA',
'DB_SNOWFLAKE_WAREHOUSE'
].forEach(v => {
config.env[v] = process.env[v];
});
return config;
};
The process.env file can be found in the root folder.
DB_SNOWFLAKE_ACCOUNT=www.xyz.com
DB_USER=xyzxyz
DB_PASS=xyzxyzxyz
DB_SNOWFLAKE_DATABASE=XYZX
Furthermore, this is the content of my test.spec.ts file:
const snowflakeUrl: string = Cypress.env('DB_SNOWFLAKE_ACCOUNT');
const userName: string = Cypress.env('DB_USER');
const password: string = Cypress.env('DB_PASS');
const database: string = Cypress.env('DB_SNOWFLAKE_DATABASE');