From 2430d9bd14a476766220f711913ad48a1cb38f05 Mon Sep 17 00:00:00 2001 From: Mantra Date: Tue, 5 Nov 2024 18:04:26 +0000 Subject: [PATCH 1/4] finish off unit tests --- app/static/eslint.config.js | 7 +++++++ .../translationPackage/tests/directive/translate.test.ts | 7 ++++--- .../translationPackage/tests/src/languageSwitcher.test.ts | 2 +- app/static/translationPackage/tests/store/actions.test.ts | 4 ++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/static/eslint.config.js b/app/static/eslint.config.js index a2ff07100..82b0022a4 100644 --- a/app/static/eslint.config.js +++ b/app/static/eslint.config.js @@ -29,6 +29,13 @@ export default [ } }, + { + files: ["**/tests/**/*.ts"], + rules: { + "vitest/expect-expect": "off" + } + }, + { ...pluginPlaywright.configs['flat/recommended'], files: ['e2e/**/*.{test,spec}.{js,ts,jsx,tsx}'], diff --git a/app/static/translationPackage/tests/directive/translate.test.ts b/app/static/translationPackage/tests/directive/translate.test.ts index ee2d95aa5..bd82af056 100644 --- a/app/static/translationPackage/tests/directive/translate.test.ts +++ b/app/static/translationPackage/tests/directive/translate.test.ts @@ -3,14 +3,15 @@ import Vuex from "vuex"; import registerTranslations from "../../registerTranslations"; import translate from "../../directive/translate"; import { nextTick } from "vue"; +import { Mock } from "vitest"; describe("translate directive", () => { beforeAll(() => { - console.warn = jest.fn(); + console.warn = vi.fn(); }); afterAll(() => { - (console.warn as jest.Mock).mockClear(); + (console.warn as Mock).mockClear(); }); const TranslateAttributeTest = { @@ -243,7 +244,7 @@ describe("translate directive", () => { } }); expect(rendered.find("h4").text()).toBe(""); - expect((console.warn as jest.Mock).mock.calls[0][0]).toBe("v-translate directive declared without a value"); + expect((console.warn as Mock).mock.calls[0][0]).toBe("v-translate directive declared without a value"); }); it("removes watcher on unbind", async () => { diff --git a/app/static/translationPackage/tests/src/languageSwitcher.test.ts b/app/static/translationPackage/tests/src/languageSwitcher.test.ts index 0a5fd1b1b..4f5f2eff7 100644 --- a/app/static/translationPackage/tests/src/languageSwitcher.test.ts +++ b/app/static/translationPackage/tests/src/languageSwitcher.test.ts @@ -3,7 +3,7 @@ import { shallowMount, mount } from "@vue/test-utils"; import LanguageSwitcher from "../../src/LanguageSwitcher.vue"; describe("languageSwitcher component", () => { - const mockUpdateLanguage = jest.fn(); + const mockUpdateLanguage = vi.fn(); const createStore = (enableI18n: boolean) => { return new Vuex.Store({ diff --git a/app/static/translationPackage/tests/store/actions.test.ts b/app/static/translationPackage/tests/store/actions.test.ts index 713de81ea..d1697c5d1 100644 --- a/app/static/translationPackage/tests/store/actions.test.ts +++ b/app/static/translationPackage/tests/store/actions.test.ts @@ -20,8 +20,8 @@ describe("Language actions", () => { }); it("UpdateLanguage commits change language mutation and i18next function", async () => { - const commit = jest.fn(); - const spyChangeLanguage = jest.spyOn(i18next, "changeLanguage"); + const commit = vi.fn(); + const spyChangeLanguage = vi.spyOn(i18next, "changeLanguage"); await (actions[LanguageAction.UpdateLanguage] as any)({ commit }, "fr"); expect(commit).toBeCalledTimes(1); expect(commit.mock.calls[0][0]).toBe(LanguageStateMutation.ChangeLanguage); From 3358a9a7bb7458f50d04192ea3377927c6d1f633 Mon Sep 17 00:00:00 2001 From: Mantra Date: Tue, 5 Nov 2024 18:05:55 +0000 Subject: [PATCH 2/4] update node version on github actions --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index efc5a6849..48cacded8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,7 +7,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: - node-version: 16.x + node-version: 20.x - name: Install dependencies run: npm install -g typescript codecov - name: Build From 2c0bfa6a6a92d7d321ccebbba92f410dc67fb263 Mon Sep 17 00:00:00 2001 From: Mantra Date: Tue, 5 Nov 2024 18:08:00 +0000 Subject: [PATCH 3/4] update server tests --- app/server/tests/controllers/appsController.test.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/server/tests/controllers/appsController.test.ts b/app/server/tests/controllers/appsController.test.ts index 0c27d2012..3a1ccb991 100644 --- a/app/server/tests/controllers/appsController.test.ts +++ b/app/server/tests/controllers/appsController.test.ts @@ -30,6 +30,7 @@ describe("appsController", () => { wodinConfig: { baseUrl: "http://localhost:3000", courseTitle: "Test Course Title", + hotReload: false, ...wodinConfig }, wodinVersion: "1.2.3" @@ -82,7 +83,8 @@ describe("appsController", () => { shareNotFound: "", mathjaxSrc, defaultLanguage: "en", - enableI18n: false + enableI18n: false, + hotReload: false }); expect(mockStatus).not.toBeCalled(); }); @@ -104,7 +106,8 @@ describe("appsController", () => { shareNotFound: "", mathjaxSrc, defaultLanguage: "en", - enableI18n: false + enableI18n: false, + hotReload: false }); }); @@ -130,7 +133,8 @@ describe("appsController", () => { shareNotFound: "", mathjaxSrc, defaultLanguage: "en", - enableI18n: false + enableI18n: false, + hotReload: false }); }); @@ -154,7 +158,8 @@ describe("appsController", () => { shareNotFound: "tiny-mouse", mathjaxSrc, defaultLanguage: "en", - enableI18n: false + enableI18n: false, + hotReload: false }); }); From 8b8eb9c1f67c302b0eb794b0ebd4a4821a172537 Mon Sep 17 00:00:00 2001 From: Mantra Date: Tue, 5 Nov 2024 18:10:33 +0000 Subject: [PATCH 4/4] fix server tests --- app/server/tests/controllers/appsController.test.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/server/tests/controllers/appsController.test.ts b/app/server/tests/controllers/appsController.test.ts index 3a1ccb991..ac1fe9ccf 100644 --- a/app/server/tests/controllers/appsController.test.ts +++ b/app/server/tests/controllers/appsController.test.ts @@ -30,7 +30,6 @@ describe("appsController", () => { wodinConfig: { baseUrl: "http://localhost:3000", courseTitle: "Test Course Title", - hotReload: false, ...wodinConfig }, wodinVersion: "1.2.3" @@ -84,7 +83,7 @@ describe("appsController", () => { mathjaxSrc, defaultLanguage: "en", enableI18n: false, - hotReload: false + hotReload: undefined }); expect(mockStatus).not.toBeCalled(); }); @@ -107,7 +106,7 @@ describe("appsController", () => { mathjaxSrc, defaultLanguage: "en", enableI18n: false, - hotReload: false + hotReload: undefined }); }); @@ -134,7 +133,7 @@ describe("appsController", () => { mathjaxSrc, defaultLanguage: "en", enableI18n: false, - hotReload: false + hotReload: undefined }); }); @@ -159,7 +158,7 @@ describe("appsController", () => { mathjaxSrc, defaultLanguage: "en", enableI18n: false, - hotReload: false + hotReload: undefined }); });