mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-21 00:06:01 +00:00
SYNC: test for parseName + fix
This commit is contained in:
committed by
Diflow
parent
d3d97b5924
commit
0dd0125e9f
5
packages/tools/jest.config.js
Normal file
5
packages/tools/jest.config.js
Normal file
@@ -0,0 +1,5 @@
|
||||
module.exports = {
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'node',
|
||||
moduleFileExtensions: ['js'],
|
||||
};
|
||||
@@ -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": {
|
||||
|
||||
20
packages/tools/src/filterName.test.ts
Normal file
20
packages/tools/src/filterName.test.ts
Normal file
@@ -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 },
|
||||
]);
|
||||
});
|
||||
@@ -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 {
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user