Skip to content

Commit

Permalink
fix(react-test-utils): fix remaining integration issues (#109)
Browse files Browse the repository at this point in the history
* fix issues with dependencies

* Change files

* try to fix jest

* fix lock

* remove wrong imports

* add eslint

* fix build issues

* Change files

* update readme

* try removing preset

* try ts-jest bump

* use local tsconfigs for jest

* adjust lage config

* bring back files to prevent need from consumers to use moduleResolution bundler

---------

Co-authored-by: Stanislaw Wilczynski <[email protected]>
  • Loading branch information
sjwilczynski and Stanislaw Wilczynski authored Sep 17, 2024
1 parent 32118d3 commit 37d880d
Show file tree
Hide file tree
Showing 29 changed files with 604 additions and 471 deletions.
6 changes: 4 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2019,
"sourceType": "module"
"sourceType": "module",
"project": "./tsconfig.json"
},
"env": {
"browser": true,
Expand All @@ -18,7 +19,8 @@
"disallowTypeAnnotations": true,
"prefer": "type-imports"
}
]
],
"@typescript-eslint/no-unsafe-member-access": "warn"
},
"extends": ["plugin:@typescript-eslint/recommended", "prettier"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "use bundler module resolution",
"packageName": "@nova/examples",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix TS version",
"packageName": "@nova/graphql-compiler",
"email": "[email protected]",
"dependentChangeType": "patch"
}
7 changes: 7 additions & 0 deletions change/@nova-react-1c909731-df94-4aae-8401-343a91a287ea.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "use bundler module resolution",
"packageName": "@nova/react",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "fix issues with dependencies",
"packageName": "@nova/react-test-utils",
"email": "[email protected]",
"dependentChangeType": "patch"
}
7 changes: 7 additions & 0 deletions change/@nova-types-2dd7c344-0151-4014-a486-33756652f003.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "use bundler module resolution",
"packageName": "@nova/types",
"email": "[email protected]",
"dependentChangeType": "patch"
}
2 changes: 1 addition & 1 deletion lage.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {
prepare: [],
types: ["^types"],
build: [],
test: ["build"],
test: ["^build", "^types"],
lint: [],
},
npmClient: "yarn",
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@
"beachball": "2.31.12",
"lage": "2.7.15",
"prettier": "^2.8.1"
},
"resolutions": {
"**/relay-compiler-language-graphitation/typescript": "<5"
}
}
6 changes: 3 additions & 3 deletions packages/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.21.0",
"@graphitation/embedded-document-artefact-loader": "^0.8.0",
"@graphitation/graphql-codegen-typescript-typemap-plugin": "^0.1.5",
"@graphitation/graphql-js-tag": "^0.9.0",
"@graphitation/graphql-codegen-typescript-typemap-plugin": "^0.1.6",
"@graphitation/graphql-js-tag": "^0.9.1",
"@graphql-codegen/add": "^4.0.1",
"@graphql-codegen/cli": "^3.2.2",
"@graphql-codegen/typescript": "^3.0.2",
Expand All @@ -56,7 +56,7 @@
"prop-types": "15.8.1",
"relay-compiler": "^17.0.0",
"storybook": "^7.6.19",
"typescript": ">=4.9.5"
"typescript": "^5.6.0"
},
"sideEffects": false
}
6 changes: 6 additions & 0 deletions packages/examples/tsconfig.jest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noUnusedLocals": false,
}
}
1 change: 1 addition & 0 deletions packages/examples/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"moduleResolution": "Bundler",
"jsx": "react",
"composite": true,
"tsBuildInfoFile": ".tsbuildinfo",
Expand Down
2 changes: 2 additions & 0 deletions packages/nova-graphql-compiler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ Then inside your package.json add the compiler to your `scripts`:
}
}
```

**NOTE**: Both `duct-tape-compiler` and `@nova/graphql-compiler` are not compatible with Typescript 5.x. When you upgrade to Typescript 5.x, make sure to force resolution to Typescript 4.x for both compilers and it's dependencies like `relay-compiler-language-graphitation`.
3 changes: 2 additions & 1 deletion packages/nova-graphql-compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"graphql": "^15.5.0",
"relay-compiler": "^12.0.0",
"relay-compiler-language-graphitation": "^0.8.2",
"yargs": "^16.2.0"
"yargs": "^16.2.0",
"typescript": "<5"
},
"devDependencies": {
"cross-spawn": "^7.0.0",
Expand Down
11 changes: 11 additions & 0 deletions packages/nova-graphql-compiler/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"composite": true,
"tsBuildInfoFile": ".tsbuildinfo",
"rootDir": "src",
"outDir": "lib"
},
"include": ["src"],
"references": []
}
41 changes: 34 additions & 7 deletions packages/nova-react-test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"@storybook/types": ">7.6",
"react": "^17 || ^18",
"@apollo/client": "^3.4",
"@graphitation/apollo-react-relay-duct-tape": "^1.0.30",
"@graphitation/apollo-mock-client": "^0.11.0",
"@graphitation/apollo-react-relay-duct-tape": "^1.1.0",
"@graphitation/apollo-mock-client": "^0.11.4",
"react-relay": ">16",
"relay-runtime": ">16",
"relay-test-utils": ">16",
Expand Down Expand Up @@ -55,9 +55,9 @@
}
},
"dependencies": {
"@graphitation/graphql-js-operation-payload-generator": "^0.12.0",
"@graphitation/graphql-js-tag": "^0.9.0",
"@jest/globals": ">27.0.0",
"@graphitation/graphql-js-operation-payload-generator": "^0.12.5",
"@graphitation/graphql-js-tag": "^0.9.1",
"@jest/types": ">27.0.0",
"@nova/react": "^2.6.0",
"@nova/types": "^1.5.0",
"@types/react": "^17 || ^18",
Expand All @@ -69,8 +69,8 @@
},
"devDependencies": {
"@apollo/client": "^3.4.15",
"@graphitation/apollo-react-relay-duct-tape": "^1.0.30",
"@graphitation/apollo-mock-client": "^0.11.0",
"@graphitation/apollo-react-relay-duct-tape": "^1.1.0",
"@graphitation/apollo-mock-client": "^0.11.4",
"@storybook/addon-actions": "^7.6.19",
"@storybook/preview-api": "^7.6.19",
"@storybook/react": "^7.6.19",
Expand All @@ -96,6 +96,23 @@
},
"sideEffects": false,
"access": "public",
"exports": {
".": {
"import": "./lib/relay/index.mjs",
"require": "./lib/relay/index.js",
"types": "./lib/relay/index.d.ts"
},
"./relay": {
"import": "./lib/relay/index.mjs",
"require": "./lib/relay/index.js",
"types": "./lib/relay/index.d.ts"
},
"./apollo": {
"import": "./lib/apollo/index.mjs",
"require": "./lib/apollo/index.js",
"types": "./lib/apollo/index.d.ts"
}
},
"publishConfig": {
"main": "./lib/relay/index",
"types": "./lib/relay/index.d.ts",
Expand All @@ -105,6 +122,16 @@
"import": "./lib/relay/index.mjs",
"require": "./lib/relay/index.js",
"types": "./lib/relay/index.d.ts"
},
"./relay": {
"import": "./lib/relay/index.mjs",
"require": "./lib/relay/index.js",
"types": "./lib/relay/index.d.ts"
},
"./apollo": {
"import": "./lib/apollo/index.mjs",
"require": "./lib/apollo/index.js",
"types": "./lib/apollo/index.d.ts"
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/nova-react-test-utils/src/apollo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export type {
WithNovaEnvironment,
UnknownOperation,
WithoutFragmentRefs,
MockResolvers,
DefaultMockResolvers,
} from "../shared/storybook-nova-decorator-shared";

export {
Expand Down
1 change: 0 additions & 1 deletion packages/nova-react-test-utils/src/apollo/test-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import type { OperationDescriptor } from "@graphitation/graphql-js-operation-pay
import { generate as payloadGenerator } from "@graphitation/graphql-js-operation-payload-generator";
import type { GraphQLTaggedNode } from "@nova/react";
import type { NovaGraphQL } from "@nova/types";
import { jest } from "@jest/globals";

type MockClientOptions = Parameters<typeof createMockClient>[1];

Expand Down
2 changes: 2 additions & 0 deletions packages/nova-react-test-utils/src/relay/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export type {
WithNovaEnvironment,
UnknownOperation,
WithoutFragmentRefs,
MockResolvers,
DefaultMockResolvers,
} from "../shared/storybook-nova-decorator-shared";

export {
Expand Down
1 change: 0 additions & 1 deletion packages/nova-react-test-utils/src/relay/test-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import type { OperationDescriptor as RelayOperationDescriptor } from "relay-runt
import { novaGraphql } from "./nova-relay-graphql";
import { createMockEnvironment } from "relay-test-utils";
import { RelayEnvironmentProvider } from "react-relay";
import { jest } from "@jest/globals";

export class RelayMockPayloadGenerator {
public gqlSchema: GraphQLSchema;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
NovaGraphQLProvider,
} from "@nova/react";
import type { Variant } from "./shared-utils";
import type { jest } from "@jest/globals";

type RelayMockFunctions = MockEnvironment["mock"];
type Environment = "test" | "storybook";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type { Variant } from "./shared-utils";

type Context = Parameters<Parameters<typeof makeDecorator>[0]["wrapper"]>[1];

export type { MockResolvers };
export type DefaultMockResolvers = Partial<{
ID: string;
Boolean: boolean;
Expand Down
1 change: 1 addition & 0 deletions packages/nova-react-test-utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"moduleResolution": "Bundler",
"jsx": "react",
"composite": true,
"tsBuildInfoFile": ".tsbuildinfo",
Expand Down
4 changes: 2 additions & 2 deletions packages/nova-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
"peerDependencies": {
"react": "^17.0.2 || ^18",
"@types/react": "^17.0.2 || ^18",
"@graphitation/graphql-js-tag": "^0.9.0"
"@graphitation/graphql-js-tag": "^0.9.1"
},
"dependencies": {
"@nova/types": "^1.5.0",
"graphql": "^15.5.0",
"invariant": "^2.2.4"
},
"devDependencies": {
"@graphitation/graphql-js-tag": "^0.9.0",
"@graphitation/graphql-js-tag": "^0.9.1",
"@testing-library/react": "^15.0.0",
"@types/invariant": "^2.2.35",
"@types/jest": "^29.2.0",
Expand Down
1 change: 1 addition & 0 deletions packages/nova-react/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"moduleResolution": "Bundler",
"jsx": "react",
"composite": true,
"tsBuildInfoFile": ".tsbuildinfo",
Expand Down
1 change: 1 addition & 0 deletions packages/nova-types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"moduleResolution": "Bundler",
"composite": true,
"tsBuildInfoFile": ".tsbuildinfo",
"rootDir": "src",
Expand Down
15 changes: 10 additions & 5 deletions scripts/config/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
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__"],
Expand All @@ -15,10 +23,7 @@ export default {
"^.+\\.tsx?$": [
"ts-jest",
{
tsconfig: {
// prevents error about graphql import not being used when artifacts are loaded
noUnusedLocals: false,
},
tsconfig: getTsConfigPath(),
},
],
},
Expand Down
8 changes: 4 additions & 4 deletions scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
"eslint": "^8.30.0",
"eslint-config-prettier": "^8.5.0",
"fast-glob": "^3.2.5",
"jest": "^29.1.0",
"jest-environment-jsdom": "^29.0.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"just-scripts": "^2.1.0",
"ts-jest": "^29.0.0",
"ts-jest": "^29.2.0",
"ts-node": "^10.4.0",
"typescript": ">=4.9.5"
"typescript": "^5.6.0"
}
}
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"isolatedModules": true,
"importsNotUsedAsValues": "error",
"forceConsistentCasingInFileNames": true,
"noUnusedLocals": true,
"noUnusedParameters": true
Expand Down
Loading

0 comments on commit 37d880d

Please sign in to comment.