CucumberJS only shows diagnostic codes after ESM upgrade

27 Views Asked by At

We've recently upgraded our test suite to ESM rather than CommonJS. This involved a few things such as setting the following Node options

--experimental-specifier-resolution=node --loader ts-node/esm

Setting the type in package.json to module et al.

Everything works fine, until I introduce an error in one of the step definition files. It can be any error, but in this case, it's using a property that doesn't exist on an interface, such as:

interface Foo {
  bar string
}

const f: Foo = { invalid: '' }

In this case, when using runCucumber, we get an ERR_UNHANDLED_REJECTION error. If we add a catch to runCucumber, all we get back is a TypeScript diagnostic code:

{ diagnosticCodes: [ 2353 ] }

This code does point to the actual error when we look at the list of TypeScript diagnostic codes but we'd expect to see the actual error.

Here's how we're calling Cucumber

const config: ILoadConfigurationOptions = {
  file: 'cucumber.mjs',
}
const { runConfiguration } = await loadConfiguration(config)
const run = await runCucumber(runConfiguration).catch(console.error)

Here's the tsconfig.json

{
  "compilerOptions": {
    "experimentalDecorators": true,
    "module": "ES2022",
    "target": "ES6",
    "moduleResolution": "Node",
    "allowSyntheticDefaultImports": true,
    "alwaysStrict": true
  }
}

And here's the command to run the test suite

yarn component:gen-org-tests && node --experimental-specifier-resolution=node --loader ts-node/esm --no-warnings index.ts

(index.ts contains the runCucumber step)

Looking in to the CucumberJS code, I can see this step that loads each file

await import((0, node_url_1.pathToFileURL)(path).toString());

and it appears it's here where it fails to load the file and exits.

0

There are 0 best solutions below