diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..a74769ed --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,28 @@ +name: Test +on: + pull_request: + types: [opened, ready_for_review, review_requested, synchronize] + push: + branches: ['master', 'develop'] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + # Setup .npmrc file to publish to npm + - uses: actions/setup-node@v2 + with: + node-version: '14.x' + registry-url: 'https://registry.npmjs.org' + # Defaults to the user or organization that owns the workflow file + scope: '@octocat' + - run: yarn + - run: yarn build + - run: yarn test + env: + DOMAIN: ${{ secrets.DOMAIN }} + USERNAME: ${{ secrets.USERNAME }} + PASSWORD: ${{ secrets.PASSWORD }} + PROJECTID: 1 + SUITEID: 1 + ASSIGNEDTOID: 1 \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..f447cdcb --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,28 @@ +name: Package and publish +on: + release: + types: [published] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + # Setup .npmrc file to publish to npm + - uses: actions/setup-node@v2 + with: + node-version: "14.x" + registry-url: "https://registry.npmjs.org" + # Defaults to the user or organization that owns the workflow file + scope: "@octocat" + - run: yarn + - run: yarn build + - run: yarn test + - run: yarn publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + DOMAIN: ${{ secrets.DOMAIN }} + USERNAME: ${{ secrets.USERNAME }} + PASSWORD: ${{ secrets.PASSWORD }} + PROJECTID: 1 + SUITEID: 1 + ASSIGNEDTOID: 1 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 59c774b2..f0588581 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,10 @@ node_modules node-debug* +*.log .c9/ *.iml .idea/ -npm-debug.log dist +.env +yarn.lock +package-lock.json diff --git a/.npmignore b/.npmignore index a4d1e892..7357c032 100644 --- a/.npmignore +++ b/.npmignore @@ -1,6 +1,12 @@ -*.iml +.github .idea/ -tsconfig.json src/ dist/test -*.map \ No newline at end of file +*.iml +tsconfig.json +*.map +*.lock +package-lock.json +.prettier* +.env +*.tgz \ No newline at end of file diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..8d87b1d2 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +node_modules/* diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000..e69de29b diff --git a/README.md b/README.md index ca4c7e7d..6dc32ad0 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ Pushes test results into Testrail system. +> **NOTE** : Version 2.0.x is backward compatible with v1 but has been updated to latest dependencies. The V2 choice is to ensure that existing users are not affected! + ## Installation ```shell @@ -32,8 +34,8 @@ mocha --opts mocha-testrail.opts build/test Mark your mocha test names with ID of Testrail test cases. Ensure that your case ids are well distinct from test descriptions. ```Javascript -it("C123 C124 Authenticate with invalid user", . . . -it("Authenticate a valid user C321", . . . +it("C123 C124 Authenticate with invalid user", () => {}) +it("Authenticate a valid user C321", () => {}) ``` Only passed or failed tests will be published. Skipped or pending tests will not be published resulting in a "Pending" status in testrail test run. @@ -52,6 +54,32 @@ Only passed or failed tests will be published. Skipped or pending tests will not **assignedToId**: *number* (optional) user id which will be assigned failed tests +## Build and test locally + +### Setup testrail test server + +- Start a new TestRail trial from https://www.gurock.com/testrail/test-management/ +- Enable API under https://XXX.testrail.io/index.php?/admin/site_settings&tab=8 +- Add a new project (Use multiple test suites to manage cases) +- Add a new test suite (ids: 1) +- Add at least 4 test cases (ids: C1, C2, C3, C4, etc) +- Once setup, set your environment variables - recommend using .env file in the root folder + - DOMAIN=XXX.testrail.io + - USERNAME=XXX + - PASSWORD=XXX + - PROJECTID=1 + - SUITEID=1 + - ASSIGNEDTOID=1 +- Execute the build and test commands (unit and integration tests) +- Execute the e2e test (requires build and .env file) + +### Build and test +``` +npm run clean +npm run build +npm run test +``` + ## References - http://mochajs.org/#mochaopts - https://github.com/mochajs/mocha/wiki/Third-party-reporters diff --git a/e2e/.gitignore b/e2e/.gitignore new file mode 100644 index 00000000..1b6ef2b1 --- /dev/null +++ b/e2e/.gitignore @@ -0,0 +1,3 @@ +package-lock.json +yarn.lock +node_modules \ No newline at end of file diff --git a/e2e/e2e.spec.js b/e2e/e2e.spec.js new file mode 100644 index 00000000..c46c8108 --- /dev/null +++ b/e2e/e2e.spec.js @@ -0,0 +1,7 @@ +describe("E2E Testrail Mocha Reporter", () => { + it("C1 Test case 1", () => {}); + it("C2 Test case 1", () => {}); + it("C3 Test case 1", () => { + throw new Error("Failed test"); + }); +}); diff --git a/e2e/package.json b/e2e/package.json new file mode 100644 index 00000000..339aec3f --- /dev/null +++ b/e2e/package.json @@ -0,0 +1,16 @@ +{ + "name": "e2e", + "version": "1.0.0", + "description": "E2E test for mocha-testrail-reporter", + "main": "index.js", + "author": "Pierre Awaragi", + "license": "MIT", + "private": true, + "scripts": { + "test": ". ../.env && mocha e2e.spec.js --reporter mocha-testrail-reporter --reporter-options domain=$DOMAIN,username=$USERNAME,password=$PASSWORD,projectId=$PROJECTID,suiteId=$SUITEID" + }, + "devDependencies": { + "mocha": "^9.2.2", + "mocha-testrail-reporter": "file:.." + } +} diff --git a/package.json b/package.json index 4ab49b74..e81b7d51 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "mocha-testrail-reporter", - "version": "1.0.12", - "description": "A Testrail reporter for mocha including TestRail API basic library", + "version": "2.0.0", + "description": "A Testrail reporter for mocha utilising TestRail API", "main": "index.js", "private": false, "keywords": [ @@ -23,24 +23,28 @@ "url": "https://github.com/awaragi/mocha-testrail-reporter/issues" }, "scripts": { - "tsc": "tsc", + "build": "tsc", "clean": "rimraf dist", "test": "mocha dist/test", - "build": "npm run clean && npm run tsc" + "test:ts": "mocha -r ts-node/register src/test/*", + "format": "prettier --check ./**/* --write" }, "dependencies": { "btoa": "^1.1.2", - "unirest": "^0.5.1" + "unirest": "^0.6.0" }, "peerDependencies": { - "mocha": "^3 || ^2.2.5" + "mocha": "9.2.2" }, "devDependencies": { - "@types/chai": "^3.4.34", - "@types/mocha": "^2.2.36", - "@types/node": "^6.0.58", - "chai": "^3.5.0", - "rimraf": "^2.5.4", - "typescript": "^2.1.4" + "@types/chai": "^4.3.0", + "@types/mocha": "^9.1.0", + "@types/node": "^12.20.47", + "chai": "^4.3.6", + "mocha": "^9.2.2", + "prettier": "^2.6.0", + "rimraf": "^3.0.2", + "ts-node": "^10.7.0", + "typescript": "^4.6.2" } } diff --git a/src/lib/mocha-testrail-reporter.ts b/src/lib/mocha-testrail-reporter.ts index 1d4d7f19..d917c7e9 100644 --- a/src/lib/mocha-testrail-reporter.ts +++ b/src/lib/mocha-testrail-reporter.ts @@ -1,92 +1,92 @@ -import {reporters} from 'mocha'; -import {TestRail} from "./testrail"; -import {titleToCaseIds} from "./shared"; -import {Status, TestRailResult} from "./testrail.interface"; - +import { reporters } from "mocha"; +import { TestRail } from "./testrail"; +import { titleToCaseIds } from "./shared"; +import { Status, TestRailOptions, TestRailResult } from "./testrail.interface"; export class MochaTestRailReporter extends reporters.Spec { - private results: TestRailResult[] = []; - private passes: number = 0; - private fails: number = 0; - private pending: number = 0; - private out: string[] = []; + private results: TestRailResult[] = []; + private passes: number = 0; + private fails: number = 0; + private pending: number = 0; + private out: string[] = []; - constructor(runner: any, options: any) { - super(runner); + constructor(runner: any, options: any) { + super(runner); - let reporterOptions: TestRailOptions = options.reporterOptions; - this.validate(reporterOptions, 'domain'); - this.validate(reporterOptions, 'username'); - this.validate(reporterOptions, 'password'); - this.validate(reporterOptions, 'projectId'); - this.validate(reporterOptions, 'suiteId'); + let reporterOptions: TestRailOptions = ( + options.reporterOptions + ); - runner.on('start', () => { - }); + // validate options + ["domain", "username", "password", "projectId", "suiteId"].forEach( + (option) => MochaTestRailReporter.validate(reporterOptions, option) + ); - runner.on('suite', (suite) => { - }); + runner.on("start", () => {}); - runner.on('suite end', () => { - }); + runner.on("suite", () => {}); - runner.on('pending', (test) => { - this.pending++; - this.out.push(test.fullTitle() + ': pending'); - }); + runner.on("suite end", () => {}); - runner.on('pass', (test) => { - this.passes++; - this.out.push(test.fullTitle() + ': pass'); - let caseIds = titleToCaseIds(test.title); - if (caseIds.length > 0) { - if (test.speed === 'fast') { - let results = caseIds.map(caseId => { - return { - case_id: caseId, - status_id: Status.Passed, - comment: test.title - }; - }); - this.results.push(...results); - } else { - let results = caseIds.map(caseId => { - return { - case_id: caseId, - status_id: Status.Passed, - comment: `${test.title} (${test.duration}ms)` - }; - }); - this.results.push(...results); - } - } - }); + runner.on("pending", (test) => { + this.pending++; + this.out.push(test.fullTitle() + ": pending"); + }); - runner.on('fail', (test) => { - this.fails++; - this.out.push(test.fullTitle() + ': fail'); - let caseIds = titleToCaseIds(test.title); - if (caseIds.length > 0) { - let results = caseIds.map(caseId => { - return { - case_id: caseId, - status_id: Status.Failed, - comment: `${test.title} -${test.err}` - }; - }); - this.results.push(...results); - } + runner.on("pass", (test) => { + this.passes++; + this.out.push(test.fullTitle() + ": pass"); + let caseIds = titleToCaseIds(test.title); + if (caseIds.length > 0) { + if (test.speed === "fast") { + let results = caseIds.map((caseId) => { + return { + case_id: caseId, + status_id: Status.Passed, + comment: test.title, + }; + }); + this.results.push(...results); + } else { + let results = caseIds.map((caseId) => { + return { + case_id: caseId, + status_id: Status.Passed, + comment: `${test.title} (${test.duration}ms)`, + }; + }); + this.results.push(...results); + } + } + }); + + runner.on("fail", (test) => { + this.fails++; + this.out.push(test.fullTitle() + ": fail"); + let caseIds = titleToCaseIds(test.title); + if (caseIds.length > 0) { + let results = caseIds.map((caseId) => { + return { + case_id: caseId, + status_id: Status.Failed, + comment: `${test.title} +${test.err}`, + }; }); + this.results.push(...results); + } + }); - runner.on('end', () => { - if (this.results.length == 0) { - console.warn("No testcases were matched. Ensure that your tests are declared correctly and matches TCxxx"); - } - let executionDateTime = new Date().toISOString(); - let total = this.passes + this.fails + this.pending; - let name = `Automated test run ${executionDateTime}`; - let description = `Automated test run executed on ${executionDateTime} + runner.on("end", () => { + if (this.results.length == 0) { + console.warn( + "No testcases were matched. Ensure that your tests are declared correctly and matches TCxxx" + ); + } + let executionDateTime = new Date().toISOString(); + let total = this.passes + this.fails + this.pending; + let name = `Automated test run ${executionDateTime}`; + let description = `Automated test run executed on ${executionDateTime} Execution summary: Passes: ${this.passes} Fails: ${this.fails} @@ -94,18 +94,20 @@ Pending: ${this.pending} Total: ${total} Execution details: -${this.out.join('\n')} +${this.out.join("\n")} `; - new TestRail(reporterOptions).publish(name, description, this.results); - }); - } + new TestRail(reporterOptions).publish(name, description, this.results); + }); + } - private validate(options: TestRailOptions, name: string) { - if (options == null) { - throw new Error("Missing --reporter-options in mocha.opts"); - } - if (options[name] == null) { - throw new Error(`Missing ${name} value. Please update --reporter-options in mocha.opts`); - } + private static validate(options: TestRailOptions, name: string) { + if (options == null) { + throw new Error("Missing --reporter-options in mocha.opts"); + } + if (options[name] == null) { + throw new Error( + `Missing ${name} value. Please update --reporter-options in mocha.opts` + ); } + } } diff --git a/src/lib/shared.ts b/src/lib/shared.ts index 1d29253d..174486db 100644 --- a/src/lib/shared.ts +++ b/src/lib/shared.ts @@ -4,14 +4,13 @@ * @returns {any} */ export function titleToCaseIds(title: string): number[] { - let caseIds: number[] = []; + let caseIds: number[] = []; - let testCaseIdRegExp: RegExp = /\bT?C(\d+)\b/g; - let m; - while((m = testCaseIdRegExp.exec(title)) !== null) { - let caseId = parseInt(m[1]); - caseIds.push(caseId); - } - return caseIds; + let testCaseIdRegExp: RegExp = /\bT?C(\d+)\b/g; + let m; + while ((m = testCaseIdRegExp.exec(title)) !== null) { + let caseId = parseInt(m[1]); + caseIds.push(caseId); + } + return caseIds; } - diff --git a/src/lib/testrail.interface.ts b/src/lib/testrail.interface.ts index 0a8669a9..ee64db29 100644 --- a/src/lib/testrail.interface.ts +++ b/src/lib/testrail.interface.ts @@ -1,46 +1,46 @@ export interface TestRailOptions { - domain: string, - username: string, - password: string, - projectId: number, - suiteId: number, - assignedToId?: number, + domain: string; + username: string; + password: string; + projectId: string; + suiteId: string; + assignedToId?: string; } export enum Status { - Passed = 1, - Blocked = 2, - Untested = 3, - Retest = 4, - Failed = 5 + Passed = 1, + Blocked = 2, + Untested = 3, + Retest = 4, + Failed = 5, } export interface TestRailResult { - case_id: number, - status_id: Status, - comment?: String, + case_id: number; + status_id: Status; + comment?: String; } export interface TestRailCase { - id: number, - title: string, - section_id: number, - template_id: number, - type_id: number, - priority_id: number, - milestone_id?: number, - refs?: string, - created_by: number, - created_on: number, - updated_by: number, - updated_on: number, - estimate?: string, - estimate_forecast?: string, - suite_id: number, - custom_preconds?: string, - custom_steps?: string, - custom_expected?: string, - custom_steps_separated?: string, - custom_mission?: string, - custom_goals?: string -} \ No newline at end of file + id: number; + title: string; + section_id: number; + template_id: number; + type_id: number; + priority_id: number; + milestone_id?: number; + refs?: string; + created_by: number; + created_on: number; + updated_by: number; + updated_on: number; + estimate?: string; + estimate_forecast?: string; + suite_id: number; + custom_preconds?: string; + custom_steps?: string; + custom_expected?: string; + custom_steps_separated?: string; + custom_mission?: string; + custom_goals?: string; +} diff --git a/src/lib/testrail.ts b/src/lib/testrail.ts index dd82f460..9dd487eb 100644 --- a/src/lib/testrail.ts +++ b/src/lib/testrail.ts @@ -1,109 +1,137 @@ import request = require("unirest"); -import {TestRailOptions, TestRailResult} from "./testrail.interface"; +import { TestRailOptions, TestRailResult } from "./testrail.interface"; /** * TestRail basic API wrapper */ export class TestRail { - private base: String; + private base: String; - constructor(private options: TestRailOptions) { - // compute base url - this.base = `https://${options.domain}/index.php`; - } + constructor(private options: TestRailOptions) { + // check if all required options are specified + ["username", "password", "domain", "projectId", "projectId"].forEach( + (option) => { + if (!options[option]) { + throw new Error(`Missing required option ${option}`); + } + } + ); - private _post(api: String, body: any, callback: Function, error?: Function) { - var req = request("POST", this.base) - .query(`/api/v2/${api}`) - .headers({ - "content-type": "application/json" - }) - .type("json") - .send(body) - .auth(this.options.username, this.options.password) - .end((res) => { - if (res.error) { - console.log("Error: %s", JSON.stringify(res.body)); - if (error) { - error(res.error); - } else { - throw new Error(res.error); - } - } - callback(res.body); - }); - } + // compute base url + this.base = `https://${options.domain}/index.php`; + } - private _get(api: String, callback: Function, error?: Function) { - var req = request("GET", this.base) - .query(`/api/v2/${api}`) - .headers({ - "content-type": "application/json" - }) - .type("json") - .auth(this.options.username, this.options.password) - .end((res) => { - if (res.error) { - console.log("Error: %s", JSON.stringify(res.body)); - if (error) { - error(res.error); - } else { - throw new Error(res.error); - } - } - callback(res.body); - }); - } + private _post(api: String, body: any, callback: Function, error?: Function) { + request("POST", this.base) + .query(`/api/v2/${api}`) + .headers({ + "content-type": "application/json", + }) + .type("json") + .send(body) + .auth(this.options.username, this.options.password) + .end((res) => { + if (res.error) { + console.log("Error: %s", JSON.stringify(res.body)); + if (error) { + error(res.error); + } else { + throw new Error(res.error); + } + } + callback(res.body); + }); + } - /** - * Fetchs test cases from projet/suite based on filtering criteria (optional) - * @param {{[p: string]: number[]}} filters - * @param {Function} callback - */ - public fetchCases(filters?: { [key: string]: number[] }, callback?: Function): void { - let filter = ""; - if(filters) { - for (var key in filters) { - if (filters.hasOwnProperty(key)) { - filter += "&" + key + "=" + filters[key].join(","); - } - } + private _get(api: String, callback: Function, error?: Function): void { + request("GET", this.base) + .query(`/api/v2/${api}`) + .headers({ + "content-type": "application/json", + }) + .type("json") + .auth(this.options.username, this.options.password) + .end((res) => { + if (res.error) { + console.log("Error: %s", JSON.stringify(res.body)); + if (error) { + error(res.error); + } else { + throw new Error(res.error); + } } + callback(res.body); + }); + } - let req = this._get(`get_cases/${this.options.projectId}&suite_id=${this.options.suiteId}${filter}`, (body) => { - if (callback) { - callback(body); - } - }); + /** + * Fetchs test cases from projet/suite based on filtering criteria (optional) + * @param {{[p: string]: number[]}} filters + * @param {Function} callback + */ + public fetchCases( + filters?: { [key: string]: number[] }, + callback?: Function + ): void { + let filter = ""; + if (filters) { + for (let key in filters) { + if (filters.hasOwnProperty(key)) { + filter += "&" + key + "=" + filters[key].join(","); + } + } } - /** - * Publishes results of execution of an automated test run - * @param {string} name - * @param {string} description - * @param {TestRailResult[]} results - * @param {Function} callback - */ - public publish(name: string, description: string, results: TestRailResult[], callback?: Function): void { - console.log(`Publishing ${results.length} test result(s) to ${this.base}`); + this._get( + `get_cases/${this.options.projectId}&suite_id=${this.options.suiteId}${filter}`, + (body) => { + if (callback) { + callback(body.cases); + } + } + ); + } - this._post(`add_run/${this.options.projectId}`, { - "suite_id": this.options.suiteId, - "name": name, - "description": description, - "assignedto_id": this.options.assignedToId, - "include_all": true - }, (body) => { - const runId = body.id - console.log(`Results published to ${this.base}?/runs/view/${runId}`) - this._post(`add_results_for_cases/${runId}`, { - results: results - }, (body) => { - // execute callback if specified - if (callback) { - callback(); - } - }) - }); - } + /** + * Publishes results of execution of an automated test run + * @param {string} name + * @param {string} description + * @param {TestRailResult[]} results + * @param {Function} callback + */ + public publish( + name: string, + description: string, + results: TestRailResult[], + callback?: Function + ): void { + console.log(`Publishing ${results.length} test result(s) to ${this.base}`); + + this._post( + `add_run/${this.options.projectId}`, + { + suite_id: this.options.suiteId, + name: name, + description: description, + assignedto_id: this.options.assignedToId, + include_all: true, + }, + (body) => { + const runId = body.id; + console.log(`Results published to ${this.base}?/runs/view/${runId}`); + this._post( + `add_results_for_cases/${runId}`, + { + results: results, + }, + (body) => { + // execute callback if specified + if (callback) { + callback(body); + } + } + ); + } + ); + } } diff --git a/src/test/shared.spec.ts b/src/test/shared.spec.ts new file mode 100644 index 00000000..5bcd73f3 --- /dev/null +++ b/src/test/shared.spec.ts @@ -0,0 +1,38 @@ +import * as chai from "chai"; +chai.should(); + +import { titleToCaseIds } from "../lib/shared"; + +describe("Shared functions", () => { + describe("titleToCaseIds", () => { + it("Single test case id present", () => { + let caseIds = titleToCaseIds("C123 Test title"); + caseIds.length.should.be.equals(1); + caseIds[0].should.be.equals(123); + + caseIds = titleToCaseIds("Execution of C123 Test title"); + caseIds.length.should.be.equals(1); + caseIds[0].should.be.equals(123); + }); + it("Multiple test case ids present", () => { + let caseIds = titleToCaseIds("Execution C321 C123 Test title"); + caseIds.length.should.be.equals(2); + caseIds[0].should.be.equals(321); + caseIds[1].should.be.equals(123); + }); + it("No test case ids present", () => { + let caseIds = titleToCaseIds("Execution Test title"); + caseIds.length.should.be.equals(0); + }); + }); + + describe("Misc tests", () => { + it("String join", () => { + let out: string[] = []; + out.push("Test 1: fail"); + out.push("Test 2: pass"); + out.join("\n").should.be.equals(`Test 1: fail +Test 2: pass`); + }); + }); +}); diff --git a/src/test/shared.ts b/src/test/shared.ts deleted file mode 100644 index 320ad1fa..00000000 --- a/src/test/shared.ts +++ /dev/null @@ -1,38 +0,0 @@ -import * as chai from "chai"; -chai.should(); - -import {titleToCaseIds} from "../lib/shared"; - -describe("Shared functions", () => { - describe("titleToCaseIds", () => { - it("Single test case id present", () => { - let caseIds = titleToCaseIds("C123 Test title"); - caseIds.length.should.be.equals(1); - caseIds[0].should.be.equals(123); - - caseIds = titleToCaseIds("Execution of C123 Test title"); - caseIds.length.should.be.equals(1); - caseIds[0].should.be.equals(123); - }); - it("Multiple test case ids present", () => { - let caseIds = titleToCaseIds("Execution C321 C123 Test title"); - caseIds.length.should.be.equals(2); - caseIds[0].should.be.equals(321); - caseIds[1].should.be.equals(123); - }); - it("No test case ids present", () => { - let caseIds = titleToCaseIds("Execution Test title"); - caseIds.length.should.be.equals(0); - }); - }); - - describe("Misc tests", () => { - it("String join", () => { - let out: string[] = []; - out.push("Test 1: fail"); - out.push("Test 2: pass"); - out.join('\n').should.be.equals(`Test 1: fail -Test 2: pass`); - }); - }); -}); \ No newline at end of file diff --git a/src/test/testrail.spec.ts b/src/test/testrail.spec.ts new file mode 100644 index 00000000..c446b78e --- /dev/null +++ b/src/test/testrail.spec.ts @@ -0,0 +1,46 @@ +import { TestRail } from "../lib/testrail"; +import { TestRailCase, Status } from "../lib/testrail.interface"; + +describe("TestRail API", () => { + it("Publish test run", (done) => { + let testRail = new TestRail({ + domain: process.env.DOMAIN, + username: process.env.USERNAME, + password: process.env.PASSWORD, + projectId: process.env.PROJECTID, + suiteId: process.env.SUITEID, + assignedToId: process.env.ASSIGNEDTOID, + }); + + testRail.fetchCases({}, (cases: TestRailCase[]) => { + console.log(cases); + cases.forEach((value) => { + console.log(value.id, "-", value.title); + }); + }); + + testRail.publish( + "Unit Test of mocha-testrail-reporter", + "Unit Test of mocha-testrail-reporter", + [ + { + case_id: 1, + status_id: Status.Passed, + comment: "Passing....", + }, + { + case_id: 2, + status_id: Status.Passed, + }, + { + case_id: 3, + status_id: Status.Failed, + comment: "Failure....", + }, + ], + () => { + done(); + } + ); + }); +}); diff --git a/src/test/testrail.ts b/src/test/testrail.ts deleted file mode 100644 index 4527294a..00000000 --- a/src/test/testrail.ts +++ /dev/null @@ -1,39 +0,0 @@ -import {TestRail} from "../lib/testrail"; -import {TestRailResult, TestRailCase, Status} from "../lib/testrail.interface"; - -describe("TestRail API", () => { - it("Publish test run", (done) => { - let testRail = new TestRail({ - domain: process.env.DOMAIN, - username: process.env.USERNAME, - password: process.env.PASSWORD, - projectId: 10, - suiteId: 104, - // assignedToId: 2, - }); - - testRail.fetchCases({type_id: [3], priority_id: [4]}, (cases: TestRailCase[]) => { - console.log(cases); - let results: TestRailResult - cases.forEach((value => { - console.log(value.id, value.title); - })); - }); - - testRail.publish("Unit Test of mocha-testrail-reporter", "Unit Test of mocha-testrail-reporter", [{ - case_id: 3033, - status_id: Status.Passed, - comment: "Passing...." - }, { - case_id: 3034, - status_id: Status.Passed - }, { - case_id: 3035, - status_id: Status.Passed - }, { - case_id: 3036, - status_id: Status.Failed, - comment: "Failure...." - }], done); - }); -}); \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index d7806c3b..23a2bd23 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "ES5", + "target": "ES6", "module": "commonjs", "moduleResolution": "node", "sourceMap": true,