Skip to content

Commit 5675cd1

Browse files
Fix tests
1 parent 323ce26 commit 5675cd1

10 files changed

Lines changed: 54 additions & 3 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { Config } from "jest";
2+
import { preactModuleNameMapper } from "@cursorless/common";
3+
4+
const config: Config = {
5+
preset: "ts-jest",
6+
testEnvironment: "jsdom",
7+
moduleNameMapper: {
8+
...preactModuleNameMapper,
9+
"^@cursorless/cheatsheet$": "<rootDir>/../cheatsheet/src/index.ts",
10+
"\\.(css|scss)$": "<rootDir>/src/test/styleMock.ts",
11+
},
12+
};
13+
14+
export default config;

packages/cheatsheet-local/src/app/app.spec.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
import { fakeCheatsheetInfo } from "@cursorless/cheatsheet";
12
import { render } from "preact";
23
import { act } from "preact/test-utils";
34
import { App } from "./app";
45

56
describe("App", () => {
7+
beforeEach(() => {
8+
document.cheatsheetInfo = fakeCheatsheetInfo;
9+
});
10+
611
afterEach(() => {
712
document.body.innerHTML = "";
813
});
@@ -26,6 +31,6 @@ describe("App", () => {
2631
render(<App />, container);
2732
});
2833

29-
expect(container.textContent).toMatch(/Welcome cheatsheet-local/gi);
34+
expect(container.textContent).toMatch(/Cursorless Cheatsheet/gi);
3035
});
3136
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default {};

packages/cheatsheet/jest.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import type { Config } from "jest";
2+
import { preactModuleNameMapper } from "@cursorless/common";
23

34
const config: Config = {
45
preset: "ts-jest",
56
testEnvironment: "jsdom",
7+
moduleNameMapper: preactModuleNameMapper,
68
};
79

810
export default config;

packages/cheatsheet/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"watch": "pnpm run --filter @cursorless/cheatsheet --parallel '/^watch:.*/'"
2727
},
2828
"dependencies": {
29+
"@cursorless/common": "workspace:*",
2930
"@fortawesome/fontawesome-svg-core": "^7.2.0",
3031
"@fortawesome/free-solid-svg-icons": "^7.2.0",
3132
"@fortawesome/react-fontawesome": "^3.2.0",

packages/cheatsheet/tsconfig.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
"esModuleInterop": true,
99
"skipLibCheck": true
1010
},
11-
"references": [],
11+
"references": [
12+
{
13+
"path": "../common"
14+
}
15+
],
1216
"include": [
1317
"src/**/*.ts",
1418
"src/**/*.json",

packages/common/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@ export * from "./testUtil/asyncSafety";
4545
export * from "./testUtil/extractTargetedMarks";
4646
export * from "./testUtil/fromPlainObject";
4747
export * from "./testUtil/getSnapshotForComparison";
48+
export * from "./testUtil/preactModuleNameMapper";
4849
export * from "./testUtil/serialize";
4950
export * from "./testUtil/serializeTestFixture";
5051
export * from "./testUtil/shouldUpdateFixtures";
5152
export * from "./testUtil/spyToPlainObject";
5253
export * from "./testUtil/TestCaseSnapshot";
5354
export * from "./testUtil/testConstants";
55+
export * from "./testUtil/viteHtmlParamsPlugin";
5456
export * from "./types/command/ActionDescriptor";
5557
export * from "./types/command/command.types";
5658
export * from "./types/command/CommandV6.types";
@@ -122,4 +124,3 @@ export * from "./util/type";
122124
export * from "./util/typeUtils";
123125
export * from "./util/uniqWithHash";
124126
export * from "./util/zipStrict";
125-
export * from "./viteHtmlParamsPlugin";
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* eslint-disable @typescript-eslint/naming-convention */
2+
3+
export const preactModuleNameMapper = {
4+
"^react$": "<rootDir>/node_modules/preact/compat/dist/compat.js",
5+
"^react-dom$": "<rootDir>/node_modules/preact/compat/dist/compat.js",
6+
"^react-dom/test-utils$":
7+
"<rootDir>/node_modules/preact/test-utils/dist/testUtils.js",
8+
"^react/jsx-runtime$":
9+
"<rootDir>/node_modules/preact/jsx-runtime/dist/jsxRuntime.js",
10+
"^react/jsx-dev-runtime$":
11+
"<rootDir>/node_modules/preact/jsx-runtime/dist/jsxRuntime.js",
12+
"^preact$": "<rootDir>/node_modules/preact/dist/preact.js",
13+
"^preact/hooks$": "<rootDir>/node_modules/preact/hooks/dist/hooks.js",
14+
"^preact/test-utils$":
15+
"<rootDir>/node_modules/preact/test-utils/dist/testUtils.js",
16+
"^preact/jsx-runtime$":
17+
"<rootDir>/node_modules/preact/jsx-runtime/dist/jsxRuntime.js",
18+
"^preact/jsx-dev-runtime$":
19+
"<rootDir>/node_modules/preact/jsx-runtime/dist/jsxRuntime.js",
20+
};
File renamed without changes.

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)