I am trying to try to add some BDD tests to this repo: https://github.com/rocket-pool/rocketpool
I've created a feature file in /test/features and a new steps file in /test/support.
The feature file looks like this:
Feature: Test
Scenario: Test Deposit Below The Minimum Amount
When A Staker Tries to Deposit Below the Minimum Amount
Then The Transaction Should Revert
The steps file complains about all the imports, which look like this :
import { printTitle } from '../_utils/formatting';
They do not include the .js extension. In order to get to this point (which I had to fight with using import vs require), I had to add "type": "module"
to the package.json file, my run command looks like this npx @cucumber/cucumber test/features/test.feature --import test/support/*.js
If I add the .js extension to the imports in my steps file, it will then complain about all the imports in other files in the project. I do not want to change all of them to use .js, and I would like to just be able to be able to keep the changes to a minimum. I have looked into webpack and babel, but there are several config files included in the node_modules for these packages so I am not sure which ones to modify, or even if that will help me in this case. It appears I am in commonjs/esm hell and I have very little experience with JavaScript.
Edit: Tried this:
node --experimental-specifier-resolution=node npx @cucumber/cucumber test/features/*.feature --import test/support/*.js
Now get this error
Running command: node --experimental-specifier-resolution=node npx @cucumber/cucumber test/features/.feature --import test/support/.js --name "Test Deposit Below The Minimum Amount"
(node:7504) ExperimentalWarning: The Node.js specifier resolution flag is experimental. It could change or be removed at any time.
(Use node --trace-warnings ...
to show where the warning was created)
node:internal/errors:490
ErrorCaptureStackTrace(err);
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/c:/Users/_/git/rocketpool/npx' imported from c:\Users_\git\rocketpool
at new NodeError (node:internal/errors:399:5)
at finalizeResolution (node:internal/modules/esm/resolve:308:15)
at moduleResolve (node:internal/modules/esm/resolve:945:10)
at defaultResolve (node:internal/modules/esm/resolve:1153:11)
at nextResolve (node:internal/modules/esm/loader:163:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
at ESMLoader.import (node:internal/modules/esm/loader:525:22)
at node:internal/modules/run_main:58:28
at loadESM (node:internal/process/esm_loader:91:11) {
code: 'ERR_MODULE_NOT_FOUND
}
Node.js v18.16.0
ERROR: Command exited with status code 1.`
This exception Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/c:/Users/_/git/rocketpool/npx'
is being returned, because the npx
command is being interpreted as a module name, hence the ERR_MODULE_NOT_FOUND
.
Set the NODE_OPTIONS
environment variable with the --experimental-specifier-resolution=node
flag to enable the experimental specifier resolution feature
export NODE_OPTIONS="--experimental-specifier-resolution=node"
Setting NODE_OPTIONS
this way, will ensure Node.js uses the experimental specifier for all subsequent executions in the same terminal session
Then run the Cucumber command separately:
npx @cucumber/cucumber test/features/*.feature --import test/support/*.js
npx
, so it locate the installed version from node_modules
dir.feature
extn.js
extnCombining all the above, should allow the experimental-specifier-resolution
to import the JavaScript files without the .js extension
Remember, if you open a new terminal session, you'll need to set NODE_OPTIONS again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With