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

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

Open
llorllale opened this issue Feb 21, 2020 · 2 comments
Open

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

llorllale opened this issue Feb 21, 2020 · 2 comments

Comments

@llorllale
Copy link

llorllale commented Feb 21, 2020

Given() not working:

devDependencies:

  "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:

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:

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
Copy link
Owner

mitcoding commented Jul 21, 2021

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
Copy link
Owner

mitcoding commented Jul 21, 2021

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.

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

No branches or pull requests

2 participants