feat: Use vitest instead of jest, run all the specs anywhere in app/ folder in the CI (#9722)

Due to the pattern `**/specs/*.spec.js` defined in CircleCI, none of the
frontend spec in the folders such as
`specs/<domain-name>/getters.spec.js` were not executed in Circle CI.

This PR fixes the issue, along with the following changes: 
- Use vitest instead of jest
- Remove jest dependancies
- Update tests to work with vitest

---------

Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
Pranav
2024-07-10 08:32:16 -07:00
committed by GitHub
parent 9498d1f003
commit 9de8c27368
140 changed files with 1678 additions and 2810 deletions

View File

@@ -51,28 +51,24 @@ describe('#hasUserKeys', () => {
});
// Mock the 'set' method of the 'Cookies' object
jest.mock('js-cookie', () => ({
set: jest.fn(),
}));
describe('setCookieWithDomain', () => {
beforeEach(() => {
vi.spyOn(Cookies, 'set');
});
afterEach(() => {
// Clear mock calls after each test
Cookies.set.mockClear();
vi.restoreAllMocks();
});
it('should set a cookie with default parameters', () => {
setCookieWithDomain('myCookie', 'cookieValue');
expect(Cookies.set).toHaveBeenCalledWith(
'myCookie',
'cookieValue',
expect.objectContaining({
expires: 365,
sameSite: 'Lax',
domain: undefined,
})
);
expect(Cookies.set).toHaveBeenCalledWith('myCookie', 'cookieValue', {
expires: 365,
sameSite: 'Lax',
domain: undefined,
});
});
it('should set a cookie with custom expiration and sameSite attribute', () => {
@@ -80,15 +76,11 @@ describe('setCookieWithDomain', () => {
expires: 30,
});
expect(Cookies.set).toHaveBeenCalledWith(
'myCookie',
'cookieValue',
expect.objectContaining({
expires: 30,
sameSite: 'Lax',
domain: undefined,
})
);
expect(Cookies.set).toHaveBeenCalledWith('myCookie', 'cookieValue', {
expires: 30,
sameSite: 'Lax',
domain: undefined,
});
});
it('should set a cookie with a specific base domain', () => {
@@ -96,18 +88,14 @@ describe('setCookieWithDomain', () => {
baseDomain: 'example.com',
});
expect(Cookies.set).toHaveBeenCalledWith(
'myCookie',
'cookieValue',
expect.objectContaining({
expires: 365,
sameSite: 'Lax',
domain: 'example.com',
})
);
expect(Cookies.set).toHaveBeenCalledWith('myCookie', 'cookieValue', {
expires: 365,
sameSite: 'Lax',
domain: 'example.com',
});
});
it('should stringify the cookie value when setting', () => {
it('should stringify the cookie value when setting the value', () => {
setCookieWithDomain(
'myCookie',
{ value: 'cookieValue' },
@@ -119,11 +107,11 @@ describe('setCookieWithDomain', () => {
expect(Cookies.set).toHaveBeenCalledWith(
'myCookie',
JSON.stringify({ value: 'cookieValue' }),
expect.objectContaining({
{
expires: 365,
sameSite: 'Lax',
domain: 'example.com',
})
}
);
});
@@ -133,14 +121,10 @@ describe('setCookieWithDomain', () => {
baseDomain: 'example.com',
});
expect(Cookies.set).toHaveBeenCalledWith(
'myCookie',
'cookieValue',
expect.objectContaining({
expires: 7,
sameSite: 'Lax',
domain: 'example.com',
})
);
expect(Cookies.set).toHaveBeenCalledWith('myCookie', 'cookieValue', {
expires: 7,
sameSite: 'Lax',
domain: 'example.com',
});
});
});