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

fix(examples): improve handling of local jest config and remove RTL clean hack #110

Merged
merged 3 commits into from
Sep 18, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "improve handling of jest config and remove RTL clean hack",
"packageName": "@nova/examples",
"email": "[email protected]",
"dependentChangeType": "patch"
}
21 changes: 21 additions & 0 deletions packages/examples/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import config from "../../scripts/config/jest.config";

export default {
...config,
transform: {
"\\.(gql|graphql)$": "@graphql-tools/jest-transform",
// Needed for packages/examples to load relay compiler generated artifacts.
// It would be better if it could be config local to examples package but haven't found a way to configure it with just
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like it is local to the examples package? Am I missing something or does the comment need to be updated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I mindlessly copy pasted, will remove on next PR

".+[\\\\/]relay[\\\\/].+\\.tsx?$":
"@graphitation/embedded-document-artefact-loader/ts-jest",
"^.+\\.tsx?$": [
"ts-jest",
{
tsconfig: {
// prevents error about graphql import not being used when artifacts are loaded
noUnusedLocals: false,
},
},
],
},
};
2 changes: 1 addition & 1 deletion packages/examples/src/testing-utils/executePlayFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
ComposedStoryPlayContext,
ComposedStoryFn,
} from "@storybook/types";
import { act, waitFor } from "@testing-library/react";
import { act, waitFor } from "@testing-library/react/pure";

type PlayFunctionThatReturnsPromise = (
options: ComposedStoryPlayContext<ReactRenderer>,
Expand Down
6 changes: 0 additions & 6 deletions packages/examples/tsconfig.jest.json

This file was deleted.

24 changes: 1 addition & 23 deletions scripts/config/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,10 @@
import path from "path";
import fs from "fs";

const getTsConfigPath = () => {
if (fs.existsSync(path.join(process.cwd(), "tsconfig.jest.json"))) {
return "<rootDir>/tsconfig.jest.json";
} else {
return "<rootDir>/tsconfig.json";
}
};

export default {
preset: "ts-jest",
rootDir: process.cwd(),
roots: ["<rootDir>/src"],
testPathIgnorePatterns: ["node_modules", "__generated__"],
testEnvironment: "jsdom",
transform: {
"\\.(gql|graphql)$": "@graphql-tools/jest-transform",
// Needed for packages/examples to load relay compiler generated artifacts.
// It would be better if it could be config local to examples package but haven't found a way to configure it with just
".+[\\\\/]relay[\\\\/].+\\.tsx?$":
"@graphitation/embedded-document-artefact-loader/ts-jest",
"^.+\\.tsx?$": [
"ts-jest",
{
tsconfig: getTsConfigPath(),
},
],
},
setupFiles: [path.join(__dirname, "jest.setup.ts")],
setupFilesAfterEnv: [path.join(__dirname, "jest.setupAfterEnv.ts")],
};
2 changes: 1 addition & 1 deletion scripts/config/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { configure } from "@testing-library/react";
import { configure } from "@testing-library/react/pure";

configure({
reactStrictMode: true,
Expand Down
6 changes: 0 additions & 6 deletions scripts/config/jest.setupAfterEnv.ts

This file was deleted.

5 changes: 4 additions & 1 deletion scripts/just.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ export const build = () => {
};

export const test = () => {
const config = fs.existsSync(path.join(process.cwd(), "jest.config.ts"))
? path.join(process.cwd(), "jest.config.ts") // if it exists prioritize using package local config
: path.join(__dirname, "config", "jest.config.ts");
return jestTask({
config: path.join(__dirname, "config", "jest.config.ts"),
config,
watch: argv().watch,
_: argv()._,
});
Expand Down
Loading