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

@@ -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));
});