Skip to content

Commit a1440cb

Browse files
committed
Centralize Jest configuration and dependencies in the root package.json and introduce a root jest.config.js and tsconfig.json to enable monorepo testing
1 parent 7fc3e5d commit a1440cb

8 files changed

Lines changed: 98 additions & 299 deletions

File tree

‎jest.config.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
testMatch: ['<rootDir>/packages/**/*.spec.ts'],
5+
testPathIgnorePatterns: ['/node_modules/', '/out/', '/dist/'],
6+
moduleNameMapper: {
7+
'^@shared/(.*)$': '<rootDir>/packages/shared/src/$1',
8+
'^@/(.*)$': '<rootDir>/packages/vscode/src/$1',
9+
},
10+
};

‎package.json‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33
"description": "Monorepo containing editor and browser extensions",
44
"packageManager": "pnpm@10.10.0+sha512.d615db246fe70f25dcfea6d8d73dee782ce23e2245e3c4f6f888249fb568149318637dca73c2c5c8ef2a4ca0d5657fb9567188bfab47f566d1ee6ce987815c39",
55
"devDependencies": {
6+
"@types/jest": "^29.5.14",
67
"husky": "^9.1.7",
7-
"lint-staged": "^15.2.10"
8+
"jest": "^29.7.0",
9+
"lint-staged": "^15.2.10",
10+
"ts-jest": "^29.4.0",
11+
"typescript": "^5.8.3"
812
},
913
"scripts": {
10-
"prepare": "husky"
14+
"prepare": "husky",
15+
"test": "jest",
16+
"test:watch": "jest --watch"
1117
},
1218
"lint-staged": {
1319
"*.{ts,tsx,json,css,scss,md}": [

‎packages/shared/package.json‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@
44
"private": true,
55
"description": "Shared utilities for CWC",
66
"scripts": {
7-
"test": "jest"
8-
},
9-
"devDependencies": {
10-
"@types/jest": "^29.5.14",
11-
"jest": "^29.7.0",
12-
"ts-jest": "^29.3.1",
13-
"typescript": "^5.8.2"
7+
"test": "jest",
8+
"test:watch": "jest --watch"
149
}
1510
}

‎packages/shared/src/utils/search-paths/search-paths.spec.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@ describe('search_paths', () => {
3737
expect(result[0]).toBe('src/routes/HomePage.tsx')
3838
})
3939

40+
it('should not find "src/routes/HomePage.tsx" with query "pagesrc"', () => {
41+
const result = search_paths({ paths, search_value: 'pagesrc' })
42+
expect(result).toHaveLength(0)
43+
})
44+
45+
it('should not find "src/routes/HomePage.tsx" with query "page."', () => {
46+
const result = search_paths({ paths, search_value: 'page.' })
47+
expect(result).toHaveLength(0)
48+
})
49+
50+
it('should not find "src/routes/HomePage.tsx" with query "src/"', () => {
51+
const result = search_paths({ paths, search_value: 'src/' })
52+
expect(result).toHaveLength(0)
53+
})
54+
4055
it('should not find "src/routes/HomePage.tsx" with query "srcagetsx"', () => {
4156
const result = search_paths({ paths, search_value: 'srcagetsx' })
4257
expect(result).toHaveLength(0)

‎packages/shared/src/utils/search-paths/search-paths.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const is_prefix_match_recursive = (params: {
1717
part_idx: number
1818
memo: Record<string, boolean>
1919
}): boolean => {
20-
const key = `${params.part_idx}:${params.query.length}`
20+
const key = `${params.part_idx}:${params.query}`
2121
if (params.memo[key] !== undefined) {
2222
return params.memo[key]
2323
}
@@ -72,6 +72,9 @@ export const search_paths = (params: {
7272
if (!params.search_value) {
7373
return params.paths
7474
}
75+
if (/[/\\\.]$/.test(params.search_value)) {
76+
return []
77+
}
7578
return params.paths.filter((path_item) => {
7679
const search_lower = params.search_value.toLowerCase()
7780
const path_to_search_lower = path_item.toLowerCase()

‎packages/vscode/package.json‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"watch": "webpack --config ./webpack.config.js --watch --mode development",
1111
"lint": "eslint src --ext ts,tsx",
1212
"lint:fix": "eslint src --ext ts,tsx --fix",
13-
"test": "jest"
13+
"test": "jest",
14+
"test:watch": "jest --watch"
1415
},
1516
"publisher": "robertpiosik",
1617
"homepage": "https://codeweb.chat/",
@@ -1647,7 +1648,6 @@
16471648
"@babel/preset-react": "^7.27.1",
16481649
"@babel/preset-typescript": "^7.27.1",
16491650
"@types/he": "^1.2.3",
1650-
"@types/jest": "^29.5.14",
16511651
"@types/node": "20.x",
16521652
"@types/react": "^18.2.60",
16531653
"@types/react-dom": "^18.2.19",
@@ -1662,15 +1662,12 @@
16621662
"eslint": "^8.57.1",
16631663
"eslint-config-prettier": "^10.1.5",
16641664
"eslint-plugin-react": "^7.37.5",
1665-
"jest": "^29.7.0",
16661665
"mini-css-extract-plugin": "^2.9.2",
16671666
"sass-embedded": "^1.89.2",
16681667
"sass-loader": "^12.6.0",
16691668
"style-loader": "^3.3.4",
1670-
"ts-jest": "^29.4.0",
16711669
"ts-loader": "^9.5.2",
16721670
"typed-css-modules": "^0.9.1",
1673-
"typescript": "^5.8.3",
16741671
"webpack": "^5.99.9",
16751672
"webpack-cli": "^6.0.1"
16761673
},

0 commit comments

Comments
 (0)