diff --git a/.eslintrc b/.eslintrc index 130bd542..2dd694c7 100644 --- a/.eslintrc +++ b/.eslintrc @@ -24,7 +24,7 @@ }, "overrides": [ { - "files": ["*.config.js", "__jest__/**/*.js"], + "files": ["jestSetup.js", "*.config.js", "__jest__/**/*.js"], "env": { "node": true, "browser": false diff --git a/docusaurus-search-local/package.json b/docusaurus-search-local/package.json index f04fcddc..cd43daff 100644 --- a/docusaurus-search-local/package.json +++ b/docusaurus-search-local/package.json @@ -37,7 +37,7 @@ "@docusaurus/utils-validation": "^2 || ^3", "@easyops-cn/autocomplete.js": "^0.38.1", "@node-rs/jieba": "^1.6.0", - "cheerio": "^1.0.0-rc.3", + "cheerio": "^1.0.0", "clsx": "^1.1.1", "debug": "^4.2.0", "fs-extra": "^10.0.0", diff --git a/docusaurus-search-local/src/server/utils/getCondensedText.spec.ts b/docusaurus-search-local/src/server/utils/getCondensedText.spec.ts index a5682a5a..5d5e0f6e 100644 --- a/docusaurus-search-local/src/server/utils/getCondensedText.spec.ts +++ b/docusaurus-search-local/src/server/utils/getCondensedText.spec.ts @@ -1,4 +1,4 @@ -import cheerio from "cheerio"; +import * as cheerio from "cheerio"; import { getCondensedText } from "./getCondensedText"; describe("getCondensedText", () => { diff --git a/docusaurus-search-local/src/server/utils/parse.ts b/docusaurus-search-local/src/server/utils/parse.ts index 22a0d8eb..b483bdc9 100644 --- a/docusaurus-search-local/src/server/utils/parse.ts +++ b/docusaurus-search-local/src/server/utils/parse.ts @@ -1,4 +1,4 @@ -import cheerio from "cheerio"; +import * as cheerio from "cheerio"; import { ParsedDocument, ProcessedPluginOptions, diff --git a/docusaurus-search-local/src/server/utils/parseDocument.spec.ts b/docusaurus-search-local/src/server/utils/parseDocument.spec.ts index b7033087..ccd4e1df 100644 --- a/docusaurus-search-local/src/server/utils/parseDocument.spec.ts +++ b/docusaurus-search-local/src/server/utils/parseDocument.spec.ts @@ -1,4 +1,4 @@ -import cheerio from "cheerio"; +import * as cheerio from "cheerio"; import { ParsedDocument } from "../../shared/interfaces"; import { parseDocument } from "./parseDocument"; diff --git a/docusaurus-search-local/src/server/utils/parsePage.spec.ts b/docusaurus-search-local/src/server/utils/parsePage.spec.ts index c41cec10..e624f59b 100644 --- a/docusaurus-search-local/src/server/utils/parsePage.spec.ts +++ b/docusaurus-search-local/src/server/utils/parsePage.spec.ts @@ -1,4 +1,4 @@ -import cheerio from "cheerio"; +import * as cheerio from "cheerio"; import { ParsedDocument } from "../../shared/interfaces"; import { parsePage } from "./parsePage"; diff --git a/jest.config.js b/jest.config.js index 59304528..bc18ae44 100644 --- a/jest.config.js +++ b/jest.config.js @@ -12,6 +12,7 @@ module.exports = { moduleNameMapper: { "\\.module\\.css$": require.resolve("identity-obj-proxy"), "@docusaurus/Translate": "/__mocks__/Translate.js", + "^cheerio$": require.resolve("cheerio"), }, // Ref https://github.com/facebook/jest/issues/2070#issuecomment-431706685 // Todo(steve): remove next line when issue fixed. diff --git a/jestSetup.js b/jestSetup.js index dc7eb1d8..d96e82fc 100644 --- a/jestSetup.js +++ b/jestSetup.js @@ -1,4 +1,8 @@ import { matcherHint, printExpected, printReceived } from "jest-matcher-utils"; +import { TextEncoder, TextDecoder } from "node:util"; +import { ReadableStream } from "node:stream/web"; + +Object.assign(global, { TextDecoder, TextEncoder, ReadableStream }); const passMessage = (actual, expected) => () => `${matcherHint(".not.toMatchPath")} diff --git a/package.json b/package.json index 80e4d7e8..9a4fdd5a 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "@typescript-eslint/eslint-plugin": "^6.10.0", "@typescript-eslint/parser": "^6.10.0", "babel-jest": "^28.1.0", + "cheerio": "^1.0.0", "cross-env": "^7.0.3", "eslint": "^8.15.0", "eslint-config-prettier": "^8.5.0", diff --git a/yarn.lock b/yarn.lock index 2c8f793f..6c839ab8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3478,7 +3478,7 @@ __metadata: "@types/react": "npm:^18.2.37" "@types/react-helmet": "npm:^6.1.0" "@types/react-router-dom": "npm:^5.1.6" - cheerio: "npm:^1.0.0-rc.3" + cheerio: "npm:^1.0.0" clsx: "npm:^1.1.1" concurrently: "npm:^7.0.0" copyfiles: "npm:^2.4.0" @@ -6436,7 +6436,26 @@ __metadata: languageName: node linkType: hard -"cheerio@npm:^1.0.0-rc.12, cheerio@npm:^1.0.0-rc.3": +"cheerio@npm:^1.0.0": + version: 1.0.0 + resolution: "cheerio@npm:1.0.0" + dependencies: + cheerio-select: "npm:^2.1.0" + dom-serializer: "npm:^2.0.0" + domhandler: "npm:^5.0.3" + domutils: "npm:^3.1.0" + encoding-sniffer: "npm:^0.2.0" + htmlparser2: "npm:^9.1.0" + parse5: "npm:^7.1.2" + parse5-htmlparser2-tree-adapter: "npm:^7.0.0" + parse5-parser-stream: "npm:^7.1.2" + undici: "npm:^6.19.5" + whatwg-mimetype: "npm:^4.0.0" + checksum: b535070add0f86b0a1f234274ad3ffb2c1c375c05b322d8057e89c3c797b3b4d2f05826c34a04df218bec9abf21b9f0d0bd71974a8dfe28b943fb87ab0170c38 + languageName: node + linkType: hard + +"cheerio@npm:^1.0.0-rc.12": version: 1.0.0-rc.12 resolution: "cheerio@npm:1.0.0-rc.12" dependencies: @@ -7740,6 +7759,17 @@ __metadata: languageName: node linkType: hard +"domutils@npm:^3.1.0": + version: 3.1.0 + resolution: "domutils@npm:3.1.0" + dependencies: + dom-serializer: "npm:^2.0.0" + domelementtype: "npm:^2.3.0" + domhandler: "npm:^5.0.3" + checksum: 9a169a6e57ac4c738269a73ab4caf785114ed70e46254139c1bbc8144ac3102aacb28a6149508395ae34aa5d6a40081f4fa5313855dc8319c6d8359866b6dfea + languageName: node + linkType: hard + "dot-case@npm:^3.0.4": version: 3.0.4 resolution: "dot-case@npm:3.0.4" @@ -7843,6 +7873,16 @@ __metadata: languageName: node linkType: hard +"encoding-sniffer@npm:^0.2.0": + version: 0.2.0 + resolution: "encoding-sniffer@npm:0.2.0" + dependencies: + iconv-lite: "npm:^0.6.3" + whatwg-encoding: "npm:^3.1.1" + checksum: fe61a759dbef4d94ddc6f4fa645459897f4275eba04f0135d0459099b5f62fbba8a7ae57d23c9ec9b118c4c39ce056b51f1b8e62ad73a8ab365699448d655f4c + languageName: node + linkType: hard + "encoding@npm:^0.1.13": version: 0.1.13 resolution: "encoding@npm:0.1.13" @@ -7876,7 +7916,7 @@ __metadata: languageName: node linkType: hard -"entities@npm:^4.4.0": +"entities@npm:^4.4.0, entities@npm:^4.5.0": version: 4.5.0 resolution: "entities@npm:4.5.0" checksum: ede2a35c9bce1aeccd055a1b445d41c75a14a2bb1cd22e242f20cf04d236cdcd7f9c859eb83f76885327bfae0c25bf03303665ee1ce3d47c5927b98b0e3e3d48 @@ -9530,6 +9570,18 @@ __metadata: languageName: node linkType: hard +"htmlparser2@npm:^9.1.0": + version: 9.1.0 + resolution: "htmlparser2@npm:9.1.0" + dependencies: + domelementtype: "npm:^2.3.0" + domhandler: "npm:^5.0.3" + domutils: "npm:^3.1.0" + entities: "npm:^4.5.0" + checksum: 6352fa2a5495781fa9a02c9049908334cd068ff36d753870d30cd13b841e99c19646717567a2f9e9c44075bbe43d364e102f9d013a731ce962226d63746b794f + languageName: node + linkType: hard + "http-cache-semantics@npm:^4.1.0": version: 4.1.0 resolution: "http-cache-semantics@npm:4.1.0" @@ -9684,7 +9736,7 @@ __metadata: languageName: node linkType: hard -"iconv-lite@npm:0.6.3, iconv-lite@npm:^0.6.2": +"iconv-lite@npm:0.6.3, iconv-lite@npm:^0.6.2, iconv-lite@npm:^0.6.3": version: 0.6.3 resolution: "iconv-lite@npm:0.6.3" dependencies: @@ -13114,6 +13166,15 @@ __metadata: languageName: node linkType: hard +"parse5-parser-stream@npm:^7.1.2": + version: 7.1.2 + resolution: "parse5-parser-stream@npm:7.1.2" + dependencies: + parse5: "npm:^7.0.0" + checksum: 75b232d460bce6bd0e35012750a78ef034f40ccf550b7c6cec3122395af6b4553202ad3663ad468cf537ead5a2e13b6727670395fd0ff548faccad1dc2dc93cf + languageName: node + linkType: hard + "parse5@npm:6.0.1": version: 6.0.1 resolution: "parse5@npm:6.0.1" @@ -13130,6 +13191,15 @@ __metadata: languageName: node linkType: hard +"parse5@npm:^7.1.2": + version: 7.1.2 + resolution: "parse5@npm:7.1.2" + dependencies: + entities: "npm:^4.4.0" + checksum: 3c86806bb0fb1e9a999ff3a4c883b1ca243d99f45a619a0898dbf021a95a0189ed955c31b07fe49d342b54e814f33f2c9d7489198e8630dacd5477d413ec5782 + languageName: node + linkType: hard + "parseurl@npm:~1.3.2, parseurl@npm:~1.3.3": version: 1.3.3 resolution: "parseurl@npm:1.3.3" @@ -14839,6 +14909,7 @@ __metadata: "@typescript-eslint/eslint-plugin": "npm:^6.10.0" "@typescript-eslint/parser": "npm:^6.10.0" babel-jest: "npm:^28.1.0" + cheerio: "npm:^1.0.0" cross-env: "npm:^7.0.3" eslint: "npm:^8.15.0" eslint-config-prettier: "npm:^8.5.0" @@ -16243,6 +16314,13 @@ __metadata: languageName: node linkType: hard +"undici@npm:^6.19.5": + version: 6.19.7 + resolution: "undici@npm:6.19.7" + checksum: 77fb8b0377388f6dba8244b015841318d621031211b4f3c2273d809304b77ec44adeba4b89dfd6708bdc044190e18f068e5b231882ef15d057d4624e46f544e3 + languageName: node + linkType: hard + "unicode-canonical-property-names-ecmascript@npm:^2.0.0": version: 2.0.0 resolution: "unicode-canonical-property-names-ecmascript@npm:2.0.0" @@ -16938,6 +17016,15 @@ __metadata: languageName: node linkType: hard +"whatwg-encoding@npm:^3.1.1": + version: 3.1.1 + resolution: "whatwg-encoding@npm:3.1.1" + dependencies: + iconv-lite: "npm:0.6.3" + checksum: bbef815eb67f91487c7f2ef96329743f5fd8357d7d62b1119237d25d41c7e452dff8197235b2d3c031365a17f61d3bb73ca49d0ed1582475aa4a670815e79534 + languageName: node + linkType: hard + "whatwg-mimetype@npm:^3.0.0": version: 3.0.0 resolution: "whatwg-mimetype@npm:3.0.0" @@ -16945,6 +17032,13 @@ __metadata: languageName: node linkType: hard +"whatwg-mimetype@npm:^4.0.0": + version: 4.0.0 + resolution: "whatwg-mimetype@npm:4.0.0" + checksum: 894a618e2d90bf444b6f309f3ceb6e58cf21b2beaa00c8b333696958c4076f0c7b30b9d33413c9ffff7c5832a0a0c8569e5bb347ef44beded72aeefd0acd62e8 + languageName: node + linkType: hard + "whatwg-url@npm:^10.0.0": version: 10.0.0 resolution: "whatwg-url@npm:10.0.0"