3
votes

I'm working on an E2E test framework using Cypress, and wanted to import spec files which are outside the Cypress directory (containing dir for: fixtures, integration, plugins, support). When I started some initial tests to verify if it would work as expected, I get these error messages stating that the error originate from my test code, not Cypress. The cause of the error is a TypeError stating: Cannot read property 'includes' of undefined.

Internet searches on this issue weren't really helpful, since no else seemed to have trouble with this behavior, (at least from my perspective). Even when I moved the spec file I selected as an import into cypress/integration/, the same issue repros.

At this point I'm stumped at what's the cause of this problem and how to resolve it. Is there something I'm missing?

Here is what I got in package.json (devDependencies, and field for main):

"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"
}

My spec which imports spec file outside of Cypress directory (cypress/integration/RunE2ETest.spec.js):

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

The spec file outside of Cypress folder (SteamHeader.spec) just showing how I have it set with imports, exports:

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

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

The file for my BaseTest:

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

Details on error: Line causing the error (node_modules/global-dirs/index.js:28:1):

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)
      at Object.eval (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:86072:32)
      at Object.512._process (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:86120:4)
      at o (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:1:265)
      at eval (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:1:316)
      at Object.eval (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:89116:20)
      at Object.551.fs (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:89130:4)
      at o (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:1:265)
      at eval (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:1:316)
      at Object.eval (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:70417:28)
      at Object.425../fs (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:70842:4)
      at o (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:1:265)
      at eval (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:1:316)
      at Object.eval (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:67474:12)
      at Object.411../lib/cypress (https://store.steampowered.com/__cypress/tests?p=cypress\integration\RunE2ETest.spec.js:67503:4)
1

1 Answers

1
votes

We experienced the same error. It was caused by an import of the cypress module. I guess this module is not intended to be imported in files which are loaded in the browser.