salesforce/lwc

Flaky karma test: profiler/mutation-logging

cardoso opened this issue · 2 comments

While working on migration to paywright and vitest , I often run the karma tests and this particular test sometimes fails and succeeds in a second run.

$ karma start ./scripts/karma-configs/test/local.js --single-run --browsers ChromeHeadless
02 10 2024 11:44:16.982:INFO [karma-server]: Karma v6.4.4 server started at http://localhost:9876/
02 10 2024 11:44:16.984:INFO [launcher]: Launching browsers ChromeHeadless with concurrency unlimited
02 10 2024 11:44:16.989:INFO [launcher]: Starting browser ChromeHeadless
02 10 2024 11:44:17.762:INFO [Chrome Headless 131.0.0.0 (Mac OS 10.15.7)]: Connected on socket EUjoOUt_pryKRXYcAAAB with id 5951216
Chrome Headless 131.0.0.0 (Mac OS 10.15.7) profiler mutation-logging parent-child Logs a mutation on the parent only FAILED
        Expected [ [object PerformanceMeasure] ] to equal <jasmine.arrayWithExactContents([ <jasmine.objectContaining(Object({ name: 'lwc-rehydrate', detail: <jasmine.objectContaining(Object({ devtools: <jasmine.objectContaining(Object({ properties: <jasmine.arrayWithExactContents([ <jasmine.arrayWithExactContents([ 'Component', '<x-parent>' ])>, <jasmine.arrayWithExactContents([ '<x-parent>', 'firstName' ])> ])> }))> }))> }))> ])>.
            at <Jasmine>
            at expectRehydrationEntry (profiler/mutation-logging/test/profiler/mutation-logging/index.spec.js:56:21 <- profiler/mutation-logging/index.spec.js:231:23)
            at UserContext.<anonymous> (profiler/mutation-logging/test/profiler/mutation-logging/index.spec.js:271:13 <- profiler/mutation-logging/index.spec.js:395:11)
Chrome Headless 131.0.0.0 (Mac OS 10.15.7): Executed 3369 of 3695 (1 FAILED) (skipped 326) (5.533 secs / 4.99 secs)
TOTAL: 1 FAILED, 3368 SUCCESS
error Command failed with exit code 1.

Taking a look at this issue

One easy (perhaps) way we could fix this: use a Jasmine spy for performance.measure instead of a PerformanceObserver. I don't know why PerformanceObserver is so flaky, but we don't need to use it.