Skip to content
This repository was archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
Move from ts-jest to @swc/jest
Browse files Browse the repository at this point in the history
  • Loading branch information
queicherius committed Aug 8, 2023
1 parent 161c2f6 commit bb47b24
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 43 deletions.
5 changes: 4 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module.exports = {
preset: 'ts-jest',
transform: { '^.+\\.tsx?$': '@swc/jest' },
coverageProvider: 'v8',
testEnvironment: 'node',
modulePathIgnorePatterns: ['<rootDir>/dist'],
collectCoverageFrom: ['<rootDir>/src/**/*'],
coverageThreshold: { global: { branches: 100, functions: 100, lines: 100, statements: 100 } },
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@
"@babel/types": "7.21.5",
"@devoxa/eslint-config": "3.0.11",
"@devoxa/prettier-config": "2.0.2",
"@swc/core": "1.3.75",
"@swc/jest": "0.2.28",
"@types/jest": "29.5.3",
"@types/node": "18.17.3",
"eslint": "8.46.0",
"jest": "29.6.2",
"prettier": "3.0.1",
"ts-jest": "29.1.1",
"typescript": "5.1.6"
},
"publishConfig": {
Expand Down
4 changes: 2 additions & 2 deletions src/astToKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function astToKey(ast: AbstractSyntaxTree, options: AstToKeyOptions): str
// This is an interpolated variable, like "t(`<Trans>Foo {{bar}}</Trans>`)" in JSX components.
// "t('Foo {{bar}}')" in template strings is handled like a string literal.
if (options.jsx && astNode.type === 'ObjectExpression') {
// istanbul ignore next
/* c8 ignore next 3 */
if (!astNode.start || !astNode.end) {
throw new Error('Start or end of a AST node are missing, please file a bug report!')
}
Expand Down Expand Up @@ -138,7 +138,7 @@ function printCodeRange(code: string, start: number, end: number, padding: numbe
const slicedCode = code.slice(start, end)
const slicedEndPadding = code.slice(end, Math.min(code.length, end + padding))

// istanbul ignore next
/* c8 ignore next */
const format = process.env.NODE_ENV === 'test' ? (x: string) => x : colors.red

return slicedStartPadding + format(slicedCode) + slicedEndPadding
Expand Down
4 changes: 2 additions & 2 deletions src/babel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function nextI18nextCompressBabelPlugin(babel: Babel): {

const options = mergeDefaultOptions(state.opts)

// istanbul ignore next
/* c8 ignore next */
if (processedNodes.has(path.node)) return

// Only handle functions with the name `t` and at least one argument
Expand Down Expand Up @@ -81,7 +81,7 @@ export default function nextI18nextCompressBabelPlugin(babel: Babel): {

const options = mergeDefaultOptions(state.opts)

// istanbul ignore next
/* c8 ignore next */
if (processedNodes.has(path.node)) return

// Only handle JSX elements with the name `Trans`
Expand Down
7 changes: 5 additions & 2 deletions tests/parseLocaleFile.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import * as compressKeyModule from '../src/compressKey'
import { parseLocaleFile } from '../src/parseLocaleFile'

const compressKeySpy = jest.spyOn(compressKeyModule, 'compressKey')
jest.mock('../src/compressKey')
const mockCompressKey = jest
.mocked(compressKeyModule.compressKey)
.mockImplementation(jest.requireActual('../src/compressKey').compressKey)

const localeFileString = JSON.stringify({
'Email address': 'E-Mail Adresse',
Expand All @@ -22,7 +25,7 @@ describe('parseLocaleFile', () => {
})

test('throws an error if there are any compression collisions', async () => {
compressKeySpy.mockImplementation(() => 'foobar')
mockCompressKey.mockImplementation(() => 'foobar')
expect(() => parseLocaleFile(localeFileString)).toThrowErrorMatchingSnapshot()
})

Expand Down
143 changes: 108 additions & 35 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,13 @@
slash "^3.0.0"
strip-ansi "^6.0.0"

"@jest/create-cache-key-function@^27.4.2":
version "27.5.1"
resolved "https://registry.yarnpkg.com/@jest/create-cache-key-function/-/create-cache-key-function-27.5.1.tgz#7448fae15602ea95c828f5eceed35c202a820b31"
integrity sha512-dmH1yW+makpTSURTy8VzdUwFnfQh1G8R+DxO2Ho2FFmBbKFEVm+3jWdvFhE2VqB/LATCTokkP0dotjyQyw5/AQ==
dependencies:
"@jest/types" "^27.5.1"

"@jest/environment@^29.6.2":
version "29.6.2"
resolved "https://registry.yarnpkg.com/@jest/environment/-/environment-29.6.2.tgz#794c0f769d85e7553439d107d3f43186dc6874a9"
Expand Down Expand Up @@ -1095,6 +1102,17 @@
slash "^3.0.0"
write-file-atomic "^4.0.2"

"@jest/types@^27.5.1":
version "27.5.1"
resolved "https://registry.yarnpkg.com/@jest/types/-/types-27.5.1.tgz#3c79ec4a8ba61c170bf937bcf9e98a9df175ec80"
integrity sha512-Cx46iJ9QpwQTjIdq5VJu2QTMMs3QlEjI0x1QbBP5W1+nMzyc2XmimiRR/CbX9TO0cPTeUlxWMOu8mslYsJ8DEw==
dependencies:
"@types/istanbul-lib-coverage" "^2.0.0"
"@types/istanbul-reports" "^3.0.0"
"@types/node" "*"
"@types/yargs" "^16.0.0"
chalk "^4.0.0"

"@jest/types@^29.2.0":
version "29.2.0"
resolved "https://registry.yarnpkg.com/@jest/types/-/types-29.2.0.tgz#c0d1ef8bc1e4f4b358e7877e34157371e7881b0b"
Expand Down Expand Up @@ -1272,6 +1290,80 @@
dependencies:
"@sinonjs/commons" "^2.0.0"

"@swc/[email protected]":
version "1.3.75"
resolved "https://registry.yarnpkg.com/@swc/core-darwin-arm64/-/core-darwin-arm64-1.3.75.tgz#f6b2fb9dd03839ff3153902e09f1772963a1bbb6"
integrity sha512-anDnx9L465lGbjB2mvcV54NGHW6illr0IDvVV7JmkabYUVneaRdQvTr0tbHv3xjHnjrK1wuwVOHKV0LcQF2tnQ==

"@swc/[email protected]":
version "1.3.75"
resolved "https://registry.yarnpkg.com/@swc/core-darwin-x64/-/core-darwin-x64-1.3.75.tgz#b5a4fcc668f15fe664c9bdddac12b7c0685e6c81"
integrity sha512-dIHDfrLmeZfr2xwi1whO7AmzdI3HdamgvxthaL+S8L1x8TeczAZEvsmZTjy3s8p3Va4rbGXcb3+uBhmfkqCbfw==

"@swc/[email protected]":
version "1.3.75"
resolved "https://registry.yarnpkg.com/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.3.75.tgz#a4b19babc256390790b50d75dd300a3201275f9f"
integrity sha512-qeJmvMGrjC6xt+G0R4kVqqxvlhxJx7tTzhcEoWgLJnfvGZiF6SJdsef4OSM7HuReXrlBoEtJbfGPrLJtbV+C0w==

"@swc/[email protected]":
version "1.3.75"
resolved "https://registry.yarnpkg.com/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.3.75.tgz#347e44d12a3fd71e9fc109b68a7fff81696ecbc3"
integrity sha512-sqA9JqHEJBF4AdNuwo5zRqq0HC3l31SPsG9zpRa4nRzG5daBBJ80H7fi6PZQud1rfNNq+Q08gjYrdrxwHstvjw==

"@swc/[email protected]":
version "1.3.75"
resolved "https://registry.yarnpkg.com/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.3.75.tgz#ca21e597ff52c0a25848be1838cd923a32963584"
integrity sha512-95rQT5xTAL3eKhMJbJbLsZHHP9EUlh1rcrFoLf0gUApoVF8g94QjZ9hYZiI72mMP5WPjgTEXQVnVB9O2GxeaLw==

"@swc/[email protected]":
version "1.3.75"
resolved "https://registry.yarnpkg.com/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.3.75.tgz#56abe19475a72bdc5333461b55ca3c2cd60e4611"
integrity sha512-If7UpAhnPduMmtC+TSgPpZ1UXZfp2hIpjUFxpeCmHHYLS6Fn/2GZC5hpEiu+wvFJF0hzPh93eNAHa9gUxGUG+w==

"@swc/[email protected]":
version "1.3.75"
resolved "https://registry.yarnpkg.com/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.3.75.tgz#bfa90d24071930effeb4514540f89266a6d6957a"
integrity sha512-HOhxX0YNHTElCZqIviquka3CGYTN8rSQ6BdFfSk/K0O+ZEHx3qGte0qr+gGLPF/237GxreUkp3OMaWKuURtuCg==

"@swc/[email protected]":
version "1.3.75"
resolved "https://registry.yarnpkg.com/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.3.75.tgz#2fd8ea75ffe1a9153c523b6135b7169266a60e54"
integrity sha512-7QPI+mvBXAerVfWahrgBNe+g7fK8PuetxFnZSEmXUcDXvWcdJXAndD7GjAJzbDyjQpLKHbsDKMiHYvfNxZoN/A==

"@swc/[email protected]":
version "1.3.75"
resolved "https://registry.yarnpkg.com/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.3.75.tgz#9dae46582027ffeb03f258d05ab797701250d465"
integrity sha512-EfABCy4Wlq7O5ShWsm32FgDkSjyeyj/SQ4wnUIvWpkXhgfT1iNXky7KRU1HtX+SmnVk/k/NnabVZpIklYbjtZA==

"@swc/[email protected]":
version "1.3.75"
resolved "https://registry.yarnpkg.com/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.3.75.tgz#c8e6d30c5deed1ae0fa162a42d6d9ef165b8041f"
integrity sha512-cTvP0pOD9C3pSp1cwtt85ZsrUkQz8RZfSPhM+jCGxKxmoowDCnInoOQ4Ica/ehyuUnQ4/IstSdYtYpO5yzPDJg==

"@swc/[email protected]":
version "1.3.75"
resolved "https://registry.yarnpkg.com/@swc/core/-/core-1.3.75.tgz#b06d32144a5be0b7b25dbbff09dcd1ab18e48b67"
integrity sha512-YLqd5oZVnaOq/OzkjRSsJUQqAfKYiD0fzUyVUPVlNNCoQEfVfSMcXH80hLmYe9aDH0T/a7qEMjWyIr/0kWqy1A==
optionalDependencies:
"@swc/core-darwin-arm64" "1.3.75"
"@swc/core-darwin-x64" "1.3.75"
"@swc/core-linux-arm-gnueabihf" "1.3.75"
"@swc/core-linux-arm64-gnu" "1.3.75"
"@swc/core-linux-arm64-musl" "1.3.75"
"@swc/core-linux-x64-gnu" "1.3.75"
"@swc/core-linux-x64-musl" "1.3.75"
"@swc/core-win32-arm64-msvc" "1.3.75"
"@swc/core-win32-ia32-msvc" "1.3.75"
"@swc/core-win32-x64-msvc" "1.3.75"

"@swc/[email protected]":
version "0.2.28"
resolved "https://registry.yarnpkg.com/@swc/jest/-/jest-0.2.28.tgz#cf21200a6058ab0dd2555b3ee1164d149bd8534b"
integrity sha512-iCB3lvngkQldLga35krb8LPa+6gmkVXnlpfCTXOAgMaEYFagLxOIFbIO8II7dhHa8ApOv5ap8iFRETI4lVY0vw==
dependencies:
"@jest/create-cache-key-function" "^27.4.2"
jsonc-parser "^3.2.0"

"@types/babel__core@^7.1.14":
version "7.1.14"
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.14.tgz#faaeefc4185ec71c389f4501ee5ec84b170cc402"
Expand Down Expand Up @@ -1369,6 +1461,13 @@
resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-20.2.0.tgz#dd3e6699ba3237f0348cd085e4698780204842f9"
integrity sha512-37RSHht+gzzgYeobbG+KWryeAW8J33Nhr69cjTqSYymXVZEN9NbRYWoYlRtDhHKPVT1FyNKwaTPC1NynKZpzRA==

"@types/yargs@^16.0.0":
version "16.0.5"
resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-16.0.5.tgz#12cc86393985735a283e387936398c2f9e5f88e3"
integrity sha512-AxO/ADJOBFJScHbWhq2xAhlWP24rY4aCEG/NFaMvbT3X2MgRsLjhjQwsn0Zi5zn0LG9jUhCCZMeX9Dkuw6k+vQ==
dependencies:
"@types/yargs-parser" "*"

"@types/yargs@^17.0.8":
version "17.0.10"
resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-17.0.10.tgz#591522fce85d8739bca7b8bb90d048e4478d186a"
Expand Down Expand Up @@ -1705,13 +1804,6 @@ browserslist@^4.21.3:
node-releases "^2.0.6"
update-browserslist-db "^1.0.5"

[email protected]:
version "0.2.6"
resolved "https://registry.yarnpkg.com/bs-logger/-/bs-logger-0.2.6.tgz#eb7d365307a72cf974cc6cda76b68354ad336bd8"
integrity sha512-pd8DCoxmbgc7hyPKOvxtqNcjYoOsABPQdcCUjGp3d42VR2CX1ORhk2A87oqqu5R1kk+76nsxZupkmyd+MVtCog==
dependencies:
fast-json-stable-stringify "2.x"

[email protected]:
version "2.1.1"
resolved "https://registry.yarnpkg.com/bser/-/bser-2.1.1.tgz#e6787da20ece9d07998533cfd9de6f5c38f4bc05"
Expand Down Expand Up @@ -2312,7 +2404,7 @@ fast-glob@^3.2.9:
merge2 "^1.3.0"
micromatch "^4.0.4"

fast-json-stable-stringify@2.x, fast-json-stable-stringify@^2.0.0, fast-json-stable-stringify@^2.1.0:
fast-json-stable-stringify@^2.0.0, fast-json-stable-stringify@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz#874bf69c6f404c2b5d99c481341399fd55892633"
integrity sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==
Expand Down Expand Up @@ -3232,7 +3324,7 @@ jest-snapshot@^29.6.2:
pretty-format "^29.6.2"
semver "^7.5.3"

jest-util@^29.0.0, jest-util@^29.2.0:
jest-util@^29.2.0:
version "29.2.0"
resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-29.2.0.tgz#797935697e83a5722aeba401ed6cd01264295566"
integrity sha512-8M1dx12ujkBbnhwytrezWY0Ut79hbflwodE+qZKjxSRz5qt4xDp6dQQJaOCFvCmE0QJqp9KyEK33lpPNjnhevw==
Expand Down Expand Up @@ -3354,11 +3446,16 @@ json5@^2.2.1:
resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.1.tgz#655d50ed1e6f95ad1a3caababd2b0efda10b395c"
integrity sha512-1hqLFMSrGHRHxav9q9gNjJ5EXznIxGVO09xQRrwplcS8qs28pZ8s8hupZAmqDwZUmVZ2Qb2jnyPOWcDH8m8dlA==

json5@^2.2.2, json5@^2.2.3:
json5@^2.2.2:
version "2.2.3"
resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.3.tgz#78cd6f1a19bdc12b73db5ad0c61efd66c1e29283"
integrity sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==

jsonc-parser@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/jsonc-parser/-/jsonc-parser-3.2.0.tgz#31ff3f4c2b9793f89c67212627c51c6394f88e76"
integrity sha512-gfFQZrcTc8CnKXp6Y4/CBT3fTc0OVuDofpre4aEeEpSBPV5X5v4+Vmx+8snU7RLPrNHPKSgLxGo9YuQzz20o+w==

"jsx-ast-utils@^2.4.1 || ^3.0.0":
version "3.2.0"
resolved "https://registry.yarnpkg.com/jsx-ast-utils/-/jsx-ast-utils-3.2.0.tgz#41108d2cec408c3453c1bbe8a4aae9e1e2bd8f82"
Expand Down Expand Up @@ -3404,11 +3501,6 @@ locate-path@^6.0.0:
dependencies:
p-locate "^5.0.0"

[email protected]:
version "4.1.2"
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
integrity sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=

lodash.merge@^4.6.2:
version "4.6.2"
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a"
Expand Down Expand Up @@ -3442,11 +3534,6 @@ make-dir@^3.0.0:
dependencies:
semver "^6.0.0"

[email protected]:
version "1.3.6"
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==

[email protected]:
version "1.0.12"
resolved "https://registry.yarnpkg.com/makeerror/-/makeerror-1.0.12.tgz#3e5dd2079a82e812e983cc6610c4a2cb0eaa801a"
Expand Down Expand Up @@ -4160,20 +4247,6 @@ ts-api-utils@^1.0.1:
resolved "https://registry.yarnpkg.com/ts-api-utils/-/ts-api-utils-1.0.1.tgz#8144e811d44c749cd65b2da305a032510774452d"
integrity sha512-lC/RGlPmwdrIBFTX59wwNzqh7aR2otPNPR/5brHZm/XKFYKsfqxihXUe9pU3JI+3vGkl+vyCoNNnPhJn3aLK1A==

[email protected]:
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==
dependencies:
bs-logger "0.x"
fast-json-stable-stringify "2.x"
jest-util "^29.0.0"
json5 "^2.2.3"
lodash.memoize "4.x"
make-error "1.x"
semver "^7.5.3"
yargs-parser "^21.0.1"

type-check@^0.4.0, type-check@~0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.4.0.tgz#07b8203bfa7056c0657050e3ccd2c37730bab8f1"
Expand Down Expand Up @@ -4318,7 +4391,7 @@ yallist@^4.0.0:
resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72"
integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==

yargs-parser@^21.0.0, yargs-parser@^21.0.1:
yargs-parser@^21.0.0:
version "21.0.1"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.0.1.tgz#0267f286c877a4f0f728fceb6f8a3e4cb95c6e35"
integrity sha512-9BK1jFpLzJROCI5TzwZL/TU4gqjK5xiHV/RfWLOahrjAko/e4DJkRDZQXfvqAsiZzzYhgAzbgz6lg48jcm4GLg==
Expand Down

0 comments on commit bb47b24

Please sign in to comment.