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 ...