From 56e2ec26e557259801326f7345eb91f0cacb0b6d Mon Sep 17 00:00:00 2001 From: Alexey Velikiy Date: Fri, 11 Dec 2020 17:05:34 +0100 Subject: [PATCH 01/10] tsconfig names --- tsconfig.bin.json => bin.tsconfig.json | 0 tsconfig.lib.json => lib.tsconfig.json | 0 package.json | 6 +++--- 3 files changed, 3 insertions(+), 3 deletions(-) rename tsconfig.bin.json => bin.tsconfig.json (100%) rename tsconfig.lib.json => lib.tsconfig.json (100%) diff --git a/tsconfig.bin.json b/bin.tsconfig.json similarity index 100% rename from tsconfig.bin.json rename to bin.tsconfig.json diff --git a/tsconfig.lib.json b/lib.tsconfig.json similarity index 100% rename from tsconfig.lib.json rename to lib.tsconfig.json diff --git a/package.json b/package.json index a3910cc..77609b1 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,10 @@ "description": "", "scripts": { "build": "yarn build:lib && yarn build:bin", - "build:lib": "tsc --p tsconfig.lib.json", - "build:bin": "tsc --p tsconfig.bin.json", + "build:lib": "tsc --p lib.tsconfig.json", + "build:bin": "tsc --p bin.tsconfig.json", "dev": "tsc -w", - "test": "jest --config jest.config.js" + "test": "ts-jest" }, "repository": { "type": "git", From 41bb85c984b415ac0aa36a39f7e4f136e1e129bd Mon Sep 17 00:00:00 2001 From: Alexey Velikiy Date: Sun, 13 Dec 2020 16:54:09 +0100 Subject: [PATCH 02/10] jest tests back + vscode --- .gitignore | 1 - .vscode/launch.json | 20 ++++++++++++++++++++ bin.tsconfig.json | 2 +- jest.config.js | 26 ++++++++------------------ package.json | 2 +- spec/elasticsearch.jest.ts | 4 +++- tsconfig.jest.json | 3 --- 7 files changed, 33 insertions(+), 25 deletions(-) create mode 100644 .vscode/launch.json delete mode 100644 tsconfig.jest.json diff --git a/.gitignore b/.gitignore index 8544c27..4179018 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,5 @@ dist/ dist-test/ node_modules/ npm-debug.log -.vscode/ lib/ bin/ diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..38a5476 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,20 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Jest All", + "program": "${workspaceFolder}/node_modules/.bin/jest", + "args": [ + "--runInBand" + ], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen", + "disableOptimisticBPs": true, + "windows": { + "program": "${workspaceFolder}/node_modules/jest/bin/jest", + } + } + ] +} \ No newline at end of file diff --git a/bin.tsconfig.json b/bin.tsconfig.json index bb6e0cd..8af8ab6 100644 --- a/bin.tsconfig.json +++ b/bin.tsconfig.json @@ -6,5 +6,5 @@ "outFile": "bin/tsdb-kit.js" }, "include": [ "src/**/*.ts" ], - "exclude": [ "src/index.ts" ] + "exclude": [ "src/index.ts" ] } diff --git a/jest.config.js b/jest.config.js index 4f0f1e2..0c8cb56 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,21 +1,11 @@ module.exports = { - "verbose": true, - "globals": { - "ts-jest": { - "useBabelrc": true, - "tsConfigFile": "tsconfig.jest.json" - } - }, - "transform": { - "\\.ts": "ts-jest" - }, - "testRegex": "(\\.|/)([jt]est)\\.[jt]s$", - "moduleFileExtensions": [ - "ts", - "js", - "json" - ], - "setupFiles": [ + verbose: true, + preset: 'ts-jest', + testEnvironment: 'node', + setupFiles: [ "/spec/setup_tests.ts" - ] + ], + // TODO: folder structure defualt for jest, so + // no preference about the testRegex + testRegex: "(\\.|/)([jt]est)\\.[jt]s$" }; diff --git a/package.json b/package.json index 77609b1..38a9d7a 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "build:lib": "tsc --p lib.tsconfig.json", "build:bin": "tsc --p bin.tsconfig.json", "dev": "tsc -w", - "test": "ts-jest" + "test": "jest " }, "repository": { "type": "git", diff --git a/spec/elasticsearch.jest.ts b/spec/elasticsearch.jest.ts index cb797da..6429735 100644 --- a/spec/elasticsearch.jest.ts +++ b/spec/elasticsearch.jest.ts @@ -179,7 +179,9 @@ describe('simple query', function(){ let limit = 222; let offset = 333; - expect(elasticMetric.getQuery(from, to, limit, offset)).toEqual(expectedQuery); + let result = elasticMetric.getQuery(from, to, limit, offset); + + expect(result).toEqual(expectedQuery); }); diff --git a/tsconfig.jest.json b/tsconfig.jest.json deleted file mode 100644 index 1c66acf..0000000 --- a/tsconfig.jest.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "./tsconfig" -} From 62e6c3c8a9705bd11228deae4596fa4f7486c76b Mon Sep 17 00:00:00 2001 From: Alexey Velikiy Date: Sun, 13 Dec 2020 17:05:26 +0100 Subject: [PATCH 03/10] content type in elastic tests --- spec/elasticsearch.jest.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/elasticsearch.jest.ts b/spec/elasticsearch.jest.ts index 6429735..a44ae29 100644 --- a/spec/elasticsearch.jest.ts +++ b/spec/elasticsearch.jest.ts @@ -167,6 +167,9 @@ describe('simple query', function(){ it('check correct time processing', function() { let expectedQuery = { + headers: { + "Content-Type": 'application/json' + }, url: datasourse.url, method: 'POST', schema: { From f32648c21477a3938aa31048bca5c3e076aac1f9 Mon Sep 17 00:00:00 2001 From: Alexey Velikiy Date: Sun, 13 Dec 2020 17:38:33 +0100 Subject: [PATCH 04/10] fx templete --- spec/elasticsearch.jest.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/spec/elasticsearch.jest.ts b/spec/elasticsearch.jest.ts index a44ae29..ffb5b3d 100644 --- a/spec/elasticsearch.jest.ts +++ b/spec/elasticsearch.jest.ts @@ -30,7 +30,7 @@ describe('simple query', function(){ { "query_string": { "analyze_wildcard": true, - "query": "beat.hostname:opt-project.ru AND !system.network.name:\"IBM USB Remote NDIS Network Device\"" + "query": "beat.hostname:example.com AND !system.network.name:\"IBM USB Remote NDIS Network Device\"" } } ] @@ -142,8 +142,8 @@ describe('simple query', function(){ "field": "@timestamp", "min_doc_count": 0, "extended_bounds": { - "min": "1545933121101", - "max": "1545954721101" + "min": "0", // used to be 1545933121101 + "max": "1" // used to be 1545954721101 }, "format": "epoch_millis" }, @@ -184,6 +184,9 @@ describe('simple query', function(){ let result = elasticMetric.getQuery(from, to, limit, offset); + console.log(result.schema.data); + console.log(expectedQuery.schema.data); + expect(result).toEqual(expectedQuery); }); From d3b8271836d6812c648cf0078f804a1503fa1c98 Mon Sep 17 00:00:00 2001 From: Alexey Velikiy Date: Sun, 13 Dec 2020 17:50:56 +0100 Subject: [PATCH 05/10] elastic tests fix --- spec/elasticsearch.jest.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/elasticsearch.jest.ts b/spec/elasticsearch.jest.ts index ffb5b3d..e386684 100644 --- a/spec/elasticsearch.jest.ts +++ b/spec/elasticsearch.jest.ts @@ -100,7 +100,7 @@ describe('simple query', function(){ "type": "derivative" } ], - "query": "beat.hostname:opt-project.ru AND !system.network.name:\"IBM USB Remote NDIS Network Device\"", + "query": "beat.hostname:example.com AND !system.network.name:\"IBM USB Remote NDIS Network Device\"", "refId": "A", "target": "carbon.agents.0b0226864dc8-a.cpuUsage", "timeField": "@timestamp" @@ -129,7 +129,7 @@ describe('simple query', function(){ { "query_string": { "analyze_wildcard": true, - "query": "beat.hostname:opt-project.ru AND !system.network.name:\"IBM USB Remote NDIS Network Device\"" + "query": "beat.hostname:example.com AND !system.network.name:\"IBM USB Remote NDIS Network Device\"" } } ] @@ -173,7 +173,7 @@ describe('simple query', function(){ url: datasourse.url, method: 'POST', schema: { - data: queryTemplate.map(e => JSON.stringify(e)).join('\n') + data: queryTemplate.map(e => JSON.stringify(e)).join('\n') + "\n" } }; From 5584fb48c917e168365a58519d0396c1839fe3f6 Mon Sep 17 00:00:00 2001 From: Alexey Velikiy Date: Sun, 13 Dec 2020 17:55:15 +0100 Subject: [PATCH 06/10] elasticsearch original test --- spec/elasticsearch.jest.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/elasticsearch.jest.ts b/spec/elasticsearch.jest.ts index e386684..c5fcfc0 100644 --- a/spec/elasticsearch.jest.ts +++ b/spec/elasticsearch.jest.ts @@ -142,8 +142,8 @@ describe('simple query', function(){ "field": "@timestamp", "min_doc_count": 0, "extended_bounds": { - "min": "0", // used to be 1545933121101 - "max": "1" // used to be 1545954721101 + "min": "1545933121101", + "max": "1545954721101" }, "format": "epoch_millis" }, From 3ec0d307212cd475acd4a1940dd0a3a5f4d701ff Mon Sep 17 00:00:00 2001 From: Alexey Velikiy Date: Sun, 13 Dec 2020 18:22:55 +0100 Subject: [PATCH 07/10] small fxs --- .vscode/launch.json | 2 +- spec/elasticsearch.jest.ts | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 38a5476..e5dc691 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -17,4 +17,4 @@ } } ] -} \ No newline at end of file +} diff --git a/spec/elasticsearch.jest.ts b/spec/elasticsearch.jest.ts index c5fcfc0..8066b15 100644 --- a/spec/elasticsearch.jest.ts +++ b/spec/elasticsearch.jest.ts @@ -184,9 +184,6 @@ describe('simple query', function(){ let result = elasticMetric.getQuery(from, to, limit, offset); - console.log(result.schema.data); - console.log(expectedQuery.schema.data); - expect(result).toEqual(expectedQuery); }); From 0dcc43804c27d75b16e4eda19bf18dd431d03abb Mon Sep 17 00:00:00 2001 From: Alexey Velikiy Date: Sun, 13 Dec 2020 18:26:17 +0100 Subject: [PATCH 08/10] rm nl in es test --- spec/elasticsearch.jest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/elasticsearch.jest.ts b/spec/elasticsearch.jest.ts index 8066b15..e5900bf 100644 --- a/spec/elasticsearch.jest.ts +++ b/spec/elasticsearch.jest.ts @@ -173,7 +173,7 @@ describe('simple query', function(){ url: datasourse.url, method: 'POST', schema: { - data: queryTemplate.map(e => JSON.stringify(e)).join('\n') + "\n" + data: queryTemplate.map(e => JSON.stringify(e)).join('\n') } }; From b11728cef4c44b73417fd3b2708f1e73b148b681 Mon Sep 17 00:00:00 2001 From: Alexey Velikiy Date: Mon, 14 Dec 2020 14:32:55 +0100 Subject: [PATCH 09/10] Update spec/elasticsearch.jest.ts Co-authored-by: rozetko --- spec/elasticsearch.jest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/elasticsearch.jest.ts b/spec/elasticsearch.jest.ts index e5900bf..28349d0 100644 --- a/spec/elasticsearch.jest.ts +++ b/spec/elasticsearch.jest.ts @@ -168,7 +168,7 @@ describe('simple query', function(){ it('check correct time processing', function() { let expectedQuery = { headers: { - "Content-Type": 'application/json' + 'Content-Type': 'application/json' }, url: datasourse.url, method: 'POST', From 872f2001a6472b88bd5a3d2b636f08519ee38693 Mon Sep 17 00:00:00 2001 From: Alexey Velikiy Date: Mon, 14 Dec 2020 14:33:03 +0100 Subject: [PATCH 10/10] Update package.json Co-authored-by: rozetko --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 38a9d7a..8c58ff1 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "build:lib": "tsc --p lib.tsconfig.json", "build:bin": "tsc --p bin.tsconfig.json", "dev": "tsc -w", - "test": "jest " + "test": "jest" }, "repository": { "type": "git",