I have two kind of tests running for my React application. For unit test I am using Jest.
For feature test I am just starting to try Cucumber @cucumber/cucumber
. I initially wanted to use jest-cucumber
but its last version was 2 years ago so I was kind of reluctant.
This is the scripts
part at the package.json
"test:unit": "jest --ci",
"test:feature": "cucumber-js"
When I run the yarn test:unit
it successfully.
I am currently have a simple Cucumber steps file steps.mjs
.
import { Given, When, Then } from '@cucumber/cucumber'
import { strict as assert } from 'assert'
Given('I am on the login page', async function () {
});
When('I enter valid credentials', function () {
});
When('I click on the login button', function () {
});
Then('I should be redirected to the dashboard', function () {
});
Add this point, the cucumber runs okay but with failing tests.
$ yarn test:feature
yarn run v1.22.19
$ cucumber-js
.....U-U
.......
2 scenarios (1 undefined, 1 passed)
8 steps (2 undefined, 1 skipped, 5 passed)
0m00.006s (executing steps: 0m00.000s)
I want to add a Selenium to test.
import { Given, When, Then } from '@cucumber/cucumber'
import { strict as assert } from 'assert'
import { Builder, By, until } from 'selenium-webdriver';
Given('I am on the login page', async function () {
// this.driver = new Builder()
// .forBrowser('chrome')
// .build();
// this.driver.wait(until.elementLocated(By.tagName('h1')));
// await this.driver.get('http://localhost:3000/login');
});
////
Then I tried installing Selenium webdriver
yarn add -D selenium-webdriver
Then when I tried the unit test again, it somewhat fails
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/petrabarus/Projects/myproject/node_modules/wrap-ansi/index.js from /Users/petrabarus/Projects/myproject/node_modules/cliui/build/index.cjs not supported.
Instead change the require of index.js in /Users/petrabarus/Projects/myproject/node_modules/cliui/build/index.cjs to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (/Users/petrabarus/Projects/myproject/node_modules/cliui/build/index.cjs:293:14)
at Object.<anonymous> (/Users/petrabarus/Projects/myproject/node_modules/yargs/build/index.cjs:1:60678)
at Object.<anonymous> (/Users/petrabarus/Projects/myproject/node_modules/yargs/index.cjs:5:30)
at _yargs (/Users/petrabarus/Projects/myproject/node_modules/jest-cli/build/run.js:30:39)
at buildArgv (/Users/petrabarus/Projects/myproject/node_modules/jest-cli/build/run.js:149:26)
at Object.run (/Users/petrabarus/Projects/myproject/node_modules/jest-cli/build/run.js:124:24)
at Object.<anonymous> (/Users/petrabarus/Projects/myproject/node_modules/jest-cli/bin/jest.js:16:17)
at Object.<anonymous> (/Users/petrabarus/Projects/myproject/node_modules/jest/bin/jest.js:12:3)
Here is the version installed:
{
"@babel/preset-typescript": "^7.23.3",
"@cucumber/cucumber": "^10.0.1",
"@testing-library/jest-dom": "^6.1.5",
"@testing-library/react": "^14.1.2",
"@types/jest": "^29.5.10",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"autoprefixer": "^10.0.1",
"eslint": "^8",
"eslint-config-next": "14.0.3",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"postcss": "^8",
"selenium-webdriver": "^4.15.0",
"tailwindcss": "^3.3.0",
"typescript": "^5"
}
I am using node v20.8.0
and yarn 1.22.19
.
Why does this happens, and how do I fix this?
Update 1
Here is the diff of the yarn.lock
before and after adding selenium-webdriver
.
2174,2178d2173
< core-util-is@~1.0.0:
< version "1.0.3"
< resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.3.tgz#a6042d3634c2b27e9328f837b965fac83808db85"
< integrity sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==
<
3261,3265d3255
< immediate@~3.0.5:
< version "3.0.6"
< resolved "https://registry.yarnpkg.com/immediate/-/immediate-3.0.6.tgz#9db1dbd0faf8de6fbe0f5dd5e56bb606280de69b"
< integrity sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==
<
3300c3290
< inherits@2, inherits@~2.0.3:
---
> inherits@2:
3542,3546d3531
<
< isarray@~1.0.0:
< version "1.0.0"
< resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
< integrity sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==
4101,4110d4085
<
< jszip@^3.10.1:
< version "3.10.1"
< resolved "https://registry.yarnpkg.com/jszip/-/jszip-3.10.1.tgz#34aee70eb18ea1faec2f589208a157d1feb091c2"
< integrity sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==
< dependencies:
< lie "~3.3.0"
< pako "~1.0.2"
< readable-stream "~2.3.6"
< setimmediate "^1.0.5"
4156,4162d4130
< lie@~3.3.0:
< version "3.3.0"
< resolved "https://registry.yarnpkg.com/lie/-/lie-3.3.0.tgz#dcf82dee545f46074daf200c7c1c5a08e0f40f6a"
< integrity sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==
< dependencies:
< immediate "~3.0.5"
<
4589,4593d4556
< pako@~1.0.2:
< version "1.0.11"
< resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.11.tgz#6c9599d340d54dfd3946380252a35705a6b992bf"
< integrity sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==
<
4762,4766d4724
<
< process-nextick-args@~2.0.0:
< version "2.0.1"
< resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"
< integrity sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==
4916,4928d4873
< readable-stream@~2.3.6:
< version "2.3.8"
< resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.8.tgz#91125e8042bba1b9887f49345f6277027ce8be9b"
< integrity sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==
< dependencies:
< core-util-is "~1.0.0"
< inherits "~2.0.3"
< isarray "~1.0.0"
< process-nextick-args "~2.0.0"
< safe-buffer "~5.1.1"
< string_decoder "~1.1.1"
< util-deprecate "~1.0.1"
<
5083,5087d5027
< safe-buffer@~5.1.0, safe-buffer@~5.1.1:
< version "5.1.2"
< resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
< integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==
<
5120,5128d5059
<
< selenium-webdriver@^4.15.0:
< version "4.15.0"
< resolved "https://registry.yarnpkg.com/selenium-webdriver/-/selenium-webdriver-4.15.0.tgz#ee827f8993864dc0821df0d3b46d4f312d6f1aa3"
< integrity sha512-BNG1bq+KWiBGHcJ/wULi0eKY0yaDqFIbEmtbsYJmfaEghdCkXBsx1akgOorhNwjBipOr0uwpvNXqT6/nzl+zjg==
< dependencies:
< jszip "^3.10.1"
< tmp "^0.2.1"
< ws ">=8.14.2"
5173,5177d5103
< setimmediate@^1.0.5:
< version "1.0.5"
< resolved "https://registry.yarnpkg.com/setimmediate/-/setimmediate-1.0.5.tgz#290cbb232e306942d7d7ea9b83732ab7856f8285"
< integrity sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==
<
5373,5379d5298
< string_decoder@~1.1.1:
< version "1.1.1"
< resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.1.1.tgz#9cf1611ba62685d7030ae9e4ba34149c3af03fc8"
< integrity sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==
< dependencies:
< safe-buffer "~5.1.0"
<
5772c5691
< util-deprecate@^1.0.2, util-deprecate@~1.0.1:
---
> util-deprecate@^1.0.2:
5913d5831
< name wrap-ansi-cjs
5944c5862
< ws@>=8.14.2, ws@^8.11.0:
---
> ws@^8.11.0: