-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: replace jest with mocha #420
Conversation
@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. |
457321d
to
ac97e71
Compare
"test-build": "npm test --runInBand --coverage", | ||
"test-staged": "npm test --bail --no-cache --findRelatedTests", | ||
"test": "mocha --exit --parallel --require ts-node/register --require src/testSetup.ts src/**/*.test.ts", | ||
"test-coverage": "c8 --reporter=json --reporter=html npm test", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test-build make no sense here, so I rename it to test-coverage
"test-staged": "npm test --bail --no-cache --findRelatedTests", | ||
"test": "mocha --exit --parallel --require ts-node/register --require src/testSetup.ts src/**/*.test.ts", | ||
"test-coverage": "c8 --reporter=json --reporter=html npm test", | ||
"test-staged": "npm test --bail", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure we still need this script command ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's for husky or something like that.
Lines 44 to 49 in 4d6d4d3
"lint-staged": { | |
"*.{ts,js}": [ | |
"eslint --fix", | |
"npm run test-staged" | |
] | |
}, |
I'd probably prefer to remove lint-staged and similar stuff. This repo is simple and should stay simple, so not worth having that lint-staged dep imo.
But probably off-topic for this PR.
C8 requires node >= 18, wtf? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was a bit worried about this but this looks like a win. You did it in a way that reduces risk and churn. Thank you!
"@types/node": "16.9.x", | ||
"c8": "^10.1.2", | ||
"expect": "^29.7.0", | ||
"jest-mock": "^29.7.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jest-mock
is fine as a temporary step (if it saves some noise in this PR), but maybe we want to switch to https://sinonjs.org/ ? Or maybe it doesn't matter. (But maybe it's confusing to have both jest and mocha :)
.eslintrc.js
Outdated
@@ -70,6 +71,7 @@ module.exports = { | |||
|
|||
'import/extensions': 'off', | |||
'import/prefer-default-export': 'off', | |||
"import/no-extraneous-dependencies": ["error", {"devDependencies": true, "optionalDependencies": false, "peerDependencies": false}], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
single quotes
"testPathIgnorePatterns": [".d.ts", ".js"] | ||
"@types/mocha": "^10.0.9", | ||
"c8": "^10.1.2", | ||
"expect": "^29.7.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK as a transitional step, but can probably be avoided in a later PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll handle this(replace expect and jest-mock with assert and sinon) in a follow up PR :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking that although expect made by Jest, should we replace it ? or is it worth to do so(expect is a good assert lib in my opinion)?
// eslint-disable-next-line import/no-mutable-exports | ||
export let proc: cp.ChildProcessWithoutNullStreams; | ||
// eslint-disable-next-line import/no-mutable-exports | ||
export let nvim: NeovimClient; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can/should this be a function? it's a bit "magical" as a global var, and also makes debugging a bit more painful?
Not a blocker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll handle this too in a follow up PR :)
We could skip codecov for older node. |
@@ -155,7 +150,7 @@ describe('Nvim API', () => { | |||
}); | |||
|
|||
it('emits "disconnect" after quit', done => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't know why this test is keep failing!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can skip it for now. even after the 'exit' workaround it still fails for me locally, sometimes.
looks like there is a Uncaught error in our test util. |
maybe drop |
Drop Got error |
that's weird, but based on mochajs/mocha#185 seems like mocha intentionally does not set NODE_ENV? For now we could just add to testSetup.ts:
|
packages/neovim/src/testSetup.ts
Outdated
|
||
import * as testUtil from './testUtil'; | ||
// import * as jest from '@jest/globals' | ||
process.env.NODE_ENV = 'test'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already done that, I mean this line is not working after drop --parallel.
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 example (untested, just a sample):
and the GHA workflow: uses: codecov/codecov-action@v4
with:
verbose: true
file: ./coverage/neovim/lcov.info
token: ${{ secrets.CODECOV_TOKEN }} |
@@ -30,7 +30,7 @@ | |||
"dev": "npm run --stream --parallel dev --workspaces --if-present", | |||
"publish:neovim": "cd packages/neovim && cp ../../README.md . && cp ../../CHANGELOG.md . && npm publish", | |||
"test": "npm run test --workspaces --if-present", | |||
"test-coverage": "npm run test --workspaces --if-present", | |||
"test-coverage": "npm run test-coverage --workspaces --if-present", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad :), codecov works now.
Follow up PR TODO:
|
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.
reading https://jestjs.io/docs/expect , mocha (or
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 :) |
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.