mitcoding / karma-cucumber-js-latest

Karma adapter for running Cucumber.js features
MIT License
1 stars 1 forks source link

TypeError: Arguments to path.resolve must be strings #2

Open llorllale opened 4 years ago

llorllale commented 4 years ago

Given() not working:

devDependencies:

```json "devDependencies": { "chai": "4.2.0", "cucumber": "6.0.5", "karma": "4.4.1", "karma-chai": "0.1.0", "karma-chrome-launcher": "3.1.0", "karma-cucumber-js-latest": "1.0.5", "karma-mocha": "1.3.0", "mocha": "7.0.1", "puppeteer": "2.1.1" }, ```

karma.conf.js:

```js process.env.CHROME_BIN = require('puppeteer').executablePath() module.exports = function(config) { config.set({ frameworks: ["mocha", "chai", "cucumber-js"], browsers: ["ChromeHeadless"], singleRun: true, files: [ {pattern: "test/**/*.js", type: "module"}, ... {pattern: "features/*.feature", included: false}, ], plugins: [ "karma-mocha", "karma-chai", "karma-chrome-launcher", "karma-cucumber-js-latest" ] }) } ```

test_steps:

```js const Given = Cucumber.Given const When = Cucumber.When const Then = Cucumber.Then // ... some code .... Given(/regex/, function() { // test code }) ```

Error:

``` 21 02 2020 16:56:52.874:INFO [karma-server]: Karma v4.4.1 server started at http://0.0.0.0:9876/ 21 02 2020 16:56:52.876:INFO [launcher]: Launching browsers ChromeHeadless with concurrency unlimited 21 02 2020 16:56:52.878:INFO [launcher]: Starting browser ChromeHeadless 21 02 2020 16:56:53.152:INFO [HeadlessChrome 80.0.3987 (Linux 0.0.0)]: Connected on socket iFJHo9Ucr6Sa13uLAAAA with id 6284202 HeadlessChrome 80.0.3987 (Linux 0.0.0) ERROR Uncaught TypeError: Arguments to path.resolve must be strings at node_modules/cucumber/dist/cucumber.js:47815:13 TypeError: Arguments to path.resolve must be strings at Object.exports.resolve (node_modules/cucumber/dist/cucumber.js:47815:13) at Object.exports.relative (node_modules/cucumber/dist/cucumber.js:47876:18) at getDefinitionLineAndUri (node_modules/cucumber/dist/cucumber.js:64807:28) at buildStepDefinition (node_modules/cucumber/dist/cucumber.js:64773:32) at SupportCodeLibraryBuilder.defineStep (node_modules/cucumber/dist/cucumber.js:64956:67) at test/test_steps.js:45:1 npm ERR! Test failed. See above for more details. ```

mitcoding commented 3 years ago

Just saw this. You don't need to import cucumber. it's already imported when karma has been configured correctly, meaning Given/When/Then already exists as global variables for all step files. take a look at my redux-forth project that use this karma plugin

https://github.com/mitcoding/redux-forth/blob/master/src/test/javascript/feature/redux.steps.js

https://github.com/mitcoding/redux-forth/blob/master/karma.config.js

mitcoding commented 3 years ago

The other thing that might be keeping the globals from working is the the step files for cucumeber need to be in a folder called steps "/steps/foo.js" or the file name needs to end in ".steps.js" e.g. foo.steps.js.