Skip to content

Commit

Permalink
Merge pull request #18595 from dannon/verbatimModuleSyntax
Browse files Browse the repository at this point in the history
Enable verbatimModuleSyntax, fix jest usage
  • Loading branch information
davelopez authored Aug 6, 2024
2 parents 7b34535 + 4036113 commit db9ff9e
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 35 deletions.
6 changes: 3 additions & 3 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@popperjs/core": "^2.11.8",
"@sentry/browser": "^7.74.1",
"@sentry/vue": "^7.114.0",
"@types/jest": "^29.5.6",
"@types/jest": "^29.5.12",
"@vueuse/core": "^10.5.0",
"@vueuse/math": "^10.9.0",
"assert": "^2.1.0",
Expand Down Expand Up @@ -142,7 +142,7 @@
"@babel/preset-typescript": "^7.23.2",
"@cerner/duplicate-package-checker-webpack-plugin": "^2.3.0",
"@pinia/testing": "0.1.3",
"@testing-library/jest-dom": "^6.1.4",
"@testing-library/jest-dom": "^6.4.8",
"@types/d3": "^7.4.2",
"@types/dompurify": "^3.0.2",
"@types/jquery": "^3.5.24",
Expand Down Expand Up @@ -189,7 +189,7 @@
"sass-loader": "^13.3.2",
"store": "^2.0.12",
"style-loader": "^3.3.3",
"ts-jest": "^29.1.1",
"ts-jest": "^29.2.3",
"ts-loader": "^9.5.0",
"tsconfig-paths-webpack-plugin": "^4.1.0",
"typescript": "^5.2.2",
Expand Down
3 changes: 3 additions & 0 deletions client/src/onload/getRootFromIndexLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { serverPath } from "@/utils/serverPath";
* @returns {string}
*/
export function getRootFromIndexLink(defaultRoot = "/"): string {
if (typeof document === "undefined") {
return defaultRoot;
}
const links = document.getElementsByTagName("link");
const indexLink = Array.from(links).find((link) => link.rel == "index");
return indexLink && indexLink.href ? serverPath(indexLink.href) : defaultRoot;
Expand Down
22 changes: 21 additions & 1 deletion client/tests/jest/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@ const modulesToTransform = [
"openapi-typescript-fetch",
].join("|");

// Override verbatimModuleSyntax to false to allow jest to transform the module syntax like it wants.
// This is necessary to allow jest to transform the module syntax to commonjs, which is necessary for
// jest to work properly. I think.

const configOverride = {
"^.+.tsx?$": [
"ts-jest",
{
tsconfig: {
verbatimModuleSyntax: false,
},
},
],
};

const mergedTSJTransform = {
...tsjPreset.transform,
...configOverride,
};

module.exports = {
preset: "ts-jest",
clearMocks: true,
Expand Down Expand Up @@ -48,7 +68,7 @@ module.exports = {
"^.*\\.(vue)$": "@vue/vue2-jest",
"^.+\\.ya?ml$": "<rootDir>/tests/jest/yaml-jest.js",
"^.+\\.txt$": "<rootDir>/tests/jest/jest-raw-loader.js",
...tsjPreset.transform,
...mergedTSJTransform,
},
transformIgnorePatterns: [`/node_modules/(?!${modulesToTransform})`],
};
8 changes: 1 addition & 7 deletions client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@
"target": "es2016",
"module": "es2020",

// @vue/tsconfig now sets this by default, but this doesn't play well
// with the ts-jest presets.
// It doesn't seem to have any immediate impact, and may not be worth
// fighting with as we want to swap to vitest anyway
// TODO: revisit and drop this override
// See https://www.typescriptlang.org/tsconfig#verbatimModuleSyntax for context
"verbatimModuleSyntax": false,
"verbatimModuleSyntax": true,

"baseUrl": ".",
"paths": {
Expand Down
78 changes: 54 additions & 24 deletions client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
resolved "https://registry.yarnpkg.com/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz#bd9154aec9983f77b3a034ecaa015c2e4201f6cf"
integrity sha512-1Yjs2SvM8TflER/OD3cOjhWWOZb58A2t7wpE2S9XfBYTiIl+XFhQG2bjy4Pu1I+EAlCNUzRDYDdFwFYUKvXcIA==

"@adobe/css-tools@^4.3.1":
version "4.3.2"
resolved "https://registry.yarnpkg.com/@adobe/css-tools/-/css-tools-4.3.2.tgz#a6abc715fb6884851fca9dad37fc34739a04fd11"
integrity sha512-DA5a1C0gD/pLOvhv33YMrbf2FK3oUzwNl9oOJqE4XVjuEtt6XIakRcsd7eLiOSPkp1kTRQGICTA8cKra/vFbjw==
"@adobe/css-tools@^4.4.0":
version "4.4.0"
resolved "https://registry.yarnpkg.com/@adobe/css-tools/-/css-tools-4.4.0.tgz#728c484f4e10df03d5a3acd0d8adcbbebff8ad63"
integrity sha512-Ff9+ksdQQB3rMncgqDK78uLznstjyfIf2Arnh22pW8kBpLs6rpKDwgnZT46hin5Hl1WzazzK64DOrhSwYpS7bQ==

"@ampproject/remapping@^2.1.0":
version "2.2.0"
Expand Down Expand Up @@ -2083,18 +2083,18 @@
dependencies:
"@sinonjs/commons" "^3.0.0"

"@testing-library/jest-dom@^6.1.4":
version "6.1.4"
resolved "https://registry.yarnpkg.com/@testing-library/jest-dom/-/jest-dom-6.1.4.tgz#cf0835c33bc5ef00befb9e672b1e3e6a710e30e3"
integrity sha512-wpoYrCYwSZ5/AxcrjLxJmCU6I5QAJXslEeSiMQqaWmP2Kzpd1LvF/qxmAIW2qposULGWq2gw30GgVNFLSc2Jnw==
"@testing-library/jest-dom@^6.4.8":
version "6.4.8"
resolved "https://registry.yarnpkg.com/@testing-library/jest-dom/-/jest-dom-6.4.8.tgz#9c435742b20c6183d4e7034f2b329d562c079daa"
integrity sha512-JD0G+Zc38f5MBHA4NgxQMR5XtO5Jx9g86jqturNTt2WUfRmLDIY7iKkWHDCCTiDuFMre6nxAD5wHw9W5kI4rGw==
dependencies:
"@adobe/css-tools" "^4.3.1"
"@adobe/css-tools" "^4.4.0"
"@babel/runtime" "^7.9.2"
aria-query "^5.0.0"
chalk "^3.0.0"
css.escape "^1.5.1"
dom-accessibility-api "^0.5.6"
lodash "^4.17.15"
dom-accessibility-api "^0.6.3"
lodash "^4.17.21"
redent "^3.0.0"

"@tootallnate/once@2":
Expand Down Expand Up @@ -2480,10 +2480,10 @@
dependencies:
"@types/istanbul-lib-report" "*"

"@types/jest@^29.5.6":
version "29.5.6"
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-29.5.6.tgz#f4cf7ef1b5b0bfc1aa744e41b24d9cc52533130b"
integrity sha512-/t9NnzkOpXb4Nfvg17ieHE6EeSjDS2SGSpNYfoLbUAeL/EOueU/RSdOWFpfQTXBEM7BguYW1XQ0EbM+6RlIh6w==
"@types/jest@^29.5.12":
version "29.5.12"
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-29.5.12.tgz#7f7dc6eb4cf246d2474ed78744b05d06ce025544"
integrity sha512-eDC8bTvT/QhYdxJAulQikueigY5AsdBRH2yDKW3yveW7svY3+DzN84/2NUgkw10RTiJbWqZrTtoGVdYlvFJdLw==
dependencies:
expect "^29.0.0"
pretty-format "^29.0.0"
Expand Down Expand Up @@ -3584,6 +3584,11 @@ async-settle@^1.0.0:
dependencies:
async-done "^1.2.2"

async@^3.2.3:
version "3.2.5"
resolved "https://registry.yarnpkg.com/async/-/async-3.2.5.tgz#ebd52a8fdaf7a2289a24df399f8d8485c8a46b66"
integrity sha512-baNZyqaaLhyLVKm/DlvdW051MSgO6b8eVfIezl9E5PqWxFgzLm/wQntEW4zOytVburDEr0JlALEpdOFwvErLsg==

asynckit@^0.4.0:
version "0.4.0"
resolved "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz"
Expand Down Expand Up @@ -4080,7 +4085,7 @@ chalk@^3.0.0:
ansi-styles "^4.1.0"
supports-color "^7.1.0"

chalk@^4.0.0, chalk@^4.1.0, chalk@~4.1.0:
chalk@^4.0.0, chalk@^4.0.2, chalk@^4.1.0, chalk@~4.1.0:
version "4.1.2"
resolved "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz"
integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==
Expand Down Expand Up @@ -5211,10 +5216,10 @@ doctrine@^3.0.0:
dependencies:
esutils "^2.0.2"

dom-accessibility-api@^0.5.6:
version "0.5.14"
resolved "https://registry.npmjs.org/dom-accessibility-api/-/dom-accessibility-api-0.5.14.tgz"
integrity sha512-NMt+m9zFMPZe0JcY9gN224Qvk6qLIdqex29clBvc/y75ZBX9YA9wNK3frsYvu2DI1xcCIwxwnX+TlsJ2DSOADg==
dom-accessibility-api@^0.6.3:
version "0.6.3"
resolved "https://registry.yarnpkg.com/dom-accessibility-api/-/dom-accessibility-api-0.6.3.tgz#993e925cc1d73f2c662e7d75dd5a5445259a8fd8"
integrity sha512-7ZgogeTnjuHbo+ct10G9Ffp0mif17idi0IyWNVA/wcwcm7NPOD/WEHVP3n7n3MhXqxoIYm8d6MuZohYWIZ4T3w==

dom-event-types@^1.0.0:
version "1.1.0"
Expand Down Expand Up @@ -5318,6 +5323,13 @@ [email protected]:
resolved "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz"
integrity sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==

ejs@^3.1.10:
version "3.1.10"
resolved "https://registry.yarnpkg.com/ejs/-/ejs-3.1.10.tgz#69ab8358b14e896f80cc39e62087b88500c3ac3b"
integrity sha512-UeJmFfOrAQS8OJWPZ4qtgHyWExa088/MtK5UEyoJGFH67cDEXkZSviOiKRCZ4Xij0zxI3JECgYs3oKx+AizQBA==
dependencies:
jake "^10.8.5"

electron-to-chromium@^1.4.202:
version "1.4.213"
resolved "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.213.tgz"
Expand Down Expand Up @@ -6128,6 +6140,13 @@ file-saver@^2.0.5:
resolved "https://registry.npmjs.org/file-saver/-/file-saver-2.0.5.tgz"
integrity sha512-P9bmyZ3h/PRG+Nzga+rbdI4OEpNDzAVyy74uVO9ATgzLK6VtAsYybF/+TOCvrc0MO793d6+42lLyZTw7/ArVzA==

filelist@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/filelist/-/filelist-1.0.4.tgz#f78978a1e944775ff9e62e744424f215e58352b5"
integrity sha512-w1cEuf3S+DrLCQL7ET6kz+gmlJdbq9J7yXCSjK/OZCPA+qEN1WyF4ZAf0YYJa4/shHJra2t/d/r8SV4Ji+x+8Q==
dependencies:
minimatch "^5.0.1"

fill-range@^4.0.0:
version "4.0.0"
resolved "https://registry.npmjs.org/fill-range/-/fill-range-4.0.0.tgz"
Expand Down Expand Up @@ -7484,6 +7503,16 @@ jackspeak@^2.3.5:
optionalDependencies:
"@pkgjs/parseargs" "^0.11.0"

jake@^10.8.5:
version "10.9.2"
resolved "https://registry.yarnpkg.com/jake/-/jake-10.9.2.tgz#6ae487e6a69afec3a5e167628996b59f35ae2b7f"
integrity sha512-2P4SQ0HrLQ+fw6llpLnOaGAvN2Zu6778SJMrCUwns4fOoG9ayrTiZk3VV8sCPkVZF8ab0zksVpS8FDY5pRCNBA==
dependencies:
async "^3.2.3"
chalk "^4.0.2"
filelist "^1.0.4"
minimatch "^3.1.2"

javascript-stringify@^2.0.1:
version "2.1.0"
resolved "https://registry.npmjs.org/javascript-stringify/-/javascript-stringify-2.1.0.tgz"
Expand Down Expand Up @@ -11233,12 +11262,13 @@ ts-api-utils@^1.0.1:
resolved "https://registry.yarnpkg.com/ts-api-utils/-/ts-api-utils-1.0.3.tgz#f12c1c781d04427313dbac808f453f050e54a331"
integrity sha512-wNMeqtMz5NtwpT/UZGY5alT+VoKdSsOOP/kqHFcUW1P/VRhH2wJ48+DN2WwUliNbQ976ETwDL0Ifd2VVvgonvg==

ts-jest@^29.1.1:
version "29.1.1"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-29.1.1.tgz#f58fe62c63caf7bfcc5cc6472082f79180f0815b"
integrity sha512-D6xjnnbP17cC85nliwGiL+tpoKN0StpgE0TeOjXQTU6MVCfsB4v7aW05CgQ/1OywGb0x/oy9hHFnN+sczTiRaA==
ts-jest@^29.2.3:
version "29.2.3"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-29.2.3.tgz#3d226ac36b8b820151a38f164414f9f6b412131f"
integrity sha512-yCcfVdiBFngVz9/keHin9EnsrQtQtEu3nRykNy9RVp+FiPFFbPJ3Sg6Qg4+TkmH0vMP5qsTKgXSsk80HRwvdgQ==
dependencies:
bs-logger "0.x"
ejs "^3.1.10"
fast-json-stable-stringify "2.x"
jest-util "^29.0.0"
json5 "^2.2.3"
Expand Down

0 comments on commit db9ff9e

Please sign in to comment.