Is it possible for Cypress to execute test files that are imported from outside of the Cypress folder

Currently, I am developing an E2E test framework using Cypress and encountered an issue while trying to import spec files from locations outside the traditional Cypress directory structure (which includes directories for fixtures, integration, plugins, and support). During initial testing to ensure everything worked correctly, I faced error messages indicating that the problem lay within my test code rather than Cypress itself. The specific error was a TypeError stating:

Cannot read property 'includes' of undefined
.

Despite conducting multiple internet searches, I could not find a solution as this problem seemed unique to my situation. Even after relocating the spec file I attempted to import into the cypress/integration/ directory, the same error persisted.

I am currently at a loss regarding the root cause of this issue and how to resolve it. Is there something crucial I may be overlooking?

Below is an excerpt from my package.json file showing the devDependencies and main field:

"main":"index.js",
"devDependencies": {
"@cypress/webpack-preprocessor": "^5.4.1",
"cypress": "^4.9.0",
"selenium-webdriver": "^4.0.0-alpha.7",
"webpack": "^4.43.0"
}

The specific spec where I attempt to import a file located outside the Cypress directory (

cypress/integration/RunE2ETest.spec.js
):

import '../../Cypress_E2E_Example/SteamHeader.spec';

The external spec file (SteamHeader.spec) exemplifies how it is structured with imports and exports:

import '../Cypress-E2E/BaseTest';

export default describe('Test Suite for ....' () => {
     it('test example'), () => {
     }
}

Furthermore, here is the base test file:

import default before('BaseSetup', () => {
     cy.visit('/');
}

Error Details: The line causing the error in node_modules/global-dirs/index.js reads as follows:

26 | 
  27 |  // Homebrew special case: `$(brew --prefix)/lib/node_modules/npm/npmrc`
> 28 |  if (process.execPath.includes('/Cellar/node')) {
     | ^
  29 |      const homebrewPrefix = process.execPath.slice(0, process.execPath.indexOf('/Cellar/node'));
  30 |      return path.join(homebrewPrefix, '/lib/node_modules/npm/npmrc');
  31 |  }

Stacktrace:

We dynamically generated a new test to display this failure.
      at getGlobalNpmrc (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:86028:23)
      at getNpmPrefix (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:86064:30)
      ... more stack trace lines follow ...

Answer №1

Encountered a similar issue ourselves. The error was triggered by importing the cypress module. It seems like this module is not meant to be imported in files that are executed within the browser.

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

What are some ways I can improve the readability of this if-else function in Javascript ES6?

As a newcomer to React development, I am currently in the process of tidying up my code. One issue that I am facing is how to deal with a particular function while minimizing the use of if-else statements. const calculatePerPage = () => { if ...

What is the best method for retrieving the character's ID from within an object?

Exploring my collection of movies, I discovered that each movie contains an array of characters. My goal is to display specific information about each character (such as their name and age) when clicked on, requiring me to obtain the id of each character. ...

The JavaScript code is not executing properly within the HTML document

I am trying to execute a function from my JavaScript file in my HTML page. Here is the code snippet: index.html <!DOCTYPE html> <html><body> <h2>Web1</h2> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jq ...

What is the best way to conceal a ModalPopupExtender that is integrated into an ASCX user control without triggering a postback, utilizing JavaScript?

I am currently working on an Asp.net application and have encountered an issue with the ModalPopupExtender embedded within an ASCX user control. I am trying to set up a cancel button that will hide the popup without triggering a post back when clicked. He ...

What is the process for choosing a specific id from a JSON structure?

Is there a way to extract specific data from a JSON format within an Ionic project? What is the process for selecting the ID associated with particular data in a JSON format? And how can I retrieve and display the value linked to the selected product&apos ...

Create a roster of individuals who responded to a particular message

Can a roster be created of individuals who responded to a specific message in Discord? Message ID : '315274607072378891' Channel : '846414975156092979' Reaction : ✅ The following code will run: bot.on("ready", async () = ...

Incorporate a JavaScript message using C# code in the backend

I am looking for a code snippet to execute a JavaScript function called recordInserted() that displays an alert, within the add_Click method in my code-behind file. Here is the relevant section of my code: protected void add_Click(object sender, EventArgs ...

Performance issues with Datatables server side processing

Utilizing Datatables server-side processing with PHP, JQuery, Ajax, and SQL Server database, I encountered slow performance in features such as pagination and search. Despite working with moderate data, there is a delay of over 40 seconds when using the se ...

Data from AngularFire not displaying in my list application

While going through tutorials on the Angular website, I encountered a roadblock while attempting to create a list that utilizes Firebase for data storage. Strangely, everything seems to be functional on the Angular site, but clicking on the "Edit Me" link ...

The Material UI slider vanishes the moment I drag it towards the initial element

After moving the Material UI Slider to the initial position, it suddenly vanishes. via GIPHY I've spent 5 hours attempting to locate the source of the issue but have not had any success. ...

Trouble with bringing in the solana/web3.js library

After successfully importing the solana/web3.js package and running it within a NodeJS file, everything was working fine. However, things took a turn when attempting to connect this file with basic HTML, resulting in an error being thrown. import { Tra ...

Utilizing AMAZON_COGNITO_USER_POOLS in conjunction with apollo-client: A comprehensive guide

Struggling to populate my jwtToken with the latest @aws-amplify packages, facing some challenges. Encountering an error when attempting to run a Query: Uncaught (in promise) No current user It seems that when using auth type AMAZON_COGNITO_USER_POOLS, I ...

What is the best way to create titles with a background?

My goal is to have a title overlay an image with specific width and the text displayed in blocks. To better illustrate, here's an example: I prefer to achieve this effect using CSS; however, I am open to utilizing Javascript if needed. ...

steps to remove the border of the select box in MUI component

i am struggling to disable the border on the select box and change the color of the label text when focused or blurred i have attempted it but have been unsuccessful i am not very skilled at Mui component customization this is the image that i desire ht ...

Firefox won't trigger the `beforeunload` event unless I interact with the webpage by clicking on it

In my quest to handle the beforeunload event in Firefox, I've encountered a small hurdle. It seems to be working smoothly, but only if the user physically interacts with the page by clicking on it or entering text into an input field. Below is the co ...

Equal size images displayed within cards in Material UI

Is there a way to create a list of Material UI components with images that have uniform height, even if the original images vary in size? I want to make all image heights responsive and consistent across all cards. Any suggestions on how to achieve this? ...

The code functions properly on a standalone device, however, it encounters issues when

I am facing an issue with my JavaScript code. It works perfectly fine when I run it on my local machine, but once I upload it to the server, it only functions properly after I refresh the page. Below is the code in question. Please do not hesitate to rea ...

What's the best way to determine which of the two forms has been submitted in Django?

On my homepage, I have both a log_in and sign_up form. Initially, the log_in form is displayed by default, but when a user clicks on the Sign Up button, the sign_up form appears. These toggles switch depending on which button the user clicks. from django ...

Interfacing Highcharts with Angular for seamless data binding across series

I am fairly new to using highcharts and I am having difficulty binding my data into the series parameter. In my controller, I have an array of objects that I want to display (when I use console.log, I can see that they are all properly there) this.plotDa ...

Using Express and Node.js to implement the Google Maps API

Currently working on creating a simple web application using the Google Maps API with express/node. At the moment, I have three main files that make up my project: server.js const express = require('express'); const bodyParser = require(' ...