diff --git a/packages/tools/jest.config.js b/packages/tools/jest.config.js new file mode 100644 index 000000000..790050941 --- /dev/null +++ b/packages/tools/jest.config.js @@ -0,0 +1,5 @@ +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node', + moduleFileExtensions: ['js'], +}; diff --git a/packages/tools/package.json b/packages/tools/package.json index ae25b21b5..8865a9f37 100644 --- a/packages/tools/package.json +++ b/packages/tools/package.json @@ -17,8 +17,9 @@ "scripts": { "build": "tsc", "start": "tsc --watch", + "prepublishOnly": "yarn build", "test": "jest", - "prepublishOnly": "yarn build" + "test:ci": "jest --json --outputFile=result.json --testLocationInResults" }, "files": [ "lib" @@ -26,8 +27,8 @@ "devDependencies": { "@types/node": "^13.7.0", "dbgate-types": "^6.0.0-alpha.1", - "jest": "^24.9.0", - "ts-jest": "^25.2.1", + "jest": "^28.1.3", + "ts-jest": "^28.0.7", "typescript": "^4.4.3" }, "dependencies": { diff --git a/packages/tools/src/filterName.test.ts b/packages/tools/src/filterName.test.ts new file mode 100644 index 000000000..4ac4ba448 --- /dev/null +++ b/packages/tools/src/filterName.test.ts @@ -0,0 +1,20 @@ +const { tokenizeBySearchFilter } = require('./filterName'); + +test('tokenize single token', () => { + const tokenized = tokenizeBySearchFilter('Album', 'al'); + // console.log(JSON.stringify(tokenized, null, 2)); + expect(tokenized).toEqual([ + { text: 'Al', isMatch: true }, + { text: 'bum', isMatch: false }, + ]); +}); + +test('tokenize two tokens', () => { + const tokenized = tokenizeBySearchFilter('Album', 'al,um'); + // console.log(JSON.stringify(tokenized, null, 2)); + expect(tokenized).toEqual([ + { text: 'Al', isMatch: true }, + { text: 'b', isMatch: false }, + { text: 'um', isMatch: true }, + ]); +}); diff --git a/packages/tools/src/filterName.ts b/packages/tools/src/filterName.ts index 853e769c8..07db7a4ff 100644 --- a/packages/tools/src/filterName.ts +++ b/packages/tools/src/filterName.ts @@ -118,7 +118,10 @@ export function filterNameCompoud( export function tokenizeBySearchFilter(text: string, filter: string): { text: string; isMatch: boolean }[] { const camelTokens = []; const stdTokens = []; - for (const token of filter.split(/ ,/).map(x => x.trim())) { + for (const token of filter + .split(/[ ,]/) + .map(x => x.trim()) + .filter(x => x.length > 0)) { if (token.replace(/[A-Z]/g, '').length == 0) { camelTokens.push(token); } else { diff --git a/workflow-templates/run-tests.yaml b/workflow-templates/run-tests.yaml index c774e7a9c..a8eac8a2f 100644 --- a/workflow-templates/run-tests.yaml +++ b/workflow-templates/run-tests.yaml @@ -43,6 +43,12 @@ jobs: cd packages/datalib yarn test:ci + - name: Tools tests + if: always() + run: | + cd packages/tools + yarn test:ci + - uses: tanmen/jest-reporter@v1 if: always() with: