test: replace jest with mocha
Closes #333.
To make a transition from Jest feasible. Capabilities Jest offers that we might need to keep:
Expect
Expect is a standalone npm package.
Mock
The jest.fn(), jest.spyOn() is provided by jest-mock, we can just use this package directly.
@justinmk Mocha doesn't support coverage out of box, Do u think https://github.com/istanbuljs/nyc is a good choice for us?
@justinmk Mocha doesn't support coverage out of box, Do u think https://github.com/istanbuljs/nyc is a good choice for us?
nyc is deprecated, https://github.com/bcoe/c8 is the current best option AFAIK.
C8 requires node >= 18, wtf?
C8 requires node >= 18, wtf?
We could skip codecov for older node.
looks like there is a Uncaught error in our test util.
maybe drop --parallel for now? not sure if these tests are prepared for that.
maybe drop
--parallelfor now? not sure if these tests are prepared for that.
Drop --parallel make `process.env.NODE_ENV = 'test' not executed, don't know why.
Got error Exception during run: TypeError: Cannot read properties of undefined (reading 'parseVersion' NODE_ENV is undefined.
that's weird, but based on https://github.com/mochajs/mocha/issues/185 seems like mocha intentionally does not set NODE_ENV? For now we could just add to testSetup.ts:
process.env.NODE_ENV = 'test';
Turns out we must set 'NODE_ENV=test' in .mocharc.js in non-parallel mode. Sets in testSetup is useless :)
Need to check why codecov is't triggered.
might need a .c8rc.json in packages/neovim/. IIRC the "lcov" reporter was important to get it to work with codecov.
example (untested, just a sample):
{
"report-dir": "../../coverage/neovim",
"reporter": ["lcov"],
"all": true,
"include": ["src/**"],
"exclude": [
"src/test/**"
]
}
and the GHA workflow:
uses: codecov/codecov-action@v4
with:
verbose: true
file: ./coverage/neovim/lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
Follow up PR TODO:
- eliminate the magical global
nvim,procin test util. - replace expect with Node.js built-in assert module to reduces total number of dependencies
replace jest-mock with sinon
On second thought, let's keep jest-mock for now. Mocking should be rare, and unless sinon improves something, using jest-mock avoids churn and doesn't really hurt.
keep expect is fine
reading https://jestjs.io/docs/expect , mocha (or assert) already provides this except the syntax is different? If removing expect reduces total number of dependencies, then it might be worth doing.
- eliminate the magical global
nvim,procin test util
I'm also not sure about this. The current situation looks ok, since this repo is very simple (and getting simpler, thanks to this PR :).
Ready for merge :)