node-client icon indicating copy to clipboard operation
node-client copied to clipboard

test: replace jest with mocha

Open gjf7 opened this issue 1 year ago • 2 comments

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.

gjf7 avatar Oct 11 '24 15:10 gjf7

@justinmk Mocha doesn't support coverage out of box, Do u think https://github.com/istanbuljs/nyc is a good choice for us?

gjf7 avatar Oct 11 '24 16:10 gjf7

@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.

justinmk avatar Oct 11 '24 17:10 justinmk

C8 requires node >= 18, wtf?

gjf7 avatar Oct 16 '24 14:10 gjf7

C8 requires node >= 18, wtf?

We could skip codecov for older node.

justinmk avatar Oct 16 '24 14:10 justinmk

looks like there is a Uncaught error in our test util.

gjf7 avatar Oct 16 '24 15:10 gjf7

maybe drop --parallel for now? not sure if these tests are prepared for that.

justinmk avatar Oct 16 '24 15:10 justinmk

maybe drop --parallel for 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.

gjf7 avatar Oct 16 '24 15:10 gjf7

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';

justinmk avatar Oct 16 '24 16:10 justinmk

Turns out we must set 'NODE_ENV=test' in .mocharc.js in non-parallel mode. Sets in testSetup is useless :)

gjf7 avatar Oct 16 '24 17:10 gjf7

Need to check why codecov is't triggered.

gjf7 avatar Oct 16 '24 17:10 gjf7

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 }}

justinmk avatar Oct 16 '24 18:10 justinmk

Follow up PR TODO:

  1. eliminate the magical global nvim, proc in test util.
  2. replace expect with Node.js built-in assert module to reduces total number of dependencies

gjf7 avatar Oct 17 '24 00:10 gjf7

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.

  1. eliminate the magical global nvim, proc in 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 :).

justinmk avatar Oct 17 '24 08:10 justinmk

Ready for merge :)

gjf7 avatar Oct 17 '24 09:10 gjf7