0

I'm trying to do a very simple test using mocha (no config files, no additional flags, just mocha, yarn2, and testee.js file), but it always give me 0 passing. Hell, it won't even run any file!

// testee.js

console.log('test') // No output

describe('something', () => {
    it('Should run', () => {
        console.log('test 2') // No output either
    })
})
$ yarn mocha testee.js

  0 passing (1ms)

Tools I'm using:

  • Mocha 9.0.2
  • Yarn Berry 2.4.2

Is mocha unsupported by Yarn 2? Should I use something else? I always use mocha for all of my test files, maybe it's time to migrate if that really is the case.

Note: I tried using yarn 1 and it worked flawlessly. Also, Mocha found the testee.js file, otherwise it would give me not found error instead of 0 passing

RobC
  • 22,977
  • 20
  • 73
  • 80
SnekNOTSnake
  • 1,157
  • 12
  • 24
  • If a bug you should open an issue on our repository (Yarn). However, Mocha is covered by an E2E test and a bug seems unlikely (https://github.com/yarnpkg/berry/blob/master/.github/workflows/e2e-mocha-workflow.yml#L31-L47). – Maël Nison Jul 19 '21 at 11:36

1 Answers1

0

Mocha 9 uses ESM-first approach to imports https://github.com/mochajs/mocha/releases/tag/v9.0.0

Yarn 2+ with the default PnP install scheme does not support ESM yet, because Node API lacks some features to make this possible

For the time being, if you want to use Mocha 9, you have to use node_modules install scheme with Yarn 2+ by changing your config to: .yarnrc.yml

nodeLinker: node-modules
...

and running yarn to reinstall your project with node_modules

You can track ESM support for Yarn PnP here: https://github.com/yarnpkg/berry/issues/638

Viktor Vlasenko
  • 2,332
  • 14
  • 16