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

@@ -2,23 +2,18 @@ import axios from 'axios';
import Cookies from 'js-cookie';
import { actions } from '../../auth';
import * as types from '../../../mutation-types';
import { setUser, clearCookiesOnLogout } from '../../../utils/api';
import * as APIHelpers from '../../../utils/api';
import '../../../../routes';
jest.mock('../../../../routes', () => {});
jest.mock('../../../utils/api', () => ({
setUser: jest.fn(),
clearCookiesOnLogout: jest.fn(),
getHeaderExpiry: jest.fn(),
}));
jest.mock('js-cookie', () => ({
get: jest.fn(),
}));
vi.spyOn(APIHelpers, 'setUser');
vi.spyOn(APIHelpers, 'clearCookiesOnLogout');
vi.spyOn(APIHelpers, 'getHeaderExpiry');
vi.spyOn(Cookies, 'get');
const commit = jest.fn();
const dispatch = jest.fn();
const commit = vi.fn();
const dispatch = vi.fn();
global.axios = axios;
jest.mock('axios');
vi.mock('axios');
describe('#actions', () => {
describe('#validityCheck', () => {
@@ -28,7 +23,7 @@ describe('#actions', () => {
headers: { expiry: 581842904 },
});
await actions.validityCheck({ commit });
expect(setUser).toHaveBeenCalledTimes(1);
expect(APIHelpers.setUser).toHaveBeenCalledTimes(1);
expect(commit.mock.calls).toEqual([
[types.default.SET_CURRENT_USER, { id: 1, name: 'John' }],
]);
@@ -38,7 +33,7 @@ describe('#actions', () => {
response: { status: 401 },
});
await actions.validityCheck({ commit });
expect(clearCookiesOnLogout);
expect(APIHelpers.clearCookiesOnLogout);
});
});

View File

@@ -1,8 +1,5 @@
import { getters } from '../../auth';
import '../../../../routes';
jest.mock('../../../../routes', () => {});
describe('#getters', () => {
describe('#isLoggedIn', () => {
it('return correct value if user data is available', () => {