-
Notifications
You must be signed in to change notification settings - Fork 26
Addressing issues with failing flaky tests #2630
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
base: master
Are you sure you want to change the base?
Conversation
b77a723
to
02dec82
Compare
42de1fd
to
02dec82
Compare
This is to fix the flaky test failures that cause: Error: ReferenceError: window is not defined ❯ stopTimer src/composables/autoRefresh.ts:12:7 ❯ startTimer src/composables/autoRefresh.ts:20:5 ❯ executeAndResetTimer src/composables/autoRefresh.ts:31:7 ❯ Timeout._onTimeout src/composables/autoRefresh.ts:22:7 ❯ listOnTimeout node:internal/timers:588:17 ❯ processTimers node:internal/timers:523:7
Added run to vitest so by default we not running in watch mode
Otherwise the cleanup happens in a non deterministic order
"lint": "eslint .", | ||
"preview": "vite preview", | ||
"test:component": "vitest ./src", | ||
"test:component": "vitest run ./src", |
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.
By default vitest runs in watch mode, but in our CI we always want it to perform a single run without watch mode.
"@testing-library/vue": "8.1.0", | ||
"@tsconfig/node18": "18.2.4", | ||
"@types/bootstrap": "5.2.10", | ||
"@types/jsdom": "27.0.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.
We were missing this typescript type
function deleteAllCookies() { | ||
const cookies = document.cookie.split(";"); | ||
|
||
for (let i = 0; i < cookies.length; i++) { | ||
const cookie = cookies[i]; | ||
const eqPos = cookie.indexOf("="); | ||
const name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie; | ||
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT"; | ||
} | ||
} | ||
|
||
afterEach(() => { | ||
//Intentionally not calling mockServer.resetHandlers here to prevent ServicePulse in flight messages after app unmount to fail. | ||
//mockServer.resetHandlers is being called instead in driver.ts | ||
|
||
//Make JSDOM create a fresh document per each test run | ||
jsdom.reconfigure({ url: "http://localhost:3000/" }); | ||
localStorage.clear(); | ||
sessionStorage.clear(); | ||
deleteAllCookies(); |
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.
All this code was moved into the driver.ts
deleteAllCookies(); | ||
afterAll(() => { | ||
console.log("Shutting down mock server"); | ||
mockServer.close(); |
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 are cleaning up the mock server as per the documentation
}, | ||
test: { | ||
pool: "forks", //https://github.com/vitest-dev/vitest/issues/2008#issuecomment-187106690 | ||
pool: "forks", |
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.
forks
is now the default.
We found an issue with the cleaning-up routines that can cause certain instances to be cleaned up before others.
We have started a discussion in vitest to figure out if the behaviour is a bug or if we are just using it incorrectly.
In the meantime, we have addressed the issue by refactoring the code to do the cleanup in a more consistent way.