Cypress is unable to retrieve variables stored in the process.env file

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');

Answer №1

For the dotenv library to function correctly, the filename must be precisely named as .env.

Once this file is in place, it will proceed to inject environment variables into the process.env object.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue encountered while attempting to launch Angular2 project

Having trouble running my Angular2 project, every time I try to use the ng serve command I get an error: Here is the link: https://i.sstatic.net/SYENX.png I've installed angular 2 using angular-cli with the following steps: 1. sudo npm install -g ...

The issue of NestJS dependency injection not working within the MongooseModule.forFeatureAsync function call has been encountered

I'm having an issue setting up a pre-save hook on my User model. Here's the code snippet from my users.module.ts: @Module({ controllers: [ UsersController, ], exports: [ UsersService, ], providers: [ UsersService, ], imp ...

Is there a way to replace top-level environment variables with lower-level ones in a GitHub Actions .yml file?

I have encountered an issue with a .yml file in my CI/CD pipeline on Github Actions. I defined an env variable at the job level, and then attempted to reset it at the step level for a single step. However, the environment variable at the step level does no ...

Having difficulty invoking the forEach function on an Array in TypeScript

I'm currently working with a class that contains an array of objects. export interface Filter { sf?: Array<{ key: string, value: string }>; } In my attempt to loop through and print out the value of each object inside the array using the forE ...

When the add button in Angular is clicked, I would like the summary section, item name, and price to be updated accordingly

How can I dynamically update the summary section with the item name and price every time I click on add without removing the previous entries? booking.component.html <table class="container table table-striped table-hover"> <thead&g ...

Expecting a return value from CreateAsyncThunk

I need help converting the following JavaScript code to TypeScript. I keep running into an error message that says Expected to return a value at the end of async arrow function. Can someone help me figure out what's wrong with this code? export const ...

When ts-loader is used to import .json files, the declaration files are outputted into a separate

I've encountered a peculiar issue with my ts-loader. When I import a *.json file from node_modules, the declaration files are being generated in a subfolder within dist/ instead of directly in the dist/ folder as expected. Here is the structure of my ...

Create an array variable for services in Angular

My goal is to define this user as an array. users = new BehaviorSubject<any>([]); In my component, I am attempting to add the userID to the array. this.Service.users.push(userID); To subscribe to it, I use the following code: this.Service.users.su ...

Pause for Progress - Angular 6

I'm looking for a solution to solve the following issue. I need to access a property that will store data from an http request. Therefore, I want to verify this property only after the transaction is completed. validateAuthorization(path: string): ...

Mongoose fails to add an object to an array

I am facing an issue with my express application where comments are not being inserted into posts. Even though there are no errors displayed, the comments are not being added when posting via Postman. I have tried various solutions like this and this, but ...

Vee-Validate: Are flags on the field value yielding undefined results? Explained with TypeScript

The documentation states that by using a flag on the value of a field, I should be able to obtain a boolean. For example: computed: { isFormDirty() { return Object.keys(this.fields).some(key => this.fields[key].dirty); } }, I am working ...

Recording the details of an Angular project through the utilization of Compodoc

I am currently in the process of documenting my Angular + Typescript application using Compodoc. To install Compodoc, I utilized npm and executed the following command: 'npm install -g compodoc'. And included "compodoc": "./node_modules/ ...

Exploring PrimeNG's method for expanding and collapsing groups

I'm attempting to incorporate two buttons that can be used to either expand or collapse all the groups in my code utilizing primeNG. Below is the functioning code: PLUNKER <p-dataTable [value]="data" sortField="room" rowGroupMode="subheader" grou ...

Using Typescript, pass a Sequelize model as a property in NodeJS

Currently in the midst of a project using Node, Typescript, and Sequelize. I'm working on defining a generic controller that needs to have specific functionality: class Controller { Schema: <Sequelize-Model>; constructor(schema: <Sequel ...

The rule result is invalid due to the occurrence of the Function()

As I proceed with the upgrade from angular 6 to angular 7, I am diligently following the guidelines provided on the official Angular website. Upon executing the command to update angular/cli and core for version 7: $ ng update @angular/cli@v7 @angular/c ...

Error code TS2749 is indicating that the identifier 'XXX' is being interpreted as a value instead of a type. Perhaps you intended to use 'typeof XXX' instead

I've encountered a strange issue while running my npm run dev command in my project built with Nuxt.js, which includes Vue.js components. While launching the application, I'm encountering errors related to TypeScript like TS2749: 'About&apos ...

Angular 2: The linting error shows up as "Anticipated operands need to be of the same type or any"

So, I have this shared service file where a variable is defined like so: export class SharedService { activeModal: String; } Then, in my component file, I import the service and define it as follows: constructor(public sharedService: SharedService) ...

Unable to invoke a function in TypeScript from a Kendo template within the Kendo TreeList component

In my TypeScript file for class A, I am encountering an issue with the Kendo TreeList code. I am trying to call a function from the Kendo template. export class A{ drillDownDataSource: any; constructor() { this.GetStatutoryIncomeGrid ...

Enable the use of unfamiliar techniques on object

I am facing a challenge with an object that contains multiple method names which are not known at compile time. The signature of these methods always remains the same, but I am unsure about how to handle this scenario. I attempted to utilize an index type ...

Issue - PerfectScrollbar : Unable to call a function on a type without a defined call signature. The data type 'Number' does not have any suitable call signatures

The following code is running smoothly:- $(".info).scrollTop(0); However, the equivalent code below is encountering an error:- let ele : HTMLElement = document.querySelector('.info'); ele.scrollTop(0); <---- Error Error: - Error - Perf ...