Skip to content

Commit

Permalink
chore(core): start supporting multiple test frameworks
Browse files Browse the repository at this point in the history
  • Loading branch information
mlaursen committed Jan 12, 2025
1 parent 6e8e77e commit 8e5e0d8
Show file tree
Hide file tree
Showing 168 changed files with 578 additions and 590 deletions.
3 changes: 3 additions & 0 deletions packages/core/jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const config = {
moduleNameMapper: {
"\\.scss$": "identity-obj-proxy",
"^(\\.{1,2}/.*)\\.js$": "$1",
"^test-utils$": "<rootDir>/src/test-utils/index.ts",
"^test-utils/jest-globals$":
"<rootDir>/src/test-utils/jest-globals/index.ts",
},

watchPlugins: [
Expand Down
3 changes: 1 addition & 2 deletions packages/core/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
import "@testing-library/jest-dom/jest-globals";
import "./src/test-utils/jest-globals/setup.js";
import "./src/test-utils/polyfills/index.js";
import "./src/test-utils/jest-setup.js";
5 changes: 1 addition & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
"require": "./dist/test-utils/polyfills/*",
"default": "./dist/test-utils/polyfills/*.js"
},
"./test-utils/jest-globals": "./dist/test-utils/jest-globals/index.js",
"./test-utils": "./dist/test-utils/index.js",
"./test-utils/*": {
"require": "./dist/test-utils/*",
"default": "./dist/test-utils/*.js"
},
"./colors": {
"sass": "./dist/_colors.scss",
"default": "./dist/theme/colors.js"
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/NoSsr.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "@jest/globals";
import { type ReactElement } from "react";
import { render, screen } from "../test-utils/index.js";
import { render, screen } from "test-utils";

import { NoSsr } from "../NoSsr.js";
import { SsrProvider, useSsr } from "../SsrProvider.js";
Expand Down
8 changes: 1 addition & 7 deletions packages/core/src/__tests__/useAsyncFunction.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { describe, expect, it, jest } from "@jest/globals";
import { type MouseEvent, type ReactElement } from "react";
import {
act,
rmdRender,
screen,
userEvent,
waitFor,
} from "../test-utils/index.js";
import { act, rmdRender, screen, userEvent, waitFor } from "test-utils";

import { box } from "../box/styles.js";
import { Button, type ButtonProps } from "../button/Button.js";
Expand Down
9 changes: 1 addition & 8 deletions packages/core/src/__tests__/useDebouncedFunction.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { describe, expect, it, jest } from "@jest/globals";
import { useState } from "react";
import {
act,
fireEvent,
render,
screen,
userEvent,
waitFor,
} from "../test-utils/index.js";
import { act, fireEvent, render, screen, userEvent, waitFor } from "test-utils";

import { Button } from "../button/Button.js";
import { TextField } from "../form/TextField.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/useDropzone.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it, jest } from "@jest/globals";
import { cnb } from "cnbuilder";
import { type ReactElement, type ReactNode } from "react";
import { fireEvent, render, screen } from "../test-utils/index.js";
import { fireEvent, render, screen } from "test-utils";

import { useDropzone, type DropzoneOptions } from "../useDropzone.js";

Expand Down
6 changes: 2 additions & 4 deletions packages/core/src/__tests__/useElementSize.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { describe, expect, it } from "@jest/globals";
import { createRef, type MutableRefObject, type ReactElement } from "react";
import { act, render, screen } from "test-utils";
import {
act,
cleanupResizeObserverAfterEach,
render,
screen,
setupResizeObserverMock,
} from "../test-utils/index.js";
} from "test-utils/jest-globals";
import { type ElementSize } from "../types.js";
import { useElementSize, type ElementSizeOptions } from "../useElementSize.js";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/useEnsuredId.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "@jest/globals";
import { type ReactElement } from "react";
import { render, screen } from "../test-utils/index.js";
import { render, screen } from "test-utils";

import { useEnsuredId } from "../useEnsuredId.js";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/useEnsuredState.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it, jest } from "@jest/globals";
import { type ReactElement } from "react";
import { fireEvent, render, screen } from "../test-utils/index.js";
import { fireEvent, render, screen } from "test-utils";
import { useEnsuredState } from "../useEnsuredState.js";
import { useToggle } from "../useToggle.js";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/useHtmlClassName.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from "@jest/globals";
import { render } from "../test-utils/index.js";
import { render } from "test-utils";

import { useHtmlClassName } from "../useHtmlClassName.js";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/useLocalStorage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { afterEach, describe, expect, it } from "@jest/globals";
import lzString from "lz-string";
import { useEffect, type ReactElement } from "react";
import { act, fireEvent, render, screen } from "../test-utils/index.js";
import { act, fireEvent, render, screen } from "test-utils";

import { Button } from "../button/Button.js";
import { SsrProvider } from "../SsrProvider.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/useOrientation.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it, jest } from "@jest/globals";
import { act, render } from "../test-utils/index.js";
import { act, render } from "test-utils";

import { useOrientation } from "../useOrientation.js";

Expand Down
8 changes: 5 additions & 3 deletions packages/core/src/__tests__/useResizeObserver.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import { describe, expect, it, jest } from "@jest/globals";
import { useEffect, type ReactElement } from "react";
import {
act,
cleanupResizeObserverAfterEach,
createResizeObserverEntry,
render,
screen,
setupResizeObserverMock,
waitFor,
} from "../test-utils/index.js";
} from "test-utils";
import {
cleanupResizeObserverAfterEach,
setupResizeObserverMock,
} from "test-utils/jest-globals";

import {
useResizeObserver,
Expand Down
9 changes: 1 addition & 8 deletions packages/core/src/__tests__/useThrottledFunction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,7 @@ import {
type MutableRefObject,
type ReactElement,
} from "react";
import {
act,
fireEvent,
render,
screen,
userEvent,
waitFor,
} from "../test-utils/index.js";
import { act, fireEvent, render, screen, userEvent, waitFor } from "test-utils";

import { Button } from "../button/Button.js";
import { TextField } from "../form/TextField.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/useToggle.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "@jest/globals";
import { type ReactElement } from "react";
import { fireEvent, render, screen } from "../test-utils/index.js";
import { fireEvent, render, screen } from "test-utils";

import { useToggle } from "../useToggle.js";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/useWindowSize.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { beforeAll, beforeEach, describe, expect, it } from "@jest/globals";
import { createRef, type MutableRefObject, type ReactElement } from "react";
import { SsrProvider } from "../SsrProvider.js";
import { act, render, screen, waitFor } from "../test-utils/index.js";
import { act, render, screen, waitFor } from "test-utils";
import { type ElementSize } from "../types.js";
import { useWindowSize, type WindowSizeOptions } from "../useWindowSize.js";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/app-bar/__tests__/AppBar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "@jest/globals";
import { createRef } from "react";
import { render, screen } from "../../test-utils/index.js";
import { render, screen } from "test-utils";
import { AppBar } from "../AppBar.js";
import { AppBarTitle } from "../AppBarTitle.js";
import { type AppBarHeight, type AppBarPosition } from "../styles.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/app-bar/__tests__/AppBarTitle.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "@jest/globals";
import { createRef } from "react";
import { render, screen } from "../../test-utils/index.js";
import { render, screen } from "test-utils";
import { AppBarTitle } from "../AppBarTitle.js";
import { appBarTitle } from "../styles.js";

Expand Down
10 changes: 2 additions & 8 deletions packages/core/src/autocomplete/__tests__/Autocomplete.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import { afterAll, beforeAll, describe, expect, it, jest } from "@jest/globals";
import { cnb } from "cnbuilder";
import { act, createRef, type ReactElement, useEffect, useState } from "react";
import { rmdRender, screen, userEvent, within } from "test-utils";
import { type RafSpy, testImmediateRaf } from "test-utils/jest-globals";
import { FontIcon } from "../../icon/FontIcon.js";
import { type MenuItemProps } from "../../menu/MenuItem.js";
import { fuzzySearch } from "../../searching/fuzzy.js";
import {
type RafSpy,
rmdRender,
screen,
testImmediateRaf,
userEvent,
within,
} from "../../test-utils/index.js";
import { SrOnly } from "../../typography/SrOnly.js";
import { Autocomplete } from "../Autocomplete.js";
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it, jest } from "@jest/globals";
import { createRef } from "react";
import { render, screen } from "../../test-utils/index.js";
import { render, screen } from "test-utils";
import { AutocompleteChip } from "../AutocompleteChip.js";

describe("AutocompleteChip", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from "@jest/globals";
import { render, screen } from "../../test-utils/index.js";
import { render, screen } from "test-utils";
import { AutocompleteCircularProgress } from "../AutocompleteCircularProgress.js";

describe("AutocompleteCircularProgress", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it, jest } from "@jest/globals";
import { render, screen } from "../../test-utils/index.js";
import { render, screen } from "test-utils";
import { AutocompleteClearButton } from "../AutocompleteClearButton.js";
import { type AutocompleteClearButtonProps } from "../types.js";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/avatar/__tests__/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "@jest/globals";
import { createRef } from "react";
import { render, screen } from "../../test-utils/index.js";
import { render, screen } from "test-utils";

import { Avatar } from "../Avatar.js";
import { avatarImage } from "../styles.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/badge/__tests__/Badge.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "@jest/globals";
import { createRef } from "react";
import { render, screen } from "../../test-utils/index.js";
import { render, screen } from "test-utils";

import { Badge } from "../Badge.js";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/box/__tests__/Box.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "@jest/globals";
import { createRef } from "react";
import { render, screen } from "../../test-utils/index.js";
import { render, screen } from "test-utils";
import { Box, type BoxProps } from "../Box.js";
import { type BoxAlignItems, type BoxJustifyContent } from "../styles.js";

Expand Down
9 changes: 1 addition & 8 deletions packages/core/src/button/__tests__/AsyncButton.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import { describe, expect, it, jest } from "@jest/globals";
import { createRef } from "react";
import { FontIcon } from "../../icon/FontIcon.js";
import {
act,
rmdRender,
screen,
userEvent,
waitFor,
within,
} from "../../test-utils/index.js";
import { act, rmdRender, screen, userEvent, waitFor, within } from "test-utils";
import { AsyncButton, type AsyncButtonProps } from "../AsyncButton.js";

describe("AsyncButton", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/button/__tests__/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, expect, it, jest } from "@jest/globals";
import { createRef } from "react";
import { FontIcon } from "../../icon/FontIcon.js";
import { INTERACTION_CONFIG } from "../../interaction/config.js";
import { fireEvent, render, screen } from "../../test-utils/index.js";
import { fireEvent, render, screen } from "test-utils";
import { SrOnly } from "../../typography/SrOnly.js";
import { Button, type ButtonProps } from "../Button.js";
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/button/__tests__/ButtonUnstyled.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "@jest/globals";
import { createRef } from "react";
import { render, screen } from "../../test-utils/index.js";
import { render, screen } from "test-utils";

import { ButtonUnstyled } from "../ButtonUnstyled.js";
import { buttonUnstyled } from "../buttonUnstyledStyles.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/button/__tests__/TooltippedButton.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it } from "@jest/globals";
import { createRef } from "react";
import { FontIcon } from "../../icon/FontIcon.js";
import { render, screen, userEvent } from "../../test-utils/index.js";
import { render, screen, userEvent } from "test-utils";
import {
TooltippedButton,
type TooltippedButtonProps,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/card/__tests__/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "@jest/globals";
import { createRef } from "react";
import { render, screen } from "../../test-utils/index.js";
import { render, screen } from "test-utils";

import { Card } from "../Card.js";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/card/__tests__/CardContent.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "@jest/globals";
import { createRef } from "react";
import { render, screen } from "../../test-utils/index.js";
import { render, screen } from "test-utils";

import { CardContent } from "../CardContent.js";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/card/__tests__/CardFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "@jest/globals";
import { createRef } from "react";
import { render, screen } from "../../test-utils/index.js";
import { render, screen } from "test-utils";

import { CardFooter } from "../CardFooter.js";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/card/__tests__/CardHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "@jest/globals";
import { createRef } from "react";
import { render, screen } from "../../test-utils/index.js";
import { render, screen } from "test-utils";

import { Button } from "../../button/Button.js";
import { CardHeader } from "../CardHeader.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/card/__tests__/CardSubtitle.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "@jest/globals";
import { createRef } from "react";
import { render, screen } from "../../test-utils/index.js";
import { render, screen } from "test-utils";

import { CardSubtitle } from "../CardSubtitle.js";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/card/__tests__/CardTitle.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "@jest/globals";
import { createRef } from "react";
import { render, screen } from "../../test-utils/index.js";
import { render, screen } from "test-utils";

import { CardTitle } from "../CardTitle.js";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/card/__tests__/ClickableCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it, jest } from "@jest/globals";
import { createRef } from "react";
import { fireEvent, render, screen } from "../../test-utils/index.js";
import { fireEvent, render, screen } from "test-utils";
import { ClickableCard } from "../ClickableCard.js";

describe("ClickableCard", () => {
Expand Down
8 changes: 1 addition & 7 deletions packages/core/src/chip/__tests__/Chip.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { describe, expect, it, jest } from "@jest/globals";
import { createRef, type ReactElement } from "react";
import {
fireEvent,
render,
rmdRender,
screen,
userEvent,
} from "../../test-utils/index.js";
import { fireEvent, render, rmdRender, screen, userEvent } from "test-utils";

import { FontIcon } from "../../icon/FontIcon.js";
import { INTERACTION_CONFIG } from "../../interaction/config.js";
Expand Down
7 changes: 1 addition & 6 deletions packages/core/src/dialog/__tests__/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ import { describe, expect, it } from "@jest/globals";
import { createRef, type ReactElement } from "react";
import { Button } from "../../button/Button.js";
import { PORTAL_CONTAINER_ID } from "../../portal/PortalContainerProvider.js";
import {
rmdRender,
screen,
userEvent,
waitFor,
} from "../../test-utils/index.js";
import { rmdRender, screen, userEvent, waitFor } from "test-utils";
import { useToggle } from "../../useToggle.js";
import { isElementVisible } from "../../utils/isElementVisible.js";
import { Dialog, type DialogProps } from "../Dialog.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/dialog/__tests__/DialogContent.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "@jest/globals";
import { createRef } from "react";
import { render, screen } from "../../test-utils/index.js";
import { render, screen } from "test-utils";
import { DialogContent } from "../DialogContent.js";
import { dialogContent } from "../styles.js";

Expand Down
Loading

0 comments on commit 8e5e0d8

Please sign in to comment.