In my Playwright test, I am trying to run a cucumber feature using npm run cucumber --profile dev, however no scenarios are being picked up:
Here is my index.ts file:
const common = `./src/features/**/*.feature \
--require-module ts-node/register \
--require ./src/step-definitions/**/**/*.ts \
-f json:./reports/report.json \
--format progress-bar `;
const dev = `${common} --tags '#dev'`;
const smoke = `${common} --tags '#smoke'`;
const regression = `${common} --tags '#regression'`;
export { dev, smoke, regression }
And here is my folder structure as that may be useful:
Also, my home-page.feature file:
Feature: As a user I expect to be able to navigate to the home page
#dev
#regression
Scenario: As a user I expect to be able to see contacts
Given I am on the 'home' page
Then the 'contacts header' should contain the text 'Contacts'
And my package.json:
{
"name": "personalised-offers-platform-e2e-pw",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"transpile": "rimraf dist && babel --extensions .ts --out-dir dist src",
"cucumber": "npm run transpile && cucumber-js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"#babel/cli": "^7.18.9",
"#babel/preset-env": "^7.18.9",
"#babel/preset-typescript": "^7.18.6",
"#cucumber/cucumber": "^8.5.0",
"#playwright/test": "^1.23.4",
"playwright": "^1.23.4",
"ts-node": "^10.9.1",
"typescript": "^4.7.4"
}
}
I have tried running just npm run cucumber to see if the tags were the issue, but it gives the same output as above.
Originally, I thought the problem was with the common paths in my index.ts, as the feature wasn't being picked up, but they look OK to me now.
Can someone please explain what I'm doing wrong, & how I can fix it?
I can provide further code to help shed some light on the issue.
Try with "cucumber" option -p or --profile:
npm run transpile && cucumber-js -p
Related
Problem
When trying to build my bundle.js file, I get the following:
Error: Can't walk dependency graph: ENOENT: no such file or directory, lstat 'C:\[filepath&filename]\stream'
required by C:\[filepath]\script.js
My package.json file is as follows:
{
"name": "[projectName]",
"version": "1.0.0",
"description": "",
"main": "script.js",
"scripts": {
"build": "browserify script.js -o bundle.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"browserify": "^17.0.0",
"crypto-js": "^4.1.1",
"stream-consumers": "^1.0.2"
}
}
High level, the code I'm trying to run is as follows:
var CryptoJS = require('crypto-js');
const { json } = require('stream/consumers');
function doSomething() {
}
doSomething();
What I've tried
I've tried a number of different recommended ways to fix this, including:
Adding './' - as recommended here which gives 'Cannot find module'
Deleting package-lock.json file and then installing the packages I wanted to install - as recommended here
This unblocked the issue for me.
It turned out that:
const { json } = require('stream/consumers');
wasn't required, so when I commented it out, it seemed to resolve the issue...
hope you doing great.
I just tried using babel and webpack but for some reason it doesn't work.
I even bought a new computer but no change...
Every time I start running the webpack command (node_modules/.bin/webpack). I am getting the error:
C:\node_modules doesn't exist or is not a directory
The same happens when I using babel without webpack:
The "node_modules" command is either misspelled or
could not be found.
(I am calling a start script from package.json file here - node_modules/.bin/babel ./src/index.js -o ./dist/assets/bundle.js)
The path clearly exsists on my computer.
Also I checked several times that I am in the correct folder in my terminal...
My package.json file looks like this:
{
"name": "chapter_19",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"babel": "node_modules/.bin/babel ./src/index.js -o ./dist/assets/bundle.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"#babel/cli": "^7.2.3",
"#babel/core": "^7.3.4",
"#babel/preset-env": "^7.3.4"
},
"dependencies": {
"webpack": "^5.72.1",
"webpack-cli": "^4.9.2"
}
}
Here's my webpack file:
const path = require('path');
module.exports = {
entry:':/src/index.js',
output:{
path: path.resolve(__dirname, 'dist/assets'),
filename: 'bundle.js'
}
}
And my files/folders
image
Does someome maybe what's going on here?
Help would be greatly greatly appreciated.Thanks.
I'm having a problem making a unitary test with jest over an es6 class. I don't know if the configurations were made properly or if I need some extra package.
This is my file queue.js
export default class Queue {
constructor() {
...
}
//Adds a new elemnt to the queue
method1(element) {
...
}
.
.
.
}
This is my test file
import Queue from "../src/queue";
const myQueue = new Queue();
describe("Queue", () => {
...
...
...
});
This is my .babelrc file
{
"presets": ["es2015"]
}
This is my package.json file. The clean, build and production scripts run all ok, but when I try to run the test, then an error is thrown.
{
"name": "queue",
"version": "1.0.0",
"description": "An implementation of a queue data structure",
"main": "queue.js",
"scripts": {
"test": "jest",
"clean": "rm -dr dist",
"build": "npm run clean && mkdir dist && babel src -s -d dist",
"production": "npm run build && node bin/production"
},
"author": "Osiris Román",
"license": "ISC",
"jest": {
"transform": {
"^.+\\.js$": "babel-jest"
}
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-jest": "^25.4.0",
"babel-preset-es2015": "^6.24.1",
"babel-register": "^6.26.0",
"jest": "^25.3.0"
}
}
This is the error:
Plugin/Preset files are not allowed to export objects, only functions. In /home/usuario/practicing/javascript/queue/node_modules/babel-preset-es2015/lib/index.js
Does someone know how can I solve this problem?
The error you are getting means that one of your presets isn't compatible with the babel version.
Looking at your package.json you are using babel version 6. But both jest and babel-jest use later versions of babel. This causes your es2015 preset not to work correctly.
If you are tied to your current version of babel you can downgrade your jest and babel-jest dependencies to a version that uses older versions of babel:
npm uninstall --save-dev babel-jest jest
npm install --save-dev babel-jest#23.6.0 jest#23.6.0
If not, I would recommend to upgrade your babel version (babel-cli, babel-register and babel-preset-es2015 packages) to newer versions.
If you follow this second path, note that babel-preset-es2015 is deprecated and the use of #babel/preset-env is recommended instead.
I finally found how to solve the problem. I'll share here the configuration If someone else is having the same problem.
This is my file queue.js
export default class Queue {
constructor() {
...
}
//Adds a new elemnt to the queue
method1(element) {
...
}
.
.
.
}
This is my test file
import Queue from "../src/queue";
const myQueue = new Queue();
describe("Queue", () => {
...
...
...
});
I decided to use babel.config.js file insted of .babelrc file. This is the content of this new file.
module.exports = {
presets: [["#babel/preset-env", { targets: { node: "current" } }]],
};
This is my package.json file. The clean, build, dev, production and test scripts run all ok without errors.
{
"name": "queue",
"version": "1.0.0",
"description": "An implementation of a queue data structure",
"main": "queue.js",
"scripts": {
"test": "jest",
"clean": "rm -dr dist",
"build": "npm run clean && babel src -s -d dist ",
"production": "npm run build && node bin/production",
"dev": "npm run build && node bin/dev"
},
"author": "Osiris Román",
"license": "ISC",
"devDependencies": {
"#babel/cli": "^7.8.4",
"#babel/core": "^7.9.0",
"#babel/preset-env": "^7.9.5",
"#babel/register": "^7.9.0",
"babel-jest": "^25.5.0",
"jest": "^25.3.0"
}
}
Thanks to #mgarcia comment I decided to avoid babel-preset-es2015 to use the recommended #babel/preset-env .
I am working on a tool and I have installed some modules locally through NPM, and I get errors when I try to require these modules through NodeJS. I am working in Windows 10, I have already tried setting up NODE_PATH etc.
Below is the structure of my files:
->project
---->node_modules
---->src
-------->css
-------->js
----------->index.js
---->package.json
---->index.html
I populate the index.html by using index.js etc.
Below is the code of my package.json:
{
"name": "bip39",
"version": "1.0.0",
"description": "A tool for converting BIP39 mnemonic phrases to addresses and private keys.",
"directories": {
"test": "tests"
},
"dependencies": {
"bip39": "^2.6.0",
"bigi": "^1.4.2",
"create-hmac": "^1.1.7",
"nem-sdk": "^1.6.7"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/PavlosTze/bip39.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/PavlosTze/bip39/issues"
},
"homepage": "https://github.com/PavlosTze/bip39#readme"
}
Below is my require() code:
var createHmac = require("create-hmac");
var BigInteger = require("bigi");
const bip39 = require("bip39");
const nem = require("nem-sdk").default;
I have done the following steps on NPM:
1) npm init
2) npm install bip39
3) npm install nem-sdk
4) npm install bigi
5) npm install create-hmac
All these files are inside the node_modules, but still, whenever I run the code in the browser I get an 'Error: Cannot find module "bip39"', etc. for all modules.
EDIT: On another directory that I have cloned the same tool, before I merged it with another one, I get no error and everything works correctly, including the require(). etc. Do you need any of those files as well?
Can someone help me please?
try this :
rm -rf node_modules
npm install
I am trying to get the code coverage in MOCHA JS test. I am using the blanket and the but I am getting 0 % coverage 0 SLOC why I am not understanding.
my package.json is
{
"name": "basics",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha && mocha test --require blanket --reporter html-cov > coverage.html"
},
"author": "",
"license": "MIT",
"devDependencies": {
"chai": "~2.2.0",
"mocha": "~2.2.4",
"blanket": "~1.1.6",
},
"config": {
"blanket": {
"pattern": ["index.js"],
"data-cover-never": "node_modules"
}
}
}
and index.js is
exports.sanitize = function(word){
return word.toLowerCase().replace(/-/g, ' ');
}
exports.testToString = function(){
return word.toLowerCase().replace(/-/g, ' ');
}
and indexSpec.js which is under test folder is
var chai = require('chai');
var expect = require('chai').expect;
var word = require('../index.js');
describe ('sanitize', function(){
it('String matching ', function(){
var inputWord = 'hello WORLD';
var outputWord = word.sanitize(inputWord);
expect(outputWord).to.equal('hello world');
expect(outputWord).to.not.equal('HELLO WORLD');
expect(outputWord).to.be.a('string');
expect(outputWord).not.to.be.a('number');
});
it('Checke hyphen ', function(){
var inputWord = 'hello-WORLD';
var outputWord = word.sanitize(inputWord);
expect(outputWord).to.equal('hello world');
});
} )
Paul is right. There is no point in using buggy library. Steps for making this code work with Istanbul:
Install Istanbul globally npm install -g istanbul
Change script section in package.json
"scripts": {
"test": "mocha",
"coverage": "istanbul cover node_modules/mocha/bin/_mocha -- -R spec"
},
Run test by typing npm test
Generage coverage report: npm run coverage
Coverage report will be available in coverage/lcov-report/index.html
Get blanket from the git repo. I don't know what's wrong with their npm package, but it didn't work for me either.
Getting the module from git repo works fine.
Make the below changes in your package.json file
"devDependencies": {
"chai": "~2.2.0",
"mocha": "~2.2.4",
"blanket": "git://github.com/alex-seville/blanket.git"
},
I had this problem and added a blanket.js file in my root directory as recommended by Neilskrijger here ... https://github.com/alex-seville/blanket/issues/361 .
I then set my blanket pattern in my package.json to '/lib' which was the root of my source code and it worked. The forward slash was required. My test script was "mocha --require blanket -R html-cov --recursive> coverage.html".
It seems like a lot of us have used the same tutorial and met the same problem.
I have tried all hints given on this page (tried with node versions: node-v4.3.1 and node-v5.7.0) + a few more without any luck
I ended up with another package Istanbul, which I should have done from the start since I normally use the stats as a indicator of which package to use (Its used by so many more users).
First try with this package and it worked :-)
I added this to the script section of package.json:
"coverage" : "./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha -- -R spec"