Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble running .features file with webpack on windows #304

Closed
alastair-todd opened this issue Jan 13, 2020 · 20 comments
Closed

Trouble running .features file with webpack on windows #304

alastair-todd opened this issue Jan 13, 2020 · 20 comments

Comments

@alastair-todd
Copy link

alastair-todd commented Jan 13, 2020

I am using v1.17 with cypress 3.8.2 on windows and am having issues with

cypress run --spec **/*.features

I get

Oops...we found an error preparing this test file:

cypress\integration\All.features

The error was:

./cypress/integration/All.features
Module build failed (from ./node_modules/cypress-cucumber-preprocessor/lib/featuresLoader.js):
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
@ multi ./cypress/integration/All.features main[0]

This occurred while Cypress was compiling and bundling your test code. This is usually caused by:

  • A missing file or dependency
  • A syntax error in the file or one of its dependencies

Fix the error in your code and re-run your tests.

The project is set up with typescript.

I have created a repo for the issue.

@lgandecki lgandecki changed the title Trouble running .features file Trouble running .features file with webpack Jan 13, 2020
@lgandecki lgandecki changed the title Trouble running .features file with webpack Trouble running .features file with webpack on windows Jan 13, 2020
@lgandecki
Copy link
Collaborator

lgandecki commented Jan 13, 2020

can you give it a try with the newest version (2.0.0)? Have you tried just running our example repo?
https://github.com/TheBrainFamily/cypress-cucumber-webpack-typescript-example

it would be helpful to verify if things work/not work there.

My native platform is not windows so the more you can give me here the easier my life will be ;)

@alastair-todd
Copy link
Author

alastair-todd commented Feb 13, 2020

I forked the repo you mentioned and brought it up to date. The (new) issue is related to running cucumber in the "nonGlobal" folder style - I created an issue on that repo with a link to the fork.

@sebastiandero
Copy link

Hi! Any updates on this? Im having this exact issue when trying to make this work with Angular 9. What possible fix is there for this?

@sebastiandero
Copy link

@lgandecki Hey, this is a major issue for us, is there some way we can help?

@lgandecki
Copy link
Collaborator

Just to reiterate - running .feature works, but .features doesn't and the problem is on windows with nonGlobal structure?

@sebastiandero
Copy link

sebastiandero commented Jun 23, 2020

@lgandecki we have the issue on linux, mac and windows. We use webpack for preprocessing and receive "cannot read property split of undefined" in cypress upon running the All.features file.

our project is set-up using nrwl.io nx.

Here's our plugins/index.js

const { getWebpackConfig } = require('@nrwl/cypress/plugins/preprocessor');
const webpack = require('@cypress/webpack-preprocessor');

function preprocessTypescript(config) {
  if (!config.env.tsConfig) {
    throw new Error('Please provide an absolute path to a tsconfig.json as cypressConfig.env.tsConfig');
  }

  const webpackConfig = getWebpackConfig(config);

  webpackConfig.node = { fs: 'empty', child_process: 'empty', readline: 'empty' };

  webpackConfig.module.rules.push({
    test: /\.feature$/,
    use: [
      {
        loader: 'cypress-cucumber-preprocessor/loader',
      },
    ],
  });

  webpackConfig.module.rules.push({
    test: /\.features$/,
    use: [
      {
        loader: 'cypress-cucumber-preprocessor/lib/featuresLoader',
      },
    ],
  });

  return webpack({
    webpackOptions: webpackConfig,
  });

}

module.exports = (on, config) => {
  on('file:preprocessor', preprocessTypescript(config));
};

@alastair-todd
Copy link
Author

@lgandecki if you scroll up there's a link to a fork with a repro.

In summary, *.features is broken on Windows when using non-global steps.

@sebastiandero
Copy link

@lgandecki let me know if we can help in any way

@badeball
Copy link
Owner

@sebastiandero, can you provide an example repo which allows us to merely clone, run npm install and observe the issue?

@alastair-todd
Copy link
Author

alastair-todd commented Jun 23, 2020

@badeball
Copy link
Owner

I don't run windows and unfortunately have no ability to reproduce your issue. @sebastiandero claims to observe this across all plattforms, hence I'm asking them.

@sebastiandero
Copy link

sebastiandero commented Jun 23, 2020

@badeball @lgandecki
https://github.com/sebastiandero/cucumber-preprocessor-reproduction
this you can reproduce on linux, macos and windows.

if you change "nonGlobalStepDefinitions": true to "nonGlobalStepDefinitions": false
in .cypress-cucumber-preprocessorrc

it will work, but switching it back will break it again.

Edit: run it using ng e2e test-e2e --watch, then you can select the All.features in cypress

EDIT: here's a screenshot
image

EDIT: here's the stacktrace

cypress_runner.js:193190 TypeError: Cannot read property 'split' of undefined
    at splitStack (cypress_runner.js:170178)
    at stackWithLinesRemoved (cypress_runner.js:170230)
    at Object.stackWithReplacementMarkerLineRemoved (cypress_runner.js:170252)
    at preferredStackAndCodeFrameIndex (cypress_runner.js:165874)
    at Object.enhanceStack (cypress_runner.js:165886)
    at fail (cypress_runner.js:163036)
    at Context.runnable.fn (cypress_runner.js:163618)
    at callFn (cypress_runner.js:102437)
    at Test.../driver/node_modules/mocha/lib/runnable.js.Runnable.run (cypress_runner.js:102424)
    at cypress_runner.js:168711
    at PassThroughHandlerContext.finallyHandler (cypress_runner.js:6715)
    at PassThroughHandlerContext.tryCatcher (cypress_runner.js:10161)
    at Promise._settlePromiseFromHandler (cypress_runner.js:8096)
    at Promise._settlePromise (cypress_runner.js:8153)
    at Promise._settlePromise0 (cypress_runner.js:8198)
    at Promise._settlePromises (cypress_runner.js:8278)

@badeball
Copy link
Owner

Alright, so what's happening is that "could not clear instance from module cache" is being thrown. Since this isn't an actual error object, Cypress fails do to decorate it with whatever, which is why you're seing that somewhat cryptic error message.

I guess the method used for invalidating the browserify module cache doesn't quite work with webpack, which doesn't come as a huge surprise, really. Did this ever work and is the case now that it doesn't work with the most recent version?

@sebastiandero
Copy link

@badeball we have only started using the preprocessor two months ago, and we have always had this issue

@lgandecki
Copy link
Collaborator

lgandecki commented Jun 23, 2020

I think @badeball is right, this is where it throws:

https://github.com/TheBrainFamily/cypress-cucumber-preprocessor/blob/master/lib/featuresLoader.js#L38

( and it should be an error not string, indeed but that won't fix anything - besides being less cryptic. )
To make this work we would need another way to clear the cache in webpack, in this function (so some "if" to check whether we are in webpack or browserify, and then remove things from cache):

https://github.com/TheBrainFamily/cypress-cucumber-preprocessor/blob/master/lib/featuresLoader.js#L28-L39

What actually happens here I believe is we need to make sure that importing the same file twice runs it's side effects, instead of just getting the cached export otherwise if you use the same file in nonGlobal feature things are not working right. It'd be easy to test by making that clearFromCache function empty and seeing how webpack behaves - maybe things will just work? (although I doubt it)

@sebastiandero is this something you are able to research? :) Or is this too low level?

@sebastiandero
Copy link

@lgandecki I will do my best

@badeball
Copy link
Owner

Does this work and if so, maybe it can be done conditionally based on whether require.cache exist or not?

@sebastiandero
Copy link

@lgandecki @badeball @alastair-todd Hi, it took me a while to get some time, seems like webpack behaves correctly without explicitly deleting the cache, here's the PR -> #404

@sebastiandero
Copy link

@alastair-todd please try again with the most recent version, should be fixed.

@soujanya1511
Copy link

we still have this issue while trying to run .feature file in cypress:6.3.0
Can any one please suggest what to do to fix it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants