Skip to content

Commit

Permalink
Fixed unit-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSimCity committed May 17, 2023
1 parent c318d2d commit fad1169
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 102 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ jobs:
run: pnpm install
- name: Run linters
run: pnpm lint
# - name: Test and create coverage
# run: pnpm coverage
# - name: Upload coverage reports to Codecov
# uses: codecov/codecov-action@v3
- name: Test and create coverage
run: pnpm coverage
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
- name: Build for production
run: pnpm generate
- name: E2E testing
Expand Down Expand Up @@ -56,11 +56,11 @@ jobs:
with:
name: dist
path: .output/public
# - name: Archive code coverage results
# uses: actions/upload-artifact@v3
# with:
# name: code-coverage-report
# path: coverage
- name: Archive code coverage results
uses: actions/upload-artifact@v3
with:
name: code-coverage-report
path: coverage

deploy_azure_static_web_apps:
runs-on: ubuntu-latest
Expand Down
5 changes: 1 addition & 4 deletions components/ProtectedImage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

import { describe, it, expect } from "vitest";
import { flushPromises, mount } from "@vue/test-utils";
import { setup } from "@nuxt/test-utils";
import { AUTH0_INJECTION_KEY, Auth0VueClient } from "@auth0/auth0-vue";
import ProtectedImage from "./ProtectedImage.vue";

describe("component ProtectedImage", async () => {
await setup({});

describe("component ProtectedImage", () => {
it("should add the access token to the given path", async () => {
// Arrange
const src = "http://localhost/image.jpg";
Expand Down
54 changes: 24 additions & 30 deletions components/playlist/PlaylistOverview.spec.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,37 @@
// @vitest-environment happy-dom

import { PlaylistApi } from "@bcc-code/bmm-sdk-fetch";
import { describe, it, expect, vi, afterEach } from "vitest";
import { PlaylistModel } from "@bcc-code/bmm-sdk-fetch";
import { describe, it, expect } from "vitest";
import { RouterLinkStub, flushPromises, mount } from "@vue/test-utils";
import { setup } from "@nuxt/test-utils";
import PlaylistOverview from "./PlaylistOverview.vue";

describe("component PlaylistOverview", async () => {
await setup({});

afterEach(() => {
vi.clearAllMocks();
});

describe("component PlaylistOverview", () => {
it("should list the playlists in the order given by the api", async () => {
// Arrange
vi.spyOn(PlaylistApi.prototype, "playlistGet").mockReturnValueOnce(
Promise.resolve([
{
id: 10,
type: "playlist",
title: "TestSamplePlaylist1",
},
{
id: 12,
type: "playlist",
title: "TestSamplePlaylist2",
},
{
id: 11,
type: "playlist",
title: "TestSamplePlaylist3",
},
])
);
const playlists: PlaylistModel[] = [
{
id: 10,
type: "playlist",
title: "TestSamplePlaylist1",
},
{
id: 12,
type: "playlist",
title: "TestSamplePlaylist2",
},
{
id: 11,
type: "playlist",
title: "TestSamplePlaylist3",
},
];

// Act
const wrapper = mount(PlaylistOverview, {
global: { stubs: { RouterLink: RouterLinkStub } },
props: {
playlists,
},
global: { stubs: { NuxtLink: RouterLinkStub } },
});
await flushPromises();

Expand Down
1 change: 1 addition & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const modules: (string | any)[] = [
"./modules/figma2tailwind", // Must be placed before "@nuxtjs/tailwindcss"
"@nuxtjs/tailwindcss",
"@nuxtjs/i18n",
"nuxt-vitest",
["@pinia/nuxt", { autoImports: ["defineStore"] }],
];

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"@intlify/eslint-plugin-vue-i18n": "^2.0.0",
"@nuxt/devtools": "^0.4.1",
"@nuxt/kit": "^3.4.3",
"@nuxt/test-utils": "^3.4.2",
"@nuxtjs/eslint-config-typescript": "^12.0.0",
"@nuxtjs/i18n": "8.0.0-beta.10",
"@nuxtjs/tailwindcss": "^6.6.6",
Expand All @@ -45,6 +44,7 @@
"nuxt": "^3.4.1",
"nuxt-electron": "^0.4.5",
"nuxt-typed-router": "^3.2.0",
"nuxt-vitest": "^0.7.0",
"prettier": "^2.8.7",
"prettier-plugin-tailwindcss": "^0.2.7",
"stylelint": "^15.5.0",
Expand Down
Loading

0 comments on commit fad1169

Please sign in to comment.