WIP: feat: update_vitest_version to 2.0.0 #1127

Draft
jsegarra wants to merge 3 commits from update_vitest_version into dev
25 changed files with 235 additions and 577 deletions

View File

@ -51,7 +51,7 @@
"husky": "^8.0.0", "husky": "^8.0.0",
"postcss": "^8.4.23", "postcss": "^8.4.23",
"prettier": "^2.8.8", "prettier": "^2.8.8",
"vitest": "^0.31.1" "vitest": "^2.0.0"
}, },
"engines": { "engines": {
"node": "^20 || ^18 || ^16", "node": "^20 || ^18 || ^16",

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,6 @@
import { vi, describe, expect, it, beforeAll } from 'vitest'; import { vi, describe, expect, it, beforeAll } from 'vitest';
import { createWrapper, axios } from 'app/test/vitest/helper'; import axios from 'axios';
import { createWrapper } from 'app/test/vitest/helper';
import Leftmenu from 'components/LeftMenu.vue'; import Leftmenu from 'components/LeftMenu.vue';
import { useNavigationStore } from 'src/stores/useNavigationStore'; import { useNavigationStore } from 'src/stores/useNavigationStore';

View File

@ -1,4 +1,5 @@
import { createWrapper, axios } from 'app/test/vitest/helper'; import axios from 'axios';
import { createWrapper } from 'app/test/vitest/helper';
import VnChangePassword from 'src/components/common/VnChangePassword.vue'; import VnChangePassword from 'src/components/common/VnChangePassword.vue';
import { vi, beforeEach, afterEach, beforeAll, describe, expect, it } from 'vitest'; import { vi, beforeEach, afterEach, beforeAll, describe, expect, it } from 'vitest';
import { Notify } from 'quasar'; import { Notify } from 'quasar';

View File

@ -1,5 +1,6 @@
import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest'; import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest';
import { createWrapper, axios } from 'app/test/vitest/helper'; import axios from 'axios';
import { createWrapper } from 'app/test/vitest/helper';
import VnLog from 'src/components/common/VnLog.vue'; import VnLog from 'src/components/common/VnLog.vue';
describe('VnLog', () => { describe('VnLog', () => {

View File

@ -1,5 +1,6 @@
import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest'; import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest';
import { createWrapper, axios } from 'app/test/vitest/helper'; import axios from 'axios';
import { createWrapper } from 'app/test/vitest/helper';
import VnPaginate from 'src/components/ui/VnPaginate.vue'; import VnPaginate from 'src/components/ui/VnPaginate.vue';
describe('VnPaginate', () => { describe('VnPaginate', () => {

View File

@ -1,5 +1,5 @@
import { describe, it, expect, beforeAll, vi } from 'vitest'; import { describe, it, expect, beforeAll, vi } from 'vitest';
import { axios } from 'app/test/vitest/helper'; import axios from 'axios';
import parsePhone from 'src/filters/parsePhone'; import parsePhone from 'src/filters/parsePhone';
describe('parsePhone filter', () => { describe('parsePhone filter', () => {

View File

@ -1,5 +1,6 @@
import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest'; import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest';
import { createWrapper, axios } from 'app/test/vitest/helper'; import axios from 'axios';
import { createWrapper } from 'app/test/vitest/helper';
import VnSms from 'src/components/ui/VnSms.vue'; import VnSms from 'src/components/ui/VnSms.vue';
describe('VnSms', () => { describe('VnSms', () => {

View File

@ -1,5 +1,5 @@
import { vi, describe, expect, it, beforeAll, afterAll } from 'vitest'; import { vi, describe, expect, it, beforeAll, afterAll } from 'vitest';
import { axios } from 'app/test/vitest/helper'; import axios from 'axios';
import { downloadFile } from 'src/composables/downloadFile'; import { downloadFile } from 'src/composables/downloadFile';
import { useSession } from 'src/composables/useSession'; import { useSession } from 'src/composables/useSession';
const session = useSession(); const session = useSession();

View File

@ -1,5 +1,7 @@
import { vi, describe, expect, it, beforeAll, afterAll } from 'vitest'; import { vi, describe, expect, it, beforeAll, afterAll } from 'vitest';
import { axios, flushPromises } from 'app/test/vitest/helper'; import axios from 'axios';
import { flushPromises } from '@vue/test-utils';
import { useAcl } from 'src/composables/useAcl'; import { useAcl } from 'src/composables/useAcl';
describe('useAcl', () => { describe('useAcl', () => {

View File

@ -1,5 +1,6 @@
import { describe, expect, it, beforeEach, afterEach, vi } from 'vitest'; import { describe, expect, it, beforeEach, afterEach, vi } from 'vitest';
import { axios, flushPromises } from 'app/test/vitest/helper'; import axios from 'axios';
import { flushPromises } from 'app/test/vitest/helper';
import { useArrayData } from 'composables/useArrayData'; import { useArrayData } from 'composables/useArrayData';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import * as vueRouter from 'vue-router'; import * as vueRouter from 'vue-router';
@ -25,8 +26,8 @@ describe('useArrayData', () => {
arrayData.fetch({}); arrayData.fetch({});
await flushPromises(); await flushPromises();
const routerReplace = useRouter().replace.mock.calls[0][0]; let routerReplace = useRouter().replace;
routerReplace = routerReplace.mock.calls[0][0];
expect(axios.get.mock.calls[0][1].params).toEqual({ expect(axios.get.mock.calls[0][1].params).toEqual({
filter, filter,
supplierFk: 2, supplierFk: 2,

View File

@ -1,5 +1,6 @@
import { vi, describe, expect, it } from 'vitest'; import { vi, describe, expect, it } from 'vitest';
import { axios, flushPromises } from 'app/test/vitest/helper'; import axios from 'axios';
import { flushPromises } from '@vue/test-utils';
import { useRole } from 'composables/useRole'; import { useRole } from 'composables/useRole';
const role = useRole(); const role = useRole();
@ -31,10 +32,9 @@ describe('useRole', () => {
lang: 'en', lang: 'en',
}; };
const expectedRoles = ['salesPerson', 'admin']; const expectedRoles = ['salesPerson', 'admin'];
vi.spyOn(axios, 'get') vi.spyOn(axios, 'get').mockResolvedValueOnce({
.mockResolvedValueOnce({
data: { roles: rolesData, user: fetchedUser }, data: { roles: rolesData, user: fetchedUser },
}) });
vi.spyOn(role.state, 'setUser'); vi.spyOn(role.state, 'setUser');
vi.spyOn(role.state, 'setRoles'); vi.spyOn(role.state, 'setRoles');

View File

@ -1,5 +1,5 @@
import { vi, describe, expect, it, beforeAll, beforeEach } from 'vitest'; import { vi, describe, expect, it, beforeAll, beforeEach } from 'vitest';
import { axios } from 'app/test/vitest/helper'; import axios from 'axios';
import { useSession } from 'composables/useSession'; import { useSession } from 'composables/useSession';
import { useState } from 'composables/useState'; import { useState } from 'composables/useState';

View File

@ -1,5 +1,6 @@
import { vi, describe, expect, it } from 'vitest'; import { vi, describe, expect, it } from 'vitest';
import { axios, flushPromises } from 'app/test/vitest/helper'; import axios from 'axios';
import { flushPromises } from '@vue/test-utils';
import { useTokenConfig } from 'composables/useTokenConfig'; import { useTokenConfig } from 'composables/useTokenConfig';
const tokenConfig = useTokenConfig(); const tokenConfig = useTokenConfig();

View File

@ -1,5 +1,6 @@
import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest'; import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest';
import { createWrapper, axios } from 'app/test/vitest/helper'; import axios from 'axios';
import { createWrapper } from 'app/test/vitest/helper';
import ClaimDescriptorMenu from 'pages/Claim/Card/ClaimDescriptorMenu.vue'; import ClaimDescriptorMenu from 'pages/Claim/Card/ClaimDescriptorMenu.vue';
describe('ClaimDescriptorMenu', () => { describe('ClaimDescriptorMenu', () => {

View File

@ -1,5 +1,6 @@
import { vi, describe, expect, it, beforeAll, beforeEach, afterEach } from 'vitest'; import { vi, describe, expect, it, beforeAll, beforeEach, afterEach } from 'vitest';
import { createWrapper, axios } from 'app/test/vitest/helper'; import axios from 'axios';
import { createWrapper } from 'app/test/vitest/helper';
import ClaimLines from '/src/pages/Claim/Card/ClaimLines.vue'; import ClaimLines from '/src/pages/Claim/Card/ClaimLines.vue';
describe('ClaimLines', () => { describe('ClaimLines', () => {

View File

@ -1,5 +1,6 @@
import { vi, describe, expect, it, beforeAll, beforeEach, afterEach } from 'vitest'; import { vi, describe, expect, it, beforeAll, beforeEach, afterEach } from 'vitest';
import { createWrapper, axios } from 'app/test/vitest/helper'; import axios from 'axios';
import { createWrapper } from 'app/test/vitest/helper';
import ClaimLinesImport from 'pages/Claim/Card/ClaimLinesImport.vue'; import ClaimLinesImport from 'pages/Claim/Card/ClaimLinesImport.vue';
describe('ClaimLinesImport', () => { describe('ClaimLinesImport', () => {

View File

@ -1,7 +1,7 @@
import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest'; import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest';
import { createWrapper, axios } from 'app/test/vitest/helper'; import axios from 'axios';
import { createWrapper } from 'app/test/vitest/helper';
import ClaimPhoto from 'pages/Claim/Card/ClaimPhoto.vue'; import ClaimPhoto from 'pages/Claim/Card/ClaimPhoto.vue';
describe('ClaimPhoto', () => { describe('ClaimPhoto', () => {
let vm; let vm;
@ -61,7 +61,7 @@ describe('ClaimPhoto', () => {
title: 'This file will be deleted', title: 'This file will be deleted',
icon: 'delete', icon: 'delete',
data: { index: 1 }, data: { index: 1 },
promise: vm.deleteDms promise: vm.deleteDms,
}, },
}) })
); );

View File

@ -1,5 +1,6 @@
import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest'; import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest';
import { createWrapper, axios } from 'app/test/vitest/helper'; import axios from 'axios';
import { createWrapper } from 'app/test/vitest/helper';
import CustomerPayments from 'src/pages/Customer/Payments/CustomerPayments.vue'; import CustomerPayments from 'src/pages/Customer/Payments/CustomerPayments.vue';
describe('CustomerPayments', () => { describe('CustomerPayments', () => {

View File

@ -1,6 +1,7 @@
import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest'; import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest';
import { createWrapper, axios } from 'app/test/vitest/helper'; import { createWrapper } from 'app/test/vitest/helper';
import Login from 'pages/Login/LoginMain.vue'; import Login from 'pages/Login/LoginMain.vue';
import axios from 'axios';
describe('Login', () => { describe('Login', () => {
let vm; let vm;

View File

@ -1,5 +1,6 @@
import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest'; import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest';
import { createWrapper, axios } from 'app/test/vitest/helper'; import axios from 'axios';
import { createWrapper } from 'app/test/vitest/helper';
import TicketBoxing from 'pages/Ticket/Card/TicketBoxing.vue'; import TicketBoxing from 'pages/Ticket/Card/TicketBoxing.vue';
// #4836 - Investigate how to test q-drawer outside // #4836 - Investigate how to test q-drawer outside
@ -21,7 +22,11 @@ describe('TicketBoxing', () => {
min: 1, min: 1,
max: 2, max: 2,
}; };
const videoList = ['2022-01-01T01-01-00.mp4', '2022-02-02T02-02-00.mp4', '2022-03-03T03-03-00.mp4']; const videoList = [
'2022-01-01T01-01-00.mp4',
'2022-02-02T02-02-00.mp4',
'2022-03-03T03-03-00.mp4',
];
vi.spyOn(axios, 'get').mockResolvedValue({ data: videoList }); vi.spyOn(axios, 'get').mockResolvedValue({ data: videoList });
vi.spyOn(vm.quasar, 'notify'); vi.spyOn(vm.quasar, 'notify');
@ -44,7 +49,9 @@ describe('TicketBoxing', () => {
await vm.getVideoList(expeditionId, timed); await vm.getVideoList(expeditionId, timed);
expect(vm.quasar.notify).toHaveBeenCalledWith(expect.objectContaining({ type: 'negative' })); expect(vm.quasar.notify).toHaveBeenCalledWith(
expect.objectContaining({ type: 'negative' })
);
}); });
}); });
}); });

View File

@ -1,5 +1,6 @@
import { vi, describe, expect, it, beforeAll, afterEach, beforeEach } from 'vitest'; import { vi, describe, expect, it, beforeAll, afterEach, beforeEach } from 'vitest';
import { createWrapper, axios } from 'app/test/vitest/helper'; import axios from 'axios';
import { createWrapper } from 'app/test/vitest/helper';
import TicketAdvance from 'pages/Ticket/TicketAdvance.vue'; import TicketAdvance from 'pages/Ticket/TicketAdvance.vue';
import { Notify } from 'quasar'; import { Notify } from 'quasar';
import { nextTick } from 'vue'; import { nextTick } from 'vue';

View File

@ -1,5 +1,6 @@
import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest'; import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest';
import { createWrapper, axios } from 'app/test/vitest/helper'; import axios from 'axios';
import { createWrapper } from 'app/test/vitest/helper';
import WagonCreate from 'pages/Wagon/WagonCreate.vue'; import WagonCreate from 'pages/Wagon/WagonCreate.vue';
describe('WagonCreate', () => { describe('WagonCreate', () => {

View File

@ -4,7 +4,6 @@ import { createTestingPinia } from '@pinia/testing';
import { vi } from 'vitest'; import { vi } from 'vitest';
import { i18n } from 'src/boot/i18n'; import { i18n } from 'src/boot/i18n';
import { Notify, Dialog } from 'quasar'; import { Notify, Dialog } from 'quasar';
import axios from 'axios';
import * as useValidator from 'src/composables/useValidator'; import * as useValidator from 'src/composables/useValidator';
installQuasarPlugin({ installQuasarPlugin({
@ -14,35 +13,6 @@ installQuasarPlugin({
}, },
}); });
const pinia = createTestingPinia({ createSpy: vi.fn, stubActions: false }); const pinia = createTestingPinia({ createSpy: vi.fn, stubActions: false });
const mockPush = vi.fn();
const mockReplace = vi.fn();
vi.mock('vue-router', () => ({
useRouter: () => ({
push: mockPush,
replace: mockReplace,
currentRoute: {
value: {
params: {
id: 1,
},
meta: { moduleName: 'mockName' },
matched: [{ path: 'mockName/list' }],
},
},
}),
useRoute: () => ({
matched: [],
query: {},
params: {},
meta: { moduleName: 'mockName' },
path: 'mockSection/list',
}),
onBeforeRouteLeave: () => {},
}));
vi.mock('axios');
vi.spyOn(useValidator, 'useValidator').mockImplementation(() => { vi.spyOn(useValidator, 'useValidator').mockImplementation(() => {
return { return {
validate: vi.fn(), validate: vi.fn(),
@ -112,5 +82,4 @@ export function createWrapper(component, options) {
return { vm, wrapper }; return { vm, wrapper };
} }
export { flushPromises };
export { axios, flushPromises };

View File

@ -1 +1,27 @@
// This file will be run before each test file, don't delete or vitest will not work. // This file will be run before each test file, don't delete or vitest will not work.
import { vi } from 'vitest';
vi.mock('axios');
vi.mock('vue-router', () => ({
useRouter: () => ({
push: vi.fn(),
replace: vi.fn(),
currentRoute: {
value: {
params: {
id: 1,
},
meta: { moduleName: 'mockName' },
matched: [{ path: 'mockName/list' }],
},
},
}),
useRoute: () => ({
matched: [],
query: {},
params: {},
meta: { moduleName: 'mockName' },
path: 'mockSection/list',
}),
onBeforeRouteLeave: () => {},
}));