@thepalaceproject/circulation-admin 1.43.0-post.2 → 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/CLAUDE.md +14 -12
- package/dist/circulation-admin.js +1 -1
- package/jest.config.js +48 -16
- package/package.json +4 -17
- package/tests/jest/legacy-setup.ts +13 -0
- package/tests/jest/legacyJsdomEnvironment.js +49 -0
- package/tsconfig.json +3 -4
- package/.nycrc.json +0 -8
- package/testReporter.js +0 -29
package/jest.config.js
CHANGED
|
@@ -1,31 +1,63 @@
|
|
|
1
1
|
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
|
2
|
-
|
|
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"],
|
|
16
19
|
// `src` must stay in `roots` so that `collectCoverageFrom` can discover source
|
|
17
|
-
// files that no
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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 = {
|
|
23
27
|
coverageDirectory: "coverage/jest",
|
|
24
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/`.
|
|
25
33
|
collectCoverageFrom: [
|
|
26
34
|
"src/**/*.{ts,tsx}",
|
|
27
35
|
"!src/**/__tests__/**",
|
|
28
|
-
"!src/testHelper.ts",
|
|
29
36
|
"!src/**/*.d.ts",
|
|
30
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
|
+
],
|
|
31
63
|
};
|
package/package.json
CHANGED
|
@@ -17,20 +17,14 @@
|
|
|
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
|
|
21
|
-
"test-
|
|
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
25
|
"test-jest": "jest --verbose",
|
|
31
26
|
"test-jest-file": "jest --verbose",
|
|
32
|
-
"coverage": "npm run coverage-
|
|
33
|
-
"coverage-ts": "nyc npm run test-ts",
|
|
27
|
+
"coverage": "npm run coverage-jest",
|
|
34
28
|
"coverage-jest": "npm run test-jest -- --coverage",
|
|
35
29
|
"dev": "webpack --watch --progress --config webpack.dev.config",
|
|
36
30
|
"dev-server": "dotenv -c -- webpack serve --progress --hot --config webpack.dev-server.config",
|
|
@@ -81,7 +75,6 @@
|
|
|
81
75
|
"@testing-library/react-hooks": "^8.0.1",
|
|
82
76
|
"@testing-library/user-event": "^14.4.3",
|
|
83
77
|
"@types/jest": "^29.2.6",
|
|
84
|
-
"@types/mocha": "^10.0.1",
|
|
85
78
|
"@types/node": "^25.9.3",
|
|
86
79
|
"@types/numeral": "^2.0.5",
|
|
87
80
|
"@types/prop-types": "^15.7.3",
|
|
@@ -93,7 +86,6 @@
|
|
|
93
86
|
"@types/redux-mock-store": "^1.0.3",
|
|
94
87
|
"chai": "4.2.0",
|
|
95
88
|
"clean-webpack-plugin": "^2.0.1",
|
|
96
|
-
"colors-cli": "^1.0.27",
|
|
97
89
|
"copy-webpack-plugin": "14.0.0",
|
|
98
90
|
"css-loader": "^7.1.4",
|
|
99
91
|
"dotenv-cli": "^11.0.0",
|
|
@@ -114,18 +106,14 @@
|
|
|
114
106
|
"jest": "^29.3.1",
|
|
115
107
|
"jest-environment-jsdom": "^30.4.1",
|
|
116
108
|
"jest-fixed-jsdom": "^0.0.11",
|
|
117
|
-
"jsdom": "^29.1.1",
|
|
118
109
|
"json-loader": "^0.5.4",
|
|
119
110
|
"lint-staged": "^17.0.7",
|
|
120
111
|
"marked": "^18.0.5",
|
|
121
112
|
"mini-css-extract-plugin": "1.6.0",
|
|
122
|
-
"mocha": "^11.7.6",
|
|
123
113
|
"msw": "^2.7.3",
|
|
124
114
|
"nightwatch": "^3.14.0",
|
|
125
|
-
"nyc": "^17.1.0",
|
|
126
115
|
"prettier": "3.8.4",
|
|
127
116
|
"react-axe": "^3.3.0",
|
|
128
|
-
"react-test-renderer": "^16.14.0",
|
|
129
117
|
"redux-mock-store": "^1.5.4",
|
|
130
118
|
"resize-observer-polyfill": "^1.5.1",
|
|
131
119
|
"sass": "^1.64.2",
|
|
@@ -137,7 +125,6 @@
|
|
|
137
125
|
"terser-webpack-plugin": "^5.3.6",
|
|
138
126
|
"ts-jest": "^29.2.6",
|
|
139
127
|
"ts-loader": "^9.5.2",
|
|
140
|
-
"ts-node": "^10.9.2",
|
|
141
128
|
"typedoc": "^0.28.19",
|
|
142
129
|
"typescript": "^5.7.3",
|
|
143
130
|
"typescript-eslint": "^8.60.1",
|
|
@@ -157,5 +144,5 @@
|
|
|
157
144
|
"*.{js,jsx,ts,tsx,css,md}": "prettier --write",
|
|
158
145
|
"*.{js,css,md}": "prettier --write"
|
|
159
146
|
},
|
|
160
|
-
"version": "1.43.0-post.
|
|
147
|
+
"version": "1.43.0-post.3"
|
|
161
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
|
-
//
|
|
10
|
-
//
|
|
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": ["
|
|
12
|
+
"types": ["node", "jest", "@testing-library/jest-dom"],
|
|
14
13
|
"jsx": "react"
|
|
15
14
|
},
|
|
16
15
|
"exclude": [
|
package/.nycrc.json
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://json.schemastore.org/nycrc",
|
|
3
|
-
"extension": [".ts", ".tsx"],
|
|
4
|
-
"include": ["src/**/*.ts", "src/**/*.tsx"],
|
|
5
|
-
"exclude": ["src/**/__tests__/**", "src/testHelper.ts", "**/*.d.ts"],
|
|
6
|
-
"reporter": ["lcov", "text-summary"],
|
|
7
|
-
"report-dir": "coverage/mocha"
|
|
8
|
-
}
|
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;
|