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

Question: npx bddgen is not getting exited properly. #197

Open
dpjp opened this issue Jul 31, 2024 · 15 comments
Open

Question: npx bddgen is not getting exited properly. #197

dpjp opened this issue Jul 31, 2024 · 15 comments
Labels
question Further information is requested

Comments

@dpjp
Copy link

dpjp commented Jul 31, 2024

Hi @vitalets - Good Day. Am trying to execute the npx bddgen with the below version. I see that the features-gen folder is successfully created with test *.spec.js files, but the process is not getting exited properly. Not sure what causes this problem. In local am able to do "Ctrl + C" and continue with my execution. But in pipeline, this particular step npx bddgen is taking longer time and its not getting exited. Also, tried debugging with nodemon mentioned in the documentation, still no luck. Can you help me here how can I fix this issue ?
Attached is the screenshot for your reference.

Please let me know if you need any other information.
pw-npx-bddgen-ExitIssue

Note: tried clearing npm cache, uninstall and reinstall playwright-bdd,

@dpjp dpjp added the question Further information is requested label Jul 31, 2024
@vitalets
Copy link
Owner

Hi @dpjp !

  1. Could you run locally npx bddgen --verbose and share the output?
  2. Could you clone playwright-bdd-example and run npx bddgen there?

@dpjp
Copy link
Author

dpjp commented Aug 1, 2024

Hi @vitalets ,

I tried the above commands. The npx bddgen works fine in the playwright-bdd-example project. And also, observed that the issue was causing because of aspose.cells nodejs via java npm package. Am using this package in my project for excel manipulations.

Aspose.cells npm package
https://www.npmjs.com/package/aspose.cells

If I have aspose.cells installed in my project, the npx bddgen is not exiting properly. But after uninstalling the aspose.cells, I see that the npx bddgen seems to be working fine.
Aspose,cells is must library for my project as we deal with different excel templates. It would be great if you could help me with a work around.

Attached the screenshot for your reference.
Pw-npxbddgen-verbose

@vitalets
Copy link
Owner

vitalets commented Aug 1, 2024

I've tried to install aspose.cells but getting an error (osx, m1):

> npm i aspose.cells

...
../src/java.h:7:10: fatal error: 'jni.h' file not found

But I see in readme they highly recommend to migrate to Aspose.Cells for Node.js via C++. I've checked - it installs correctly and npx bddgen works.
Could try with it?
Looks like support for aspose.cells will be dropped anyway in future.

@dpjp
Copy link
Author

dpjp commented Aug 15, 2024

Hi @vitalets @VitaliyPotapov - For the past few days, I had been following up on this with aspose.cells support and my project engineering team. Due to security concerns and performance issues, I will not be able to use aspose.cells for Node.js via c++ as they set license using a file and cannot have the license file in shared repository, whereas, for nodejs via java we use metered license and we can store the keys in secrets. Also, aspose support team confirmed that they will be supporting this aspose.cells for nodejs via Java in the future and dont have any plans to retire/deprecate it. So I think we have only this option(use aspose.cells for nodejs via Java) to go with.

Aspose support ticket reference: https://forum.aspose.com/t/aspose-cells-node-version-24-7-npm-library/288564

Issue Description:
I can say exactly when this npx bddgen is not exiting properly.

I was able to do npm install for aspose.cells and Java.
I installed Java JDK(v22) in my machine.

After the above installation steps, npx bddgen works fine.

In order to use the aspose.cells for nodejs via java in my office laptop, I am forced to set the certificate in Java bin folder using keytool command as mentioned below

"keytool -import -trustcacerts -file /ca-certificatename -alias custom-Root-CA -keystore ..\jre\lib\security\cacerts"

Only after setting the certificate, am facing this issue.(npx bddgen is not exiting properly).

Note: Only after installing the certificate, the system will allow to set aspose.cells license and my code works fine.

Can you help me if you have any workaround / solution towards this ?

@vitalets
Copy link
Owner

Hey @dpjp
Such issue is very difficult to reproduce.

Lets try the following:

  1. When you run pure Playwright tests, do es it exit correctly with and without installed certs?
  2. Try to run this command with and without installed certs, to check what causes node to hang (uses this module):
    npx why-is-node-running node_modules/playwright-bdd/dist/cli/index.js --verbose
    

@dpjp
Copy link
Author

dpjp commented Aug 15, 2024

Hi @vitalets, @VitaliyPotapov - Sorry.. Ignore my last post. I see the issue is in the below lines. In one of my .ts class,
am importing the aspose.cells using the below lines.

var aspose:any = aspose || {};
aspose.cells= require("aspose.cells");

npx_bddgen_rootcause_AsposeCells

The same code works with playwright test runner(excluded playwright-bdd). Do you have any work around for this ?

@vitalets
Copy link
Owner

If you just run the following file with node, does it exit properly?

// file.js
var aspose = aspose || {};
aspose.cells= require("aspose.cells");

Run:

node file.js

@dpjp
Copy link
Author

dpjp commented Aug 16, 2024

@vitalets - When executed the above code, I see that its not exiting.

image

But when executing the same code with playwright test runner, am not seeing any issue.

image

@vitalets
Copy link
Owner

Ok. Then please try this command, to get the exact reason of hanging:

npx why-is-node-running file.js

Also, haven't you open an issue in aspose forum? Because hanging of require("aspose.cells"); looks like a more general issue than related to playwright-bdd.

In Playwright it exists, because Playwright internally calls process.exit() to force exiting.

@dpjp
Copy link
Author

dpjp commented Aug 20, 2024

Hi @vitalets - I tried running this command 'npx why-is-node-running file.js' and I see the below error.

image

Also, Yes, I did posted in the aspose.cells forum and I got the below response and still no luck.
image

Is there any work around using this command ?
var java = require("java");
java.callStaticMethodSync('java.lang.System', 'exit', 0);

@vitalets
Copy link
Owner

Then we can try to wrap the call of bddgen and force exit when files are generated:
// bddgen.cjs

const { spawn } = require('node:child_process');
const child = spawn('./node_modules/.bin/bddgen', ['--verbose']); // for windows there can be bddgen.bat

child.stdout.on('data', (data) => {
    console.log(`stdout: ${data}`);
    if (data.includes('Generating Playwright tests')) {
        setTimeout(() => child.kill(), 2000);
    }
});

And run it:

node bddgen.cjs

Let me know, does it work?

Note:
Now it uses timeout for 2000 ms.
This could be improved in the next version of pw-bdd, I will add a string Done. as a final output to let child process know that files are generated.

@dpjp
Copy link
Author

dpjp commented Aug 26, 2024

Hi @vitalets - Am I doing anything wrong here? Tried executing the same. I get the below error and says that its unable to locate the executable.

image

Also, in the bin folder under node modules, I see the below files.

image

@vitalets
Copy link
Owner

Hi @dpjp
Could you try with const child = spawn('./node_modules/.bin/bddgen.cmd', ['--verbose']);

@dpjp
Copy link
Author

dpjp commented Aug 27, 2024

Hi @vitalets - Yes. I did try the same previously for .cmd and .ps1. I was getting the below error.

image

Also, wanted to check on the below. I had generated the steps definitions for the steps(in screenshot). But still it says undefined steps and when pressed "F12" from the feature file, Its not navigating to the corresponding step definition. I tried setting the cucumber. Glue in settings.json file as well.

image

@vitalets
Copy link
Owner

I did try the same previously for .cmd and .ps1. I was getting the below error.

I'm not on windows, so tried to ask chatgpt to check, that's the suggested code:

const { spawn } = require('child_process');
const path = require('path');

// Assuming `bddgen` is installed as a dependency in your project
const bddgenPath = path.resolve(__dirname, 'node_modules', '.bin', 'bddgen');

const child = spawn(bddgenPath, ['--verbose'], {
  stdio: 'inherit',  // This option will output the child process logs in the parent process
  shell: true        // Helps with path resolution on Windows
});

child.on('error', (err) => {
  console.error('Failed to start subprocess:', err);
});

child.on('close', (code) => {
  console.log(`Child process exited with code ${code}`);
});

Please try with it.

Also, wanted to check on the below...

Lets track it in a separate issue. Please share project structure or try to reproduce it based on https://github.com/vitalets/playwright-bdd-example

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

No branches or pull requests

2 participants