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:
@@ -4,8 +4,8 @@ import Vuex from 'vuex';
|
||||
import OpenAPI from '../../api/integrations/openapi';
|
||||
import { LocalStorage } from '../../../shared/helpers/localStorage';
|
||||
|
||||
jest.mock('../../api/integrations/openapi');
|
||||
jest.mock('../../../shared/helpers/localStorage');
|
||||
vi.mock('../../api/integrations/openapi');
|
||||
vi.mock('../../../shared/helpers/localStorage');
|
||||
|
||||
const localVue = createLocalVue();
|
||||
localVue.use(Vuex);
|
||||
@@ -18,12 +18,12 @@ describe('aiMixin', () => {
|
||||
let actions;
|
||||
|
||||
beforeEach(() => {
|
||||
OpenAPI.processEvent = jest.fn();
|
||||
LocalStorage.set = jest.fn();
|
||||
LocalStorage.get = jest.fn();
|
||||
OpenAPI.processEvent = vi.fn();
|
||||
LocalStorage.set = vi.fn();
|
||||
LocalStorage.get = vi.fn();
|
||||
|
||||
actions = {
|
||||
['integrations/get']: jest.fn(),
|
||||
['integrations/get']: vi.fn(),
|
||||
};
|
||||
|
||||
getters = {
|
||||
@@ -63,20 +63,20 @@ describe('aiMixin', () => {
|
||||
localVue,
|
||||
});
|
||||
|
||||
const dispatchSpy = jest.spyOn(wrapper.vm.$store, 'dispatch');
|
||||
const dispatchSpy = vi.spyOn(wrapper.vm.$store, 'dispatch');
|
||||
await wrapper.vm.fetchIntegrationsIfRequired();
|
||||
expect(dispatchSpy).toHaveBeenCalledWith('integrations/get');
|
||||
});
|
||||
|
||||
it('does not fetch integrations', async () => {
|
||||
const dispatchSpy = jest.spyOn(wrapper.vm.$store, 'dispatch');
|
||||
const dispatchSpy = vi.spyOn(wrapper.vm.$store, 'dispatch');
|
||||
await wrapper.vm.fetchIntegrationsIfRequired();
|
||||
expect(dispatchSpy).not.toHaveBeenCalledWith('integrations/get');
|
||||
expect(wrapper.vm.isAIIntegrationEnabled).toBeTruthy();
|
||||
});
|
||||
|
||||
it('fetches label suggestions', async () => {
|
||||
const processEventSpy = jest.spyOn(OpenAPI, 'processEvent');
|
||||
const processEventSpy = vi.spyOn(OpenAPI, 'processEvent');
|
||||
await wrapper.vm.fetchLabelSuggestions({
|
||||
conversationId: '123',
|
||||
});
|
||||
|
||||
@@ -11,7 +11,7 @@ describe('attributeMixin', () => {
|
||||
let store;
|
||||
|
||||
beforeEach(() => {
|
||||
actions = { updateUISettings: jest.fn(), toggleSidebarUIState: jest.fn() };
|
||||
actions = { updateUISettings: vi.fn(), toggleSidebarUIState: vi.fn() };
|
||||
getters = {
|
||||
getSelectedChat: () => ({
|
||||
id: 7165,
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import fileUploadMixin from 'dashboard/mixins/fileUploadMixin';
|
||||
import Vue from 'vue';
|
||||
|
||||
jest.mock('shared/helpers/FileHelper', () => ({
|
||||
checkFileSizeLimit: jest.fn(),
|
||||
vi.mock('shared/helpers/FileHelper', () => ({
|
||||
checkFileSizeLimit: vi.fn(),
|
||||
}));
|
||||
|
||||
jest.mock('activestorage', () => ({
|
||||
DirectUpload: jest.fn().mockImplementation(() => ({
|
||||
create: jest.fn(),
|
||||
vi.mock('activestorage', () => ({
|
||||
DirectUpload: vi.fn().mockImplementation(() => ({
|
||||
create: vi.fn(),
|
||||
})),
|
||||
}));
|
||||
|
||||
@@ -27,20 +27,20 @@ describe('FileUploadMixin', () => {
|
||||
vm.currentUser = {
|
||||
access_token: 'token',
|
||||
};
|
||||
vm.$t = jest.fn(message => message);
|
||||
vm.showAlert = jest.fn();
|
||||
vm.attachFile = jest.fn();
|
||||
vm.$t = vi.fn(message => message);
|
||||
vm.showAlert = vi.fn();
|
||||
vm.attachFile = vi.fn();
|
||||
});
|
||||
|
||||
it('should call onDirectFileUpload when direct uploads are enabled', () => {
|
||||
vm.onDirectFileUpload = jest.fn();
|
||||
vm.onDirectFileUpload = vi.fn();
|
||||
vm.onFileUpload({});
|
||||
expect(vm.onDirectFileUpload).toHaveBeenCalledWith({});
|
||||
});
|
||||
|
||||
it('should call onIndirectFileUpload when direct uploads are disabled', () => {
|
||||
vm.globalConfig.directUploadsEnabled = false;
|
||||
vm.onIndirectFileUpload = jest.fn();
|
||||
vm.onIndirectFileUpload = vi.fn();
|
||||
vm.onFileUpload({});
|
||||
expect(vm.onIndirectFileUpload).toHaveBeenCalledWith({});
|
||||
});
|
||||
@@ -53,7 +53,7 @@ describe('FileUploadMixin', () => {
|
||||
|
||||
it('shows an alert if the file size exceeds the maximum limit', () => {
|
||||
const fakeFile = { size: 999999999 };
|
||||
vm.showAlert = jest.fn();
|
||||
vm.showAlert = vi.fn();
|
||||
vm.onDirectFileUpload(fakeFile);
|
||||
expect(vm.showAlert).toHaveBeenCalledWith(expect.any(String));
|
||||
});
|
||||
@@ -67,7 +67,7 @@ describe('FileUploadMixin', () => {
|
||||
|
||||
it('shows an alert if the file size exceeds the maximum limit', () => {
|
||||
const fakeFile = { size: 999999999 };
|
||||
vm.showAlert = jest.fn();
|
||||
vm.showAlert = vi.fn();
|
||||
vm.onIndirectFileUpload(fakeFile);
|
||||
expect(vm.showAlert).toHaveBeenCalledWith(expect.any(String));
|
||||
});
|
||||
|
||||
@@ -11,14 +11,14 @@ describe('#messageStamp', () => {
|
||||
|
||||
describe('#messageTimestamp', () => {
|
||||
beforeEach(() => {
|
||||
jest.useFakeTimers('modern');
|
||||
vi.useFakeTimers('modern');
|
||||
|
||||
const mockDate = new Date(2023, 4, 5);
|
||||
jest.setSystemTime(mockDate);
|
||||
vi.setSystemTime(mockDate);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.useRealTimers();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it('should return the message date in the specified format if the message was sent in the current year', () => {
|
||||
@@ -35,7 +35,7 @@ describe('#messageTimestamp', () => {
|
||||
|
||||
describe('#dynamicTime', () => {
|
||||
it('returns correct value', () => {
|
||||
Date.now = jest.fn(() => new Date(Date.UTC(2023, 1, 14)).valueOf());
|
||||
Date.now = vi.fn(() => new Date(Date.UTC(2023, 1, 14)).valueOf());
|
||||
expect(TimeMixin.methods.dynamicTime(1612971343)).toEqual(
|
||||
'about 2 years ago'
|
||||
);
|
||||
|
||||
@@ -14,7 +14,7 @@ describe('uiSettingsMixin', () => {
|
||||
let store;
|
||||
|
||||
beforeEach(() => {
|
||||
actions = { updateUISettings: jest.fn(), toggleSidebarUIState: jest.fn() };
|
||||
actions = { updateUISettings: vi.fn(), toggleSidebarUIState: vi.fn() };
|
||||
getters = {
|
||||
getUISettings: () => ({
|
||||
enter_to_send_enabled: false,
|
||||
|
||||
Reference in New Issue
Block a user