diff --git a/index.d.ts b/index.d.mts similarity index 100% rename from index.d.ts rename to index.d.mts diff --git a/package.json b/package.json index 18630b5..f870162 100644 --- a/package.json +++ b/package.json @@ -6,12 +6,12 @@ "description": "Make your React.js rendering predictable", "scripts": { "test": "tsc && bun test && node ./test/all.mjs", - "format": "prettier **/*.mjs **/*.ts --write", - "formatCheck": "prettier **/*.mjs **/*.ts --check" + "format": "prettier **/*.mjs **/*.mts --write", + "formatCheck": "prettier **/*.mjs **/*.mts --check" }, "type": "module", "exports": "./index.mjs", - "types": "./index.d.ts", + "types": "./index.d.mts", "private": false, "publishConfig": { "access": "public" diff --git a/src/assertComponent.d.ts b/src/assertComponent.d.ts deleted file mode 100644 index e69a588..0000000 --- a/src/assertComponent.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -export interface TestInstance { - type: any; - props: { [propName: string]: any }; - children?: Array; -} diff --git a/src/assertComponent.mjs b/src/assertComponent.mjs index e35076d..58428d4 100644 --- a/src/assertComponent.mjs +++ b/src/assertComponent.mjs @@ -8,10 +8,18 @@ function assertComponent(result, expectedElement) { assertComponentImpl("", result, expectedElement); } +/** + * @typedef {{ + * type: any; + * props: { [propName: string]: any }; + * children?: Array; + * }} TestInstance + */ + /** * @param { string } path - * @param { import('./assertComponent').TestInstance | string } result - * @param { import('./assertComponent').TestInstance | string } expectedElement + * @param { TestInstance | string } result + * @param { TestInstance | string } expectedElement */ function assertComponentImpl(path, result, expectedElement) { const name = @@ -164,8 +172,8 @@ function assertAttrValue(name, resultValue, expectedValue) { } /** - * @param {import('./assertComponent').TestInstance} result - * @returns {(import('./assertComponent').TestInstance | string)[]} + * @param {TestInstance} result + * @returns {(TestInstance | string)[]} */ function getComponentChildren(result) { // in case of ReactElement get children from props diff --git a/test/example.jsx b/test/example.jsx index b14dc0e..a033876 100644 --- a/test/example.jsx +++ b/test/example.jsx @@ -3,10 +3,12 @@ import TestRenderer from "react-test-renderer"; import { assertComponents, mockComponent } from "../index.mjs"; const { describe, it } = await (async () => { + // @ts-ignore + const module = process.isBun ? "bun:test" : "node:test"; // @ts-ignore return process.isBun // @ts-ignore ? Promise.resolve({ describe: (_, fn) => fn(), it: test }) - : import("node:test"); + : import(module); })(); function SubComponent() { diff --git a/tsconfig.json b/tsconfig.json index 27dc065..90fba86 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -25,7 +25,7 @@ "noUnusedLocals": true, "noUnusedParameters": true, // use Node's module resolution algorithm, instead of the legacy TS one - "moduleResolution": "node", + //"moduleResolution": "node", // interop between ESM and CJS modules. Recommended by TS "esModuleInterop": true, // significant perf increase by skipping checking .d.ts files, particularly those in node_modules. Recommended by TS