-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
ci() Introducing JEST and basic tests #8919
Conversation
Build Stats
|
This is here for discussion and best practices. |
Ok this is up for discussion. |
Well coverage didn't work. i suppose runInBand? no just doesn't work. |
i don't know on my local works, coverage bumbs to 83.92 while on github action something is off. Is not super important before evaluating the approach anyway
|
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 am not for jest because it is falling behind in esm support.
I am worried it will reach its course because of this issue.
IMO this is a no go for us.
Slow when analyzing what to run?
Can you, for the sake of discussion think of a need to mock other modules in fabric for some test? Because that is one of the thigs jest will not be able to do if I understand correctly. Or does babel fix that?
At least we should have a test that mocks some class methods w/o using mocks and not mutatuion.
src/brushes/CircleBrush.test.ts
Outdated
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.
This is very nice
So our worry is that we can't mock internal fabricjs files because of some kind of missing support from jest? Which would be a better unit test framework then? |
I heard of vitest this week (asked people at work since they use jest heavily with mocking etc.)
|
So maybe it is non blocking... |
could you (or should I) make #8738 pick these tests up as well and see it works. |
importing and snapshots in tests is extremely exciting |
Also I would us to come up with a convention for visual test etc. |
You can, but i don't want change test runner. |
Yes another important point is that we want to test functions without having to put them in the bundle or test them from the bundle. |
i have no idea what |
The issue that remains with visual tests is that we need to run them in 2 different suites. With this PR i don't want to settle the conventions for all tests, i just want to see if JEST is good to replace QUNIT for all tests that are logic only and do not relate to events or canvas, and remove those from the browser. This is the scope with which i opened this PR. |
I am ok with merging this and moving forward. |
Regarding visual tests, I am hoping we will find a decent way to solve it and believe we will. |
In order to merge this i need to understand what is going on with coverage. |
.github you mean? In the build action I think |
fabric.js/.github/workflows/build.yml Lines 92 to 109 in 9414434
|
This action is wasteful and not precise (node only - many tests are skipped). We can use the existing test actions and upload the coverage outputs as an artifact and then run the report to combine both browser and node coverage |
clearMocks: true, | ||
|
||
// Indicates whether the coverage information should be collected while executing the test | ||
collectCoverage: 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.
why is this 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.
becasue we collect coverage with nyc for qunit, and is the only way to mix it it seems. So i disabled the internal coverage reporter of Jest
coverageReporters: [ | ||
'json', | ||
// "text", | ||
// 'lcov', |
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.
did you try lcov? I think the action uses that
i have to add the globals or JEST before being able to merge |
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.
What is the status with coverge? Did you try lcov as well?
The action needs lcov reports.
node-version: 18 | ||
- run: npm ci | ||
- name: Run Jest unit test | ||
run: npm run test:jest |
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 will follow up with cli PR exposing this and playwright
beforeAll(() => { | ||
global.Math.random = jest.fn(() => 0.1); | ||
}); | ||
afterAll(() => { | ||
global.Math.random = originalMathRandom; | ||
}); | ||
it('return a number between min and max', () => { | ||
(global.Math.random as jest.Mock).mockReturnValue(0.1); | ||
const semiRandom = getRandomInt(0, 10); | ||
expect(semiRandom).toBe(1); | ||
}); |
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 don't understand why the beforeAll/afterAll if this test is using mocks
I think we should not do that anymore and use only mocks, stubs, spies whatever
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 don't think you can mock random differently than this.
Because Math is not an import so it doesn't go in the import cache, so the standrd jest.mock('lib', mockFunction)
doesn't work
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.
So i would like to add sinon
Sinon does that so easily and plays nicely everywhere
For now we don't have it. |
All the coverage is generated with NYC, so the format is the same as before ( LCOV ). |
Motivation
Today Qunit it is what it is and in order to move to testing functions rather than the whole fabricJS package, we need to refactor our test files.
Is probably possible to better undertand QUnit and just import the specific file we want to test and run scoped tests, but at work we mostly use JEST and we are probably more productive with it.
Now this brings in patterns and decisions and opinions.
I opened this PR with the same pattern i use every day at work
i followed the jest tutorial to get this setup runnig.
My proposal is to:
PROS:
CONS: