new(all): Unit test infra added again.
This commit is contained in:
parent
e1ec6e0f05
commit
6b4efe3110
6 changed files with 59 additions and 50 deletions
22
package.json
22
package.json
|
@ -35,7 +35,7 @@
|
||||||
"build-server": "tsc",
|
"build-server": "tsc",
|
||||||
"build-gbui": "cd packages/default.gbui && echo SKIP_PREFLIGHT_CHECK=true >.env && npm install && npm run build",
|
"build-gbui": "cd packages/default.gbui && echo SKIP_PREFLIGHT_CHECK=true >.env && npm install && npm run build",
|
||||||
"build-docs": "typedoc --options typedoc.json src/",
|
"build-docs": "typedoc --options typedoc.json src/",
|
||||||
"test": "node test.js",
|
"test": "vitest",
|
||||||
"start": "NODE_NO_WARNINGS=1 node ./boot.mjs --loader ts-node/esm --require ./suppress-node-warnings.cjs",
|
"start": "NODE_NO_WARNINGS=1 node ./boot.mjs --loader ts-node/esm --require ./suppress-node-warnings.cjs",
|
||||||
"debug": "NODE_NO_WARNINGS=1 node ./boot.mjs --loader ts-node/esm --require ./suppress-node-warnings.cjs --inspect",
|
"debug": "NODE_NO_WARNINGS=1 node ./boot.mjs --loader ts-node/esm --require ./suppress-node-warnings.cjs --inspect",
|
||||||
"reverse-proxy": "node_modules/.bin/ngrok http 4242",
|
"reverse-proxy": "node_modules/.bin/ngrok http 4242",
|
||||||
|
@ -52,6 +52,19 @@
|
||||||
"semantic-release": "semantic-release",
|
"semantic-release": "semantic-release",
|
||||||
"commit": "git-cz"
|
"commit": "git-cz"
|
||||||
},
|
},
|
||||||
|
"jest": {
|
||||||
|
"workerIdleMemoryLimit": "4096MB",
|
||||||
|
"transform": {
|
||||||
|
"^.+\\.tsx?$": "ts-jest"
|
||||||
|
},
|
||||||
|
"moduleFileExtensions": [
|
||||||
|
"ts",
|
||||||
|
"tsx",
|
||||||
|
"js",
|
||||||
|
"jsx",
|
||||||
|
"json"
|
||||||
|
]
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@azure/arm-appservice": "13.0.3",
|
"@azure/arm-appservice": "13.0.3",
|
||||||
"@azure/arm-cognitiveservices": "7.3.1",
|
"@azure/arm-cognitiveservices": "7.3.1",
|
||||||
|
@ -121,7 +134,7 @@
|
||||||
"google-libphonenumber": "3.2.31",
|
"google-libphonenumber": "3.2.31",
|
||||||
"googleapis": "126.0.1",
|
"googleapis": "126.0.1",
|
||||||
"ibm-watson": "7.1.2",
|
"ibm-watson": "7.1.2",
|
||||||
"iso-639-1": "^3.1.1",
|
"iso-639-1": "3.1.1",
|
||||||
"join-images-updated": "1.1.4",
|
"join-images-updated": "1.1.4",
|
||||||
"js-md5": "0.8.3",
|
"js-md5": "0.8.3",
|
||||||
"just-indent": "0.0.1",
|
"just-indent": "0.0.1",
|
||||||
|
@ -130,6 +143,7 @@
|
||||||
"koa-body": "6.0.1",
|
"koa-body": "6.0.1",
|
||||||
"koa-router": "12.0.0",
|
"koa-router": "12.0.0",
|
||||||
"langchain": "^0.0.163",
|
"langchain": "^0.0.163",
|
||||||
|
"language-tags": "^1.0.9",
|
||||||
"line-replace": "2.0.1",
|
"line-replace": "2.0.1",
|
||||||
"lodash": "4.17.21",
|
"lodash": "4.17.21",
|
||||||
"luxon": "3.1.0",
|
"luxon": "3.1.0",
|
||||||
|
@ -214,8 +228,8 @@
|
||||||
"super-strong-password-generator": "2.0.2",
|
"super-strong-password-generator": "2.0.2",
|
||||||
"super-strong-password-generator-es": "2.0.2",
|
"super-strong-password-generator-es": "2.0.2",
|
||||||
"travis-deploy-once": "5.0.11",
|
"travis-deploy-once": "5.0.11",
|
||||||
"ts-node": "10.9.1",
|
"tslint": "6.1.3",
|
||||||
"tslint": "6.1.3"
|
"vitest": "^1.3.0"
|
||||||
},
|
},
|
||||||
"eslintConfig": {
|
"eslintConfig": {
|
||||||
"env": {
|
"env": {
|
||||||
|
|
|
@ -1155,38 +1155,34 @@ export class GBConversationalService {
|
||||||
|
|
||||||
let replacements = [];
|
let replacements = [];
|
||||||
|
|
||||||
if (translate) {
|
// To fix MSFT bug.
|
||||||
// To fix MSFT bug.
|
|
||||||
|
|
||||||
if (keepTextList) {
|
if (keepTextList) {
|
||||||
keepTextList = keepTextList.filter(p => p.trim() !== '');
|
keepTextList = keepTextList.filter(p => p.trim() !== '');
|
||||||
let i = 0;
|
let i = 0;
|
||||||
await CollectionUtil.asyncForEach(keepTextList, item => {
|
await CollectionUtil.asyncForEach(keepTextList, item => {
|
||||||
if (text.toLowerCase().indexOf(item.toLowerCase()) != -1) {
|
if (text.toLowerCase().indexOf(item.toLowerCase()) != -1) {
|
||||||
const replacementToken = GBAdminService['getNumberIdentifier']();
|
const replacementToken = GBAdminService['getNumberIdentifier']();
|
||||||
replacements[i] = { text: item, replacementToken: replacementToken };
|
replacements[i] = { text: item, replacementToken: replacementToken };
|
||||||
i++;
|
|
||||||
text = text.replace(new RegExp(item.trim(), 'gi'), `${replacementToken}`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const locale = user.locale;
|
|
||||||
text = await min.conversationalService.translate(
|
|
||||||
min,
|
|
||||||
text,
|
|
||||||
locale ? locale : min.core.getParam<string>(min.instance, 'Locale', GBConfigService.get('LOCALE'))
|
|
||||||
);
|
|
||||||
|
|
||||||
if (keepTextList) {
|
|
||||||
let i = 0;
|
|
||||||
await CollectionUtil.asyncForEach(replacements, item => {
|
|
||||||
i++;
|
i++;
|
||||||
text = text.replace(new RegExp(`${item.replacementToken}`, 'gi'), item.text);
|
text = text.replace(new RegExp(item.trim(), 'gi'), `${replacementToken}`);
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
|
||||||
GBLog.verbose(`Translated text(sendText): ${text}.`);
|
const locale = user.locale;
|
||||||
|
text = await min.conversationalService.translate(
|
||||||
|
min,
|
||||||
|
text,
|
||||||
|
locale ? locale : min.core.getParam<string>(min.instance, 'Locale', GBConfigService.get('LOCALE'))
|
||||||
|
);
|
||||||
|
|
||||||
|
if (keepTextList) {
|
||||||
|
let i = 0;
|
||||||
|
await CollectionUtil.asyncForEach(replacements, item => {
|
||||||
|
i++;
|
||||||
|
text = text.replace(new RegExp(`${item.replacementToken}`, 'gi'), item.text);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const analytics = new AnalyticsService();
|
const analytics = new AnalyticsService();
|
||||||
|
|
8
src/util.test.ts
Normal file
8
src/util.test.ts
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
import { GBUtil} from './util';
|
||||||
|
import { expect, test } from 'vitest'
|
||||||
|
|
||||||
|
test('Default', () => {
|
||||||
|
|
||||||
|
expect(null).toBe(null);
|
||||||
|
|
||||||
|
});
|
16
src/util.ts
16
src/util.ts
|
@ -33,17 +33,17 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
import iso6391 from 'iso-639-1';
|
import tags from 'language-tags';
|
||||||
|
|
||||||
export class GBUtil {
|
export class GBUtil {
|
||||||
|
|
||||||
public static repeat = function (chr, count) {
|
public static repeat (chr, count) {
|
||||||
var str = "";
|
var str = "";
|
||||||
for (var x = 0; x < count; x++) { str += chr };
|
for (var x = 0; x < count; x++) { str += chr };
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static padL = function (value, width, pad) {
|
public static padL (value, width, pad) {
|
||||||
if (!width || width < 1)
|
if (!width || width < 1)
|
||||||
return value;
|
return value;
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ export class GBUtil {
|
||||||
|
|
||||||
return (GBUtil.repeat(pad, length) + value).substr(0, width);
|
return (GBUtil.repeat(pad, length) + value).substr(0, width);
|
||||||
}
|
}
|
||||||
public static padR = function (value, width, pad) {
|
public static padR (value, width, pad) {
|
||||||
if (!width || width < 1)
|
if (!width || width < 1)
|
||||||
return value;
|
return value;
|
||||||
|
|
||||||
|
@ -95,12 +95,4 @@ export class GBUtil {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public static getLocaleLanguageAndCountry(locale) {
|
|
||||||
const iso6393Language = iso6391.getCode(locale);
|
|
||||||
if (iso6393Language) {
|
|
||||||
return iso6393Language + '-' + locale.toLowerCase();
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
1
test.js
1
test.js
|
@ -1 +0,0 @@
|
||||||
console.log("Feel free to PR refactored and unit tests added if you want to.");
|
|
|
@ -33,14 +33,14 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"test/**/*",
|
|
||||||
"src/**/*",
|
"src/**/*",
|
||||||
"packages/*.gbapp/**/*",
|
"packages/*.gbapp/**/*",
|
||||||
"packages/*.gblib/**/*",
|
"packages/*.gblib/**/*",
|
||||||
"packages/*.gbtheme/**/*",
|
"packages/*.gbtheme/**/*"
|
||||||
],
|
],
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"dist",
|
"dist",
|
||||||
"node_modules"
|
"node_modules",
|
||||||
]
|
"**/*.test.ts"
|
||||||
|
]
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue