cucumber / cucumber-js

Cucumber for JavaScript
https://cucumber.io
MIT License
5.04k stars 1.09k forks source link

Cannot read properties of undefined (reading 'line') at test_case_attempt_parser.ts #2226

Closed pawelrochala closed 1 year ago

pawelrochala commented 1 year ago

👓 What did you see?

Hi I have following stacktrace

TypeError: Cannot read properties of undefined (reading 'line')
    at parseTestCaseAttempt (/home/rochala/workspace/ui/aa/cuc/node_modules/@cucumber/cucumber/src/formatter/helpers/test_case_attempt_parser.ts:147:9)
    at formatTestCaseAttempt (/home/rochala/workspace/ui/aa/cuc/node_modules/@cucumber/cucumber/src/formatter/helpers/test_case_attempt_formatter.ts:99:38)
    at formatIssue (/home/rochala/workspace/ui/aa/cuc/node_modules/@cucumber/cucumber/src/formatter/helpers/issue_helpers.ts:51:57)
    at /home/rochala/workspace/ui/aa/cuc/node_modules/@cucumber/cucumber/src/formatter/summary_formatter.ts:84:20
    at Array.forEach (<anonymous>)
    at ProgressFormatter.logIssues (/home/rochala/workspace/ui/aa/cuc/node_modules/@cucumber/cucumber/src/formatter/summary_formatter.ts:82:12)
    at ProgressFormatter.logSummary (/home/rochala/workspace/ui/aa/cuc/node_modules/@cucumber/cucumber/src/formatter/summary_formatter.ts:66:12)
    at EventEmitter.<anonymous> (/home/rochala/workspace/ui/aa/cuc/node_modules/@cucumber/cucumber/src/formatter/summary_formatter.ts:27:14)
    at EventEmitter.emit (node:events:539:35)
    at EventEmitter.emit (node:domain:475:12)

I checked the logic in parseTestCaseAttempt and it seems that gherkinScenarioLocationMap keys doesn't match provided picke id.

✅ What did you expect to see?

A correct summary.

📦 Which tool/library version are you using?

"@cucumber/cucumber": "8.10.0",
"@types/yargs": "17.0.20",
"playwright": "1.29.2",
"ts-node": "10.9.1",
"typescript": "4.9.4",
"yargs": "17.6.2"

Node.js v16.16.0.

🔬 How could we reproduce it?

I'm running : "cucumber-js --config src/cucumber.json src/features/*.feature --require-module ts-node/register --require src/setup.ts"

cucumber.json:

{
  "default": {
    "baseURL": "http://localhost:8080",
    "require": ["src/steps/**/*.ts", "src/setup.ts"],
    "requireModule": ["ts-node/register"],
    "paths": ["src/features/*.feature"]
  }
}

setup.js

import {
  Before,
  BeforeAll,
  ITestCaseHookParameter,
  setDefaultTimeout,
  World as CucumberWorld,
} from '@cucumber/cucumber';
import { BrowserContext, chromium, devices, Page } from 'playwright';
import yargs from 'yargs';

const argv: any = yargs(process.argv).parse();
const config: any = require('./cucumber.json')[argv.p || 'default'];
const globalAny: any = global;
const DEFAULT_TIMEOUT: number = 60000;

setDefaultTimeout(DEFAULT_TIMEOUT);
BeforeAll(async function () {
  globalAny.browser = await chromium.launch({
    headless: config.headless,
    slowMo: config.slowMo,
    timeout: DEFAULT_TIMEOUT,
  });
});

Before(async function (this: SstWorld, parameter: ITestCaseHookParameter) {
  const chrome: any = devices['Desktop Chrome'];
  this.context = await globalAny.browser.newContext({
    viewport: chrome.viewport,
    userAgent: chrome.userAgent,
    baseURL: config.baseURL,
  });
  this.page = await this.context.newPage();
});

export interface SstWorld extends CucumberWorld {
  context: BrowserContext;
  page: Page;
}

screenshot

📚 Any additional context?


This text was originally generated from a template, then edited by hand. You can modify the template here.

davidjgoss commented 1 year ago

Thanks for the detail @pawelrochala. This is a weird one.

I'm not able to reproduce this but I think it's going to be something about one or more of your features. Would you be willing to share the filenames and/or content?

A possible way to narrow it down would be to run one feature at a time and see if any in particular yield the failure.

I'd also note that the command line args you are passing in are duplicating/conflicting what's in your config file.

shogowada commented 1 year ago

Moving the feature files to the default location (./features/**) and removing the paths config fixed the issue for me.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 3 weeks with no activity. Remove the stale label or comment or this will be closed in another 5 days.

davidjgoss commented 1 year ago

I've done a minimal reproducible example here: https://github.com/davidjgoss/cucumber-js-repro-2226

Essentially the issue comes from the same feature file getting loaded twice. Declaring the paths in both the config file and on the CLI looks like identical config that should be deduplicated. But your shell expands the glob, so the merged config Cucumber ends up with is:

{
  paths: [ 'src/features/*.feature', 'src/features/a.feature' ]
}

Which isn't anticipated and causes the duplication.

davidjgoss commented 1 year ago

Thanks all for your patience with this one. Fixed in https://github.com/cucumber/cucumber-js/releases/tag/v9.0.1