avajs/ava

node v20 --loader error

iambumblehead opened this issue · 0 comments

Checking in here to notify about an issue using ava with node v20 and --loader. There is a problem demonstrated at the repo here: https://github.com/iambumblehead/nodejs-v20-loader-ava-noop; using npm test from that repo with node v20 causes the test to incorrectly fail.

Essentially ava fails when used with --loader

anyloader.js

export const load = async (url, context, nextLoad) => {
  if (url.endsWith('anyfile.js')) {
    return {
      format: 'module',
      shortCircuit: true,
      responseURL: url,
      source: 'export default "fromloader"'
    }
  }
  return nextLoad(url, context)
}

anyfile.spec.js

import test from 'ava'

test('should user loader', async t => {
  const anyfile = await import('./anyfile.js')

  t.is(anyfile.default, 'fromloader')
})
ava --node-arguments="--loader=./anyloader.js"


(node:59341) ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
  ✖ should user loader Promise returned by test never resolved


  should user loader

  Error: Promise returned by test never resolved



  1 test failed

It might be caused by an upstream issue reported earlier this evening nodejs/node#47614, however opening an issue here may be useful because the error manifests itself in a special way with ava, indicating a possibly separate issue.