@thepalaceproject/circulation-admin 1.43.0-post.1 → 1.43.0-post.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/eslint.config.mjs CHANGED
@@ -8,7 +8,15 @@ import globals from "globals";
8
8
 
9
9
  export default tseslint.config(
10
10
  {
11
- ignores: ["dist/", "lib/", "docs/", "typings/", "node_modules/"],
11
+ ignores: [
12
+ "dist/",
13
+ "lib/",
14
+ "docs/",
15
+ "typings/",
16
+ "node_modules/",
17
+ "coverage/",
18
+ ".nyc_output/",
19
+ ],
12
20
  },
13
21
  js.configs.recommended,
14
22
  ...tseslint.configs.recommended,
package/jest.config.js CHANGED
@@ -1,16 +1,63 @@
1
1
  /** @type {import('ts-jest').JestConfigWithTsJest} */
2
- module.exports = {
2
+
3
+ // Options shared by both projects.
4
+ const sharedProjectConfig = {
5
+ preset: "ts-jest",
6
+ testEnvironmentOptions: {
7
+ // Without this, jsdom's default `["browser"]` export condition resolves sinon
8
+ // to its ESM bundle, which ts-jest does not transform. Every legacy suite then
9
+ // dies with `SyntaxError: Unexpected token 'export'`.
10
+ customExportConditions: [""],
11
+ },
12
+ setupFiles: ["<rootDir>/jest.polyfills.js"],
3
13
  moduleNameMapper: {
4
14
  "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
5
15
  "<rootDir>/tests/__mocks__/fileMock.js",
6
- "\\.(css|less)$": "<rootDir>/tests/__mocks__/styleMock.js",
16
+ "\\.(css|less|scss|sass)$": "<rootDir>/tests/__mocks__/styleMock.js",
7
17
  "\\.md$": "<rootDir>/tests/__mocks__/fileMock.js",
8
18
  },
9
- preset: "ts-jest",
10
- testEnvironment: "jest-fixed-jsdom",
11
- testEnvironmentOptions: {
12
- customExportConditions: [""],
13
- },
14
- setupFiles: ["./jest.polyfills.js"],
15
- setupFilesAfterEnv: ["./tests/jest/jest-setup.ts"],
19
+ // `src` must stay in `roots` so that `collectCoverageFrom` can discover source
20
+ // files that no test imports — otherwise they are silently omitted from the
21
+ // report rather than counted as uncovered, and the coverage percentage rises
22
+ // while real coverage is unchanged.
23
+ roots: ["<rootDir>/src"],
24
+ };
25
+
26
+ module.exports = {
27
+ coverageDirectory: "coverage/jest",
28
+ coverageReporters: ["lcov", "text-summary"],
29
+ // Must live at the top level, not inside `projects`: jest reads
30
+ // `collectCoverageFrom` off the *global* config. Set it only per-project and it
31
+ // is silently undefined globally, so every executed file gets instrumented —
32
+ // including test helpers and everything under `tests/`.
33
+ collectCoverageFrom: [
34
+ "src/**/*.{ts,tsx}",
35
+ "!src/**/__tests__/**",
36
+ "!src/**/*.d.ts",
37
+ ],
38
+ projects: [
39
+ {
40
+ ...sharedProjectConfig,
41
+ displayName: "unit",
42
+ roots: [...sharedProjectConfig.roots, "<rootDir>/tests/jest"],
43
+ testMatch: ["<rootDir>/tests/jest/**/*.test.{js,jsx,ts,tsx}"],
44
+ // `jest-fixed-jsdom` restores Node's fetch/Response globals so MSW can
45
+ // intercept them.
46
+ testEnvironment: "jest-fixed-jsdom",
47
+ setupFilesAfterEnv: ["<rootDir>/tests/jest/jest-setup.ts"],
48
+ },
49
+ {
50
+ // Legacy enzyme + chai + sinon tests, still in `src/**/__tests__/`. They are
51
+ // being rewritten as React Testing Library tests under `tests/jest/`; when the
52
+ // last one is gone, delete this project, its environment, and its setup file.
53
+ //
54
+ // These cannot use `jest-fixed-jsdom`: it swaps in undici's `FormData`, which
55
+ // rejects `new FormData(formElement)` and crashes any test that submits a form.
56
+ ...sharedProjectConfig,
57
+ displayName: "legacy",
58
+ testMatch: ["<rootDir>/src/**/__tests__/*-test.{ts,tsx}"],
59
+ testEnvironment: "<rootDir>/tests/jest/legacyJsdomEnvironment.js",
60
+ setupFilesAfterEnv: ["<rootDir>/tests/jest/legacy-setup.ts"],
61
+ },
62
+ ],
16
63
  };
package/package.json CHANGED
@@ -17,18 +17,15 @@
17
17
  "prepublish": "npm run prod",
18
18
  "lint": "npm run lint:js && sass-lint -c .sass-lint.yml -v -q",
19
19
  "lint:js": "eslint . --max-warnings 0",
20
- "test-js": "tsc && cp -r src/stylesheets lib && cp -r src/images lib && mocha --require lib/testHelper.js lib/__tests__/*.js lib/**/__tests__/*.js lib/**/**/__tests__/*.js",
21
- "test-js-file": "tsc && cp -r src/stylesheets lib && cp -r src/images lib && mocha --require lib/testHelper.js",
22
- "test-js-list": "mocha --require lib/testHelper.js lib/__tests__/*.js lib/**/__tests__/*.js lib/**/**/__tests__/*.js --reporter ./testReporter.js",
23
- "test-ts": "mocha -r ts-node/register --require src/testHelper.ts src/__tests__/*.ts* src/**/__tests__/*.ts* src/**/**/__tests__/*.ts*",
24
- "test-file-ts": "mocha -r ts-node/register --require src/testHelper.ts",
25
- "test": "npm run test-ts && npm run test-jest",
26
- "test-file": "npm run test-file-ts",
20
+ "test": "npm run test-jest",
21
+ "test-file": "npm run test-jest-file",
27
22
  "test-browser": "npm run test-chrome && npm run test-firefox",
28
23
  "test-chrome": "node_modules/.bin/selenium-standalone install && nightwatch -e chrome",
29
24
  "test-firefox": "node_modules/.bin/selenium-standalone install && nightwatch -e firefox",
30
- "test-jest": "jest --verbose --roots tests/jest",
25
+ "test-jest": "jest --verbose",
31
26
  "test-jest-file": "jest --verbose",
27
+ "coverage": "npm run coverage-jest",
28
+ "coverage-jest": "npm run test-jest -- --coverage",
32
29
  "dev": "webpack --watch --progress --config webpack.dev.config",
33
30
  "dev-server": "dotenv -c -- webpack serve --progress --hot --config webpack.dev-server.config",
34
31
  "dev-test-axe": "TEST_AXE=true npm run dev",
@@ -78,7 +75,6 @@
78
75
  "@testing-library/react-hooks": "^8.0.1",
79
76
  "@testing-library/user-event": "^14.4.3",
80
77
  "@types/jest": "^29.2.6",
81
- "@types/mocha": "^10.0.1",
82
78
  "@types/node": "^25.9.3",
83
79
  "@types/numeral": "^2.0.5",
84
80
  "@types/prop-types": "^15.7.3",
@@ -90,7 +86,6 @@
90
86
  "@types/redux-mock-store": "^1.0.3",
91
87
  "chai": "4.2.0",
92
88
  "clean-webpack-plugin": "^2.0.1",
93
- "colors-cli": "^1.0.27",
94
89
  "copy-webpack-plugin": "14.0.0",
95
90
  "css-loader": "^7.1.4",
96
91
  "dotenv-cli": "^11.0.0",
@@ -111,17 +106,14 @@
111
106
  "jest": "^29.3.1",
112
107
  "jest-environment-jsdom": "^30.4.1",
113
108
  "jest-fixed-jsdom": "^0.0.11",
114
- "jsdom": "^29.1.1",
115
109
  "json-loader": "^0.5.4",
116
110
  "lint-staged": "^17.0.7",
117
111
  "marked": "^18.0.5",
118
112
  "mini-css-extract-plugin": "1.6.0",
119
- "mocha": "^11.7.6",
120
113
  "msw": "^2.7.3",
121
114
  "nightwatch": "^3.14.0",
122
115
  "prettier": "3.8.4",
123
116
  "react-axe": "^3.3.0",
124
- "react-test-renderer": "^16.14.0",
125
117
  "redux-mock-store": "^1.5.4",
126
118
  "resize-observer-polyfill": "^1.5.1",
127
119
  "sass": "^1.64.2",
@@ -133,7 +125,6 @@
133
125
  "terser-webpack-plugin": "^5.3.6",
134
126
  "ts-jest": "^29.2.6",
135
127
  "ts-loader": "^9.5.2",
136
- "ts-node": "^10.9.2",
137
128
  "typedoc": "^0.28.19",
138
129
  "typescript": "^5.7.3",
139
130
  "typescript-eslint": "^8.60.1",
@@ -153,5 +144,5 @@
153
144
  "*.{js,jsx,ts,tsx,css,md}": "prettier --write",
154
145
  "*.{js,css,md}": "prettier --write"
155
146
  },
156
- "version": "1.43.0-post.1"
147
+ "version": "1.43.0-post.3"
157
148
  }
@@ -0,0 +1,13 @@
1
+ import { configure } from "enzyme";
2
+ import * as Adapter from "enzyme-adapter-react-16";
3
+
4
+ // Setup for the legacy enzyme + chai + sinon tests under `src/**/__tests__/`.
5
+ // Replaces what `src/testHelper.ts` did for mocha. Delete alongside the last
6
+ // enzyme test.
7
+
8
+ configure({ adapter: new Adapter() });
9
+
10
+ // Unhandled promise rejections are tolerated for these tests — see the comment in
11
+ // `legacyJsdomEnvironment.js`. It cannot be done from here: jest hands test code a
12
+ // *copy* of `process`, so a listener registered in this file never reaches the real
13
+ // one that Node checks before throwing.
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ const JSDOMEnvironment = require("jest-environment-jsdom").default;
4
+
5
+ const warnUnhandledRejection = (reason) => {
6
+ console.warn("Unhandled promise rejection in a legacy test:", reason);
7
+ };
8
+
9
+ /**
10
+ * jsdom environment for the legacy enzyme tests. Delete it with the last one.
11
+ *
12
+ * Two things it restores that `src/testHelper.ts` used to provide under mocha:
13
+ *
14
+ * 1. `global.jsdom`. A handful of tests call `global.jsdom.reconfigure({ url })` to
15
+ * change the page origin mid-test. `history.replaceState` is not a substitute —
16
+ * they navigate across origins (`http://example.com`), which it cannot do.
17
+ *
18
+ * 2. Tolerance for unhandled promise rejections. Several suites stub a `fetch` that
19
+ * rejects, and nothing awaits the result; the rejection surfaces after the test
20
+ * has already passed. Mocha shrugged those off because its runner keeps an
21
+ * `unhandledRejection` listener installed, and Node only throws when there are
22
+ * none. Under jest they kill the worker and take the whole suite with them.
23
+ *
24
+ * Re-arming has to happen on the `teardown` event, not in the constructor.
25
+ * `jest-circus/globalErrorHandlers` reads `process.listeners()` off the sandbox's
26
+ * *copied* `process` (always empty) but calls `removeAllListeners()` on the real
27
+ * one. So any listener registered earlier is dropped at `setup` and "restored"
28
+ * from an empty list, leaving zero listeners during the post-run window where
29
+ * these rejections actually land.
30
+ *
31
+ * Scoping this to the legacy environment keeps the modern `tests/jest/` suite
32
+ * strict: jest clears listeners at each file's `setup`, and nothing re-arms one
33
+ * for a project that does not use this environment.
34
+ */
35
+ module.exports = class LegacyJSDOMEnvironment extends JSDOMEnvironment {
36
+ constructor(config, context) {
37
+ super(config, context);
38
+ this.global.jsdom = this.dom;
39
+ }
40
+
41
+ handleTestEvent(event) {
42
+ if (
43
+ event.name === "teardown" &&
44
+ process.listenerCount("unhandledRejection") === 0
45
+ ) {
46
+ process.on("unhandledRejection", warnUnhandledRejection);
47
+ }
48
+ }
49
+ };
package/tsconfig.json CHANGED
@@ -6,11 +6,10 @@
6
6
  "outDir": "lib",
7
7
  "lib": ["es2023.array","es2019", "dom"],
8
8
  "rootDir": ".",
9
- // Mocha and jest are both used in this project. Certain globals are declared by both,
10
- // such as describe, it, and test. Setting skipLibCheck to true prevents typescript from
11
- // erroring when it sees duplicate variable declarations with different types.
9
+ // Some dependencies' type declarations (recharts, @open-draft/deferred-promise)
10
+ // do not compile under this project's `target` and `esModuleInterop` settings.
12
11
  "skipLibCheck": true,
13
- "types": ["mocha", "node", "jest", "@testing-library/jest-dom"],
12
+ "types": ["node", "jest", "@testing-library/jest-dom"],
14
13
  "jsx": "react"
15
14
  },
16
15
  "exclude": [
package/testReporter.js DELETED
@@ -1,29 +0,0 @@
1
- const mocha = require("mocha");
2
- const sinon = require("sinon");
3
- const color = require("colors-cli/safe");
4
-
5
- function TestReporter(runner) {
6
- // This isn't the place for warnings about soon-to-be-deprecated React methods, etc; we just want a clean list.
7
- console.warn = sinon.stub();
8
- console.error = sinon.stub();
9
-
10
- const {
11
- EVENT_SUITE_BEGIN,
12
- EVENT_TEST_BEGIN,
13
- EVENT_SUITE_END,
14
- } = mocha.Runner.constants;
15
-
16
- mocha.reporters.Base.call(this, runner);
17
-
18
- runner.on(EVENT_SUITE_BEGIN, function (suite) {
19
- console.group(color.x25.bold(suite.title));
20
- });
21
- runner.on(EVENT_TEST_BEGIN, function (test) {
22
- console.log(test.title);
23
- });
24
- runner.on(EVENT_SUITE_END, function () {
25
- console.groupEnd();
26
- });
27
- }
28
-
29
- module.exports = TestReporter;