Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade vitest and some related packages #3482

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion @navikt/aksel-icons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@
"tsx": "^4.7.1",
"typescript": "5.5.4",
"unified": "10.1.2",
"vitest": "^1.2.2"
"vitest": "^2.1.8"
}
}
2 changes: 1 addition & 1 deletion @navikt/aksel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"devDependencies": {
"rimraf": "6.0.1",
"typescript": "5.5.4",
"vitest": "^1.2.2"
"vitest": "^2.1.8"
},
"sideEffects": false,
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion @navikt/core/css/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"postcss-combine-duplicated-selectors": "10.0.3",
"postcss-import": "^14.1.0",
"tsx": "^4.7.1",
"vitest": "^1.2.2"
"vitest": "^2.1.8"
},
"browserslist": [
">0.2%",
Expand Down
12 changes: 6 additions & 6 deletions @navikt/core/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -622,23 +622,23 @@
"react-day-picker": "8.10.1"
},
"devDependencies": {
"@testing-library/dom": "9.3.4",
"@testing-library/jest-dom": "^5.16.0",
"@testing-library/react": "^15.0.7",
"@testing-library/user-event": "^14.2.0",
"@testing-library/dom": "10.4.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.1.0",
"@testing-library/user-event": "^14.5.2",
"@types/jscodeshift": "^0.11.11",
"concurrently": "9.0.1",
"fast-glob": "3.2.11",
"jscodeshift": "^0.15.1",
"jsdom": "24.0.0",
"jsdom": "25.0.1",
"react-dom": "^18.0.0",
"react-router-dom": "^6.3.0",
"rimraf": "6.0.1",
"swr": "^1.1.2",
"tsc-alias": "1.8.8",
"tsx": "^4.19.1",
"typescript": "5.5.4",
"vitest": "^1.2.2"
"vitest": "^2.1.8"
},
"peerDependencies": {
"@types/react": ">=17.0.30",
Expand Down
7 changes: 2 additions & 5 deletions @navikt/core/react/src/date/datepicker/datepicker.test.tsx
Copy link
Contributor Author

@HalvorHaugan HalvorHaugan Dec 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed act() from multiple tests because it gave this warning: The current testing environment is not configured to support act(...)

Tests seems to work fine without it 🤷‍♂️

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { act, render, screen } from "@testing-library/react";
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import React from "react";
import { describe, test } from "vitest";
Expand All @@ -23,9 +23,6 @@ describe("Render datepicker", () => {
test("Should not crash when e.target is window", async () => {
render(<App />);

// eslint-disable-next-line testing-library/no-unnecessary-act -- https://kentcdodds.com/blog/fix-the-not-wrapped-in-act-warning
await act(async () => {
await userEvent.click(screen.getByText("Velg dato"));
});
await userEvent.click(screen.getByText("Velg dato"));
});
});
15 changes: 5 additions & 10 deletions @navikt/core/react/src/date/hooks/useRangeDatepicker.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable testing-library/no-unnecessary-act -- https://kentcdodds.com/blog/fix-the-not-wrapped-in-act-warning */
import { act, render, screen } from "@testing-library/react";
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import React from "react";
import { describe, expect, test } from "vitest";
Expand Down Expand Up @@ -29,10 +28,8 @@ describe("Writing in input sets correct values", () => {

const fraInput = screen.getByRole("textbox", { name: "Fra" });
const tilInput = screen.getByRole("textbox", { name: "Til" });
await act(async () => {
await userEvent.type(fraInput, "03.08.2022");
await userEvent.type(tilInput, "03.08.2022");
});
await userEvent.type(fraInput, "03.08.2022");
await userEvent.type(tilInput, "03.08.2022");
const res = screen.getByTitle("res");
expect(res.innerHTML).toEqual(
JSON.stringify({
Expand All @@ -47,10 +44,8 @@ describe("Writing in input sets correct values", () => {

const fraInput = screen.getByRole("textbox", { name: "Fra" });
const tilInput = screen.getByRole("textbox", { name: "Til" });
await act(async () => {
await userEvent.type(fraInput, "03.08.2022");
await userEvent.type(tilInput, "02.08.2022");
});
await userEvent.type(fraInput, "03.08.2022");
await userEvent.type(tilInput, "02.08.2022");
const res = screen.getByTitle("res");
expect(res.innerHTML).toEqual(
JSON.stringify({
Expand Down
16 changes: 4 additions & 12 deletions @navikt/core/react/src/tabs/Tabs.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { act, fireEvent, render, screen } from "@testing-library/react";
import { fireEvent, render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import React from "react";
import { describe, expect, test } from "vitest";
Expand Down Expand Up @@ -154,19 +154,11 @@ describe("Tabs", () => {
expect(screen.getByTestId("tab2")).toHaveFocus();

/* Move focus to tabPanel */
// eslint-disable-next-line testing-library/no-unnecessary-act
await act(async () => {
/* Tablist handles tabbing with setTimeout, so we need to use act */
await userEvent.tab();
});

await userEvent.tab();
expect(screen.getByTestId("tabpanel1")).toHaveFocus();
/* Move focus back to tablist, now tab1 should have focus */

// eslint-disable-next-line testing-library/no-unnecessary-act
await act(async () => {
await userEvent.tab({ shift: true });
});
/* Move focus back to tablist, now tab1 should have focus */
await userEvent.tab({ shift: true });
expect(screen.getByTestId("tab1")).toHaveFocus();
});
});
8 changes: 1 addition & 7 deletions @navikt/core/react/tests/setup.ts
Copy link
Contributor Author

@HalvorHaugan HalvorHaugan Dec 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes type errors when using the matchers from @testing-library/jest-dom, e.g. Property 'toBeVisible' does not exist on type 'Assertion<HTMLElement>'

The docs says the old method should still work though 🤷‍♂️

https://github.com/testing-library/jest-dom/releases/tag/v6.0.0

Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
/**
* Setup-file is required to avoid "chai" type errors when using testing-library with vitest
*/
import matchers from "@testing-library/jest-dom/matchers";
import { expect } from "vitest";

expect.extend(matchers);
import "@testing-library/jest-dom/vitest";
8 changes: 7 additions & 1 deletion @navikt/core/react/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@
"declaration": true,
"sourceMap": true
},
"include": ["./src"]
"include": ["./src"],
"exclude": [
"./src/**/*.test.ts",
"./src/**/*.test.tsx",
"./src/**/*.test-d.ts",
"./src/**/*.stories.tsx"
]
Comment on lines +11 to +16
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added to fix these errors:

Error: [@navikt/ds-react]: [1] src/modal/types.test-d.ts(4,1): error TS2582: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`.

[0] src/form/file-upload/utils/validate-files.test.ts(29,5): error TS2304: Cannot find name 'expect'. // multiple instances, just an example

src/tabs/Tabs.stories.tsx(7,1): error TS4082: Default export of the module has or is using private name 'TabsComponent'. // multiple instances, just an example

This could also be fixed by adding "types": ["vitest/globals"] to compilerOptions, but maybe it's a good idea to exclude these files anyways?

}
3 changes: 2 additions & 1 deletion @navikt/core/react/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "../../../tsconfig.json",
"compilerOptions": {
"noImplicitAny": false,
"resolveJsonModule": true
"resolveJsonModule": true,
"types": ["vitest/globals"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes type errors when using test(), expect() etc, e.g. Cannot find name 'expect'.

Not sure why it wasn't needed before.

}
}
2 changes: 1 addition & 1 deletion @navikt/core/tailwind/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"tailwindcss": "^3.3.3",
"tsx": "^4.19.1",
"typescript": "5.5.4",
"vitest": "^1.2.2"
"vitest": "^2.1.8"
},
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion @navikt/core/tokens/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"style-dictionary": "^4.1.1",
"tsx": "^4.19.1",
"typescript": "5.5.4",
"vitest": "^1.2.2"
"vitest": "^2.1.8"
},
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion aksel.nav.no/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,6 @@
"start-server-and-test": "^2.0.3",
"tsx": "^4.19.1",
"typescript": "5.5.4",
"vitest": "^1.2.2"
"vitest": "^2.1.8"
}
}
Loading
Loading