Skip to content

Commit

Permalink
started jest to vitest migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Ruf committed Aug 1, 2024
1 parent 36f71ca commit 867d521
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/Resources/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"dev": "vite",
"build": "run-p type-check \"build-only {@}\" --",
"test:unit": "vitest",
"test:unit": "vitest run",
"build-only": "vite build",
"type-check": "vue-tsc --build --force",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import { vi } from 'vitest';
import { computed } from 'vue';

jest.mock('vue-i18n', () => ({
vi.mock('vue-i18n', () => ({
useI18n: () => ({
t: (key: string) => key,
locale: computed(() => 'en')
})
}));

jest.mock('@marcoschulte/vue3-progress', () => ({
vi.mock('@marcoschulte/vue3-progress', () => ({
useProgress: () => ({
start: () => ({
finish: () => void 0
})
})
}));

jest.mock('vue-router', () => ({
vi.mock('vue-router', () => ({
useRouter: () => ({
push: () => void 0
})
}));

jest.mock('tools/mercureReceiver', () => ({
vi.mock('tools/mercureReceiver', () => ({
mercureReceiver: {
init: async () => new Promise((resolve) => resolve(undefined))
}
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/tests/unit/stores/participationsStore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ref } from 'vue';
import Participations from '../fixtures/menuParticipations.json';
import Update from '../fixtures/participationUpdateResponse.json';
import { IProfile } from '@/stores/profilesStore';
import { describe, beforeEach, it, expect, vi } from 'vitest';

const asyncFunc: () => Promise<void> = async () => {
new Promise((resolve) => resolve(undefined));
Expand Down Expand Up @@ -33,7 +34,7 @@ const getMockedResponses = (method: string, url: string) => {

// @ts-expect-error ts doesn't allow reassignig a import but we need that to mock that function
// eslint-disable-next-line @typescript-eslint/no-unused-vars
useApi = jest.fn().mockImplementation((method: string, url: string) => getMockedResponses(method, url));
useApi = vi.fn().mockImplementation((method: string, url: string) => getMockedResponses(method, url));

describe('Test participationsStore', () => {
const {
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/tests/unit/stores/profilesStore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import useApi from '@/api/api';
import { ref } from 'vue';
import Profiles from '../fixtures/abstaining.json';
import HashedProfile from '../fixtures/hashProfile.json';
import { describe, it, expect, vi } from 'vitest';

const WEEK_ID = 123;

Expand All @@ -28,7 +29,7 @@ const getMockedResponses = (method: string, url: string) => {

// @ts-expect-error ts doesn't allow reassignig a import but we need that to mock that function
// eslint-disable-next-line @typescript-eslint/no-unused-vars
useApi = jest.fn().mockImplementation((method: string, url: string) => getMockedResponses(method, url));
useApi = vi.fn().mockImplementation((method: string, url: string) => getMockedResponses(method, url));

describe('Test profilesStore', () => {
it('should not contain data before fetching', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/tests/unit/stores/timeSlotStore.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useTimeSlots } from '@/stores/timeSlotStore';
import { beforeEach, describe } from '@jest/globals';
import { ref } from 'vue';
import updatedSlot from '../fixtures/updatedSlot.json';
import timeSlots from '../fixtures/getTimeSlots.json';
import useApi from '@/api/api';
import { describe, beforeEach, it, expect } from 'vitest';

const asyncFunc: () => Promise<void> = async () => {
new Promise((resolve) => resolve(undefined));
Expand Down
1 change: 1 addition & 0 deletions src/Resources/tests/unit/stores/weeksStore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import useApi from '@/api/api';
import { ref } from 'vue';
import Weeks from '../fixtures/getWeeks.json';
import DishesCount from '../fixtures/dishesCount.json';
import { describe, beforeEach, it, expect } from 'vitest';

const asyncFunc: () => Promise<void> = async () => {
new Promise((resolve) => resolve(undefined));
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/tests/unit/timeslots/SlotActions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SlotActions from '@/components/timeslots/SlotActions.vue';
import { describe, expect, it } from '@jest/globals';
import { mount } from '@vue/test-utils';
import { TimeSlot } from '@/stores/timeSlotStore';
import { describe, it, expect } from 'vitest';

const timeSlot: TimeSlot = {
title: 'TestSlot 1234',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SlotCreationPanel from '@/components/timeslots/SlotCreationPanel.vue';
import InputLabel from '@/components/misc/InputLabel.vue';
import { describe, it } from '@jest/globals';
import { mount } from '@vue/test-utils';
import { describe, it, expect } from 'vitest';

describe('Test SlotCreationPanel', () => {
it('should contain a header, three InputLbel-components and a separate input field', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/tests/unit/timeslots/SlotHeader.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect } from '@jest/globals';
import { mount } from '@vue/test-utils';
import CreateButton from '@/components/misc/CreateButton.vue';
import SlotHeader from '@/components/timeslots/SlotHeader.vue';
import { describe, it, expect } from 'vitest';

describe('Test SlotHeader', () => {
it('should have a Header with the correct i18n text', () => {
Expand Down
7 changes: 4 additions & 3 deletions src/Resources/tests/unit/tools/localeHelper.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DateTime } from '@/api/getDashboardData';
import { translateWeekday, translateWeekdayWithoutRef, translateMonth } from '@/tools/localeHelper';
import { describe, beforeAll, afterAll, it, expect, vi } from 'vitest';
import { computed, ref } from 'vue';

const dateTime: DateTime = {
Expand All @@ -20,12 +21,12 @@ const computedLocale = computed({

describe('Test localeHelper', () => {
beforeAll(() => {
jest.useFakeTimers();
jest.setSystemTime(new Date(2023, 3, 15));
vi.useFakeTimers();
vi.setSystemTime(new Date(2023, 3, 15));
});

afterAll(() => {
jest.useRealTimers();
vi.useRealTimers();
});

it('should return the correct weekday representation', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/tests/unit/unitTestsFunctional.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { mount, shallowMount } from '@vue/test-utils';
import { test, expect, describe } from '@jest/globals';
import Footer from '@/components/Footer.vue';
import HelloTest from '@/components/test/HelloTest.vue';
import { computed } from 'vue';
import { describe, expect, test, vi } from 'vitest';

const MessageComponent = {
template: '<p>{{ msg }}</p>',
props: ['msg']
};

jest.mock('vue-i18n', () => ({
vi.mock('vue-i18n', () => ({
useI18n: () => ({
t: (key: string) => key,
locale: computed(() => 'en')
Expand Down
1 change: 1 addition & 0 deletions src/Resources/tests/unit/week/WeekOverview.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import WeekOverview from '@/components/weeks/WeekOverview.vue';
import { Week } from '@/stores/weeksStore';
import { mount } from '@vue/test-utils';
import { describe, it, expect } from 'vitest';

const weekOne: Week = {
id: 57,
Expand Down
8 changes: 7 additions & 1 deletion src/Resources/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ export default mergeConfig(
test: {
environment: 'jsdom',
exclude: [...configDefaults.exclude, 'e2e/**'],
root: fileURLToPath(new URL('./', import.meta.url))
root: fileURLToPath(new URL('./', import.meta.url)),
setupFiles: './tests/unit/setup-vi.ts'
},
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
}
})
)

0 comments on commit 867d521

Please sign in to comment.