diff --git a/.gitignore b/.gitignore index 5e58c67..153ba92 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.log *.output -node_modules/ \ No newline at end of file +node_modules/ +dist/ \ No newline at end of file diff --git a/index.ts b/index.ts index ecc1877..4769bd8 100644 --- a/index.ts +++ b/index.ts @@ -1,5 +1,5 @@ -import CallerVitest from "./src/reporters/caller-vitest.ts"; -import CallerPlaywright from "./src/reporters/caller-playwright.ts"; +import CallerVitest from "./src/reporters/caller-vitest"; +import CallerPlaywright from "./src/reporters/caller-playwright"; import type { FullConfig, FullResult, Suite, TestCase, TestResult } from '@playwright/test/reporter'; @@ -13,19 +13,19 @@ class VitestTestrailReporter { this.caller.onInit(); } - onPathsCollected(paths) { + onPathsCollected(paths: any) { this.caller.onPathsCollected(paths); } - onCollected(file) { + onCollected(file: any) { this.caller.onCollected(file); } - onTaskUpdate(packs) { + onTaskUpdate(packs: any) { this.caller.onTaskUpdate(packs); } - onFinished(packs) { + onFinished(packs: any) { this.caller.onFinished(packs); } } diff --git a/package-lock.json b/package-lock.json index ac728b6..b902bb1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,29 +1,31 @@ { "name": "@zealteam/testrail-reporter", - "version": "1.0.3", + "version": "1.0.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@zealteam/testrail-reporter", - "version": "1.0.3", + "version": "1.0.4", "license": "MIT", "dependencies": { "@dlenroc/testrail": "^1.9.1", "@playwright/test": "^1.40.1", + "colorette": "^2.0.20", "jest": "^29.7.0", + "node-schedule": "^2.1.1", "playwright": "^1.40.1", "vitest": "^1.1.0" }, "devDependencies": { "@types/node": "^20.11.6", + "@types/node-schedule": "^2.1.6", "@typescript-eslint/eslint-plugin": "^7.0.1", "@typescript-eslint/parser": "^7.0.1", - "colorette": "^2.0.20", "eslint": "^8.56.0", "eslint-plugin-react": "^7.33.2", - "node-schedule": "^2.1.1", "path": "^0.12.7", + "ts-node": "^10.9.2", "typescript": "^5.2.2" }, "engines": { @@ -622,6 +624,28 @@ "resolved": "https://registry.npmjs.org/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz", "integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==" }, + "node_modules/@cspotcode/source-map-support": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "devOptional": true, + "dependencies": { + "@jridgewell/trace-mapping": "0.3.9" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@cspotcode/source-map-support/node_modules/@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "devOptional": true, + "dependencies": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, "node_modules/@dlenroc/testrail": { "version": "1.9.1", "resolved": "https://registry.npmjs.org/@dlenroc/testrail/-/testrail-1.9.1.tgz", @@ -1669,6 +1693,30 @@ "@sinonjs/commons": "^3.0.0" } }, + "node_modules/@tsconfig/node10": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz", + "integrity": "sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==", + "devOptional": true + }, + "node_modules/@tsconfig/node12": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", + "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", + "devOptional": true + }, + "node_modules/@tsconfig/node14": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", + "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", + "devOptional": true + }, + "node_modules/@tsconfig/node16": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz", + "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", + "devOptional": true + }, "node_modules/@types/babel__core": { "version": "7.20.5", "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz", @@ -1749,6 +1797,15 @@ "undici-types": "~5.26.4" } }, + "node_modules/@types/node-schedule": { + "version": "2.1.6", + "resolved": "https://registry.npmjs.org/@types/node-schedule/-/node-schedule-2.1.6.tgz", + "integrity": "sha512-6AlZSUiNTdaVmH5jXYxX9YgmF1zfOlbjUqw0EllTBmZCnN1R5RR/m/u3No1OiWR05bnQ4jM4/+w4FcGvkAtnKQ==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/semver": { "version": "7.5.7", "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.7.tgz", @@ -2272,6 +2329,12 @@ "node": ">= 8" } }, + "node_modules/arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "devOptional": true + }, "node_modules/argparse": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", @@ -2777,8 +2840,7 @@ "node_modules/colorette": { "version": "2.0.20", "resolved": "https://registry.npmjs.org/colorette/-/colorette-2.0.20.tgz", - "integrity": "sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==", - "dev": true + "integrity": "sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==" }, "node_modules/combined-stream": { "version": "1.0.8", @@ -2821,11 +2883,16 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", + "devOptional": true + }, "node_modules/cron-parser": { "version": "4.9.0", "resolved": "https://registry.npmjs.org/cron-parser/-/cron-parser-4.9.0.tgz", "integrity": "sha512-p0SaNjrHOnQeR8/VnfGbmg9te2kfyYSQ7Sc/j/6DtPL3JQvKxmjO9TSjNFpujqV3vEYYBvNNvXSxzyksBWAx1Q==", - "dev": true, "dependencies": { "luxon": "^3.2.1" }, @@ -2950,6 +3017,15 @@ "node": ">=8" } }, + "node_modules/diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "devOptional": true, + "engines": { + "node": ">=0.3.1" + } + }, "node_modules/diff-sequences": { "version": "29.6.3", "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-29.6.3.tgz", @@ -5293,8 +5369,7 @@ "node_modules/long-timeout": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/long-timeout/-/long-timeout-0.1.1.tgz", - "integrity": "sha512-BFRuQUqc7x2NWxfJBCyUrN8iYUYznzL9JROmRz1gZ6KlOIgmoD+njPVbb+VNn2nGMKggMsK79iUNErillsrx7w==", - "dev": true + "integrity": "sha512-BFRuQUqc7x2NWxfJBCyUrN8iYUYznzL9JROmRz1gZ6KlOIgmoD+njPVbb+VNn2nGMKggMsK79iUNErillsrx7w==" }, "node_modules/loose-envify": { "version": "1.4.0", @@ -5328,7 +5403,6 @@ "version": "3.4.4", "resolved": "https://registry.npmjs.org/luxon/-/luxon-3.4.4.tgz", "integrity": "sha512-zobTr7akeGHnv7eBOXcRgMeCP6+uyYsczwmeRCauvpvaAltgNyTbLH/+VaEAPUeWBT+1GuNmz4wC/6jtQzbbVA==", - "dev": true, "engines": { "node": ">=12" } @@ -5388,6 +5462,12 @@ "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" }, + "node_modules/make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "devOptional": true + }, "node_modules/makeerror": { "version": "1.0.12", "resolved": "https://registry.npmjs.org/makeerror/-/makeerror-1.0.12.tgz", @@ -5531,7 +5611,6 @@ "version": "2.1.1", "resolved": "https://registry.npmjs.org/node-schedule/-/node-schedule-2.1.1.tgz", "integrity": "sha512-OXdegQq03OmXEjt2hZP33W2YPs/E5BcFQks46+G2gAxs4gHOIVD1u7EqlYLYSKsaIpyKCK9Gbk0ta1/gjRSMRQ==", - "dev": true, "dependencies": { "cron-parser": "^4.2.0", "long-timeout": "0.1.1", @@ -6378,8 +6457,7 @@ "node_modules/sorted-array-functions": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/sorted-array-functions/-/sorted-array-functions-1.3.0.tgz", - "integrity": "sha512-2sqgzeFlid6N4Z2fUQ1cvFmTOLRi/sEDzSQ0OKYchqgoPmQBVyM3959qYx3fpS6Esef80KjmpgPeEr028dP3OA==", - "dev": true + "integrity": "sha512-2sqgzeFlid6N4Z2fUQ1cvFmTOLRi/sEDzSQ0OKYchqgoPmQBVyM3959qYx3fpS6Esef80KjmpgPeEr028dP3OA==" }, "node_modules/source-map": { "version": "0.6.1", @@ -6674,6 +6752,49 @@ "typescript": ">=4.2.0" } }, + "node_modules/ts-node": { + "version": "10.9.2", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", + "integrity": "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==", + "devOptional": true, + "dependencies": { + "@cspotcode/source-map-support": "^0.8.0", + "@tsconfig/node10": "^1.0.7", + "@tsconfig/node12": "^1.0.7", + "@tsconfig/node14": "^1.0.0", + "@tsconfig/node16": "^1.0.2", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "v8-compile-cache-lib": "^3.0.1", + "yn": "3.1.1" + }, + "bin": { + "ts-node": "dist/bin.js", + "ts-node-cwd": "dist/bin-cwd.js", + "ts-node-esm": "dist/bin-esm.js", + "ts-node-script": "dist/bin-script.js", + "ts-node-transpile-only": "dist/bin-transpile.js", + "ts-script": "dist/bin-script-deprecated.js" + }, + "peerDependencies": { + "@swc/core": ">=1.2.50", + "@swc/wasm": ">=1.2.50", + "@types/node": "*", + "typescript": ">=2.7" + }, + "peerDependenciesMeta": { + "@swc/core": { + "optional": true + }, + "@swc/wasm": { + "optional": true + } + } + }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -6774,7 +6895,7 @@ "version": "5.3.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz", "integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==", - "dev": true, + "devOptional": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -6861,6 +6982,12 @@ "integrity": "sha512-x00IRNXNy63jwGkJmzPigoySHbaqpNuzKbBOmzK+g2OdZpQ9w+sxCN+VSB3ja7IAge2OP2qpfxTjeNcyjmW1uw==", "dev": true }, + "node_modules/v8-compile-cache-lib": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", + "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", + "devOptional": true + }, "node_modules/v8-to-istanbul": { "version": "9.2.0", "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.2.0.tgz", @@ -7336,6 +7463,15 @@ "node": ">=12" } }, + "node_modules/yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "devOptional": true, + "engines": { + "node": ">=6" + } + }, "node_modules/yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", diff --git a/package.json b/package.json index 262f588..7696b44 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,22 @@ { "name": "@zealteam/testrail-reporter", - "version": "1.0.3", + "version": "1.0.4", "description": "A custom reporter for Vitest, Jest, and Playwright designed to synchronize with Testrail.", "author": "Davit Manukyan ", "repository": { "type": "git", "url": "git+https://github.com/zealous-tech/testrail-reporter.git" }, + "types": "./dist/index.d.ts", "engines": { "node": ">=10.0.0" }, - "main": "index.ts", + "main": "./dist/index.js", + "files": [ + "/dist" + ], "scripts": { + "build": "npx tsc", "jest": "jest", "playwright": "playwright", "vitest": "vitest" @@ -28,7 +33,9 @@ "dependencies": { "@dlenroc/testrail": "^1.9.1", "@playwright/test": "^1.40.1", + "colorette": "^2.0.20", "jest": "^29.7.0", + "node-schedule": "^2.1.1", "playwright": "^1.40.1", "vitest": "^1.1.0" }, @@ -41,13 +48,13 @@ "homepage": "https://github.com/zealous-tech/testrail-reporter#readme", "devDependencies": { "@types/node": "^20.11.6", + "@types/node-schedule": "^2.1.6", "@typescript-eslint/eslint-plugin": "^7.0.1", "@typescript-eslint/parser": "^7.0.1", - "colorette": "^2.0.20", "eslint": "^8.56.0", "eslint-plugin-react": "^7.33.2", - "node-schedule": "^2.1.1", "path": "^0.12.7", + "ts-node": "^10.9.2", "typescript": "^5.2.2" }, "publishConfig": { diff --git a/src/base.ts b/src/base.ts index f26c913..5c20b0e 100644 --- a/src/base.ts +++ b/src/base.ts @@ -1,7 +1,7 @@ import TestRail from "@dlenroc/testrail"; import path from "path"; import { green as message, red as error } from "colorette"; -import { IResult, ITestrailConfig } from "../lib/interface.ts"; +import { IResult, ITestrailConfig } from "../lib/interface"; import * as schedule from 'node-schedule'; const DEFAULT_CONFIG_FILENAME = 'testrail.config.ts'; diff --git a/src/reporters/caller-playwright.ts b/src/reporters/caller-playwright.ts index 7557e63..ca24ff1 100644 --- a/src/reporters/caller-playwright.ts +++ b/src/reporters/caller-playwright.ts @@ -3,7 +3,7 @@ import Utils from "../utils.js"; import type { FullConfig, FullResult, Suite, TestCase, TestResult } from '@playwright/test/reporter'; -import { BaseClass, testResults, case_ids, copiedTestResults } from "../base.ts"; +import { BaseClass, testResults, case_ids, copiedTestResults } from "../base"; import { setTimeout } from 'timers/promises'; global.need_to_stop = false; diff --git a/src/reporters/caller-vitest.ts b/src/reporters/caller-vitest.ts index b802a0d..590a3bd 100644 --- a/src/reporters/caller-vitest.ts +++ b/src/reporters/caller-vitest.ts @@ -1,14 +1,14 @@ import { blue, red as error, underline } from "colorette"; import Utils from "../utils.js"; import { setTimeout } from 'timers/promises'; -import { BaseClass, testResults, case_ids } from "../base.ts"; +import { BaseClass, testResults, case_ids } from "../base"; const startList = {} as { [x: number]: number }; global.need_to_stop = false; let files_count = 0 let paths_count = 0 -global.runId = 0; +let runId = 0; class CallerVitest extends BaseClass { readonly utils = new Utils(); @@ -17,32 +17,32 @@ class CallerVitest extends BaseClass { console.log('TestRail Reporter Log: ' + "The reporter started successfully!") } - onPathsCollected(paths) { + onPathsCollected(paths: string | any[]) { paths_count = paths.length } - async onCollected(file) { + async onCollected(file: any) { files_count++ this.processStartList(file); if (files_count == paths_count) { if (this.tesrailConfigs.use_existing_run.id != 0) { - global.runId = this.tesrailConfigs.use_existing_run.id - await this.tr_api.getRun(global.runId).then(() => { + runId = this.tesrailConfigs.use_existing_run.id + await this.tr_api.getRun(runId).then(() => { console.log('TestRail Reporter Log: ' + "The runId is a valid test run id!!") }) - console.log('TestRail Reporter Log: ' + 'TestRail Reporter Log: ' + `The Run started, utilizing an existing run in TestRail with the ID=${global.runId}.`); + console.log('TestRail Reporter Log: ' + 'TestRail Reporter Log: ' + `The Run started, utilizing an existing run in TestRail with the ID=${runId}.`); } else { await this.addRunToTestRail(case_ids) .then(({ id }) => { - global.runId = id; + runId = id; }) .catch((err) => console.log('TestRail Reporter Log: ' + error(err))); } - if (this.tesrailConfigs.testRailUpdateInterval != 0) this.startScheduler(global.runId) + if (this.tesrailConfigs.testRailUpdateInterval != 0) this.startScheduler(runId) } } - onTaskUpdate(packs) { + onTaskUpdate(packs: any[]) { packs.forEach((element) => { const testRunId = element[0]; const case_id = startList[testRunId]; @@ -73,21 +73,21 @@ class CallerVitest extends BaseClass { } - async onFinished(packs) { + async onFinished(packs: any) { if (this.tesrailConfigs.testRailUpdateInterval == 0) { - while (global.runId === 0) { + while (runId === 0) { await setTimeout(100) } - await this.updateTestRailResults(testResults, global.runId) + await this.updateTestRailResults(testResults, runId) } global.need_to_stop = true; console.log('TestRail Reporter Log: ' + "See Results: " + - blue(underline(`${this.tesrailConfigs.base_url}/index.php?/runs/view/${global.runId}\n`)) + blue(underline(`${this.tesrailConfigs.base_url}/index.php?/runs/view/${runId}\n`)) ); } - processStartList(arr) { + processStartList(arr: any) { for (const element of arr) { if (!element.name.match(/[@C][?\d]{1,8}$/gm) && element.tasks) { this.processStartList(element.tasks); diff --git a/src/types/index.d.ts b/src/types/index.d.ts new file mode 100644 index 0000000..9a37f22 --- /dev/null +++ b/src/types/index.d.ts @@ -0,0 +1,8 @@ +/* eslint-disable no-var */ + +declare global { + var need_to_stop: boolean; + } + + export {}; + \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..5c97dc6 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + "lib": ["es6", "dom"], + "rootDir": "./", + "target": "es6", + "module": "commonjs", + "strict": true, + "noImplicitAny": true, + "downlevelIteration": true, + "allowJs": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "outDir": "./dist", + "declaration": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "allowSyntheticDefaultImports": true, + "moduleResolution": "node", + "sourceMap": true + }, + "include": [ + "./src/**/*.ts", + "./index.ts" + ], + "exclude": [ + "./tests", + "logs" + ] +} \ No newline at end of file