-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "added users listing fetch" - Accidental delete
This reverts commit 8a12765.
- Loading branch information
Showing
20 changed files
with
662 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Continuous Deploiment 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 | ||
env: | ||
TESTRAIL_DOMAIN: ${{ secrets.DOMAIN }} | ||
TESTRAIL_USERNAME: ${{ secrets.USERNAME }} | ||
TESTRAIL_PASSWORD: ${{ secrets.PASSWORD }} | ||
TESTRAIL_PROJECTID: 1 | ||
TESTRAIL_SUITEID: 1 | ||
TESTRAIL_ASSIGNEDTOID: 1 | ||
- run: yarn publish --access public | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Continuous Integration Checking | ||
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: | ||
TESTRAIL_DOMAIN: ${{ secrets.DOMAIN }} | ||
TESTRAIL_USERNAME: ${{ secrets.USERNAME }} | ||
TESTRAIL_PASSWORD: ${{ secrets.PASSWORD }} | ||
TESTRAIL_PROJECTID: 1 | ||
TESTRAIL_SUITEID: 1 | ||
TESTRAIL_ASSIGNEDTOID: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
node_modules | ||
node-debug* | ||
*.log | ||
.c9/ | ||
*.iml | ||
.idea/ | ||
*.sh | ||
dist | ||
.env | ||
*.tgz | ||
yarn.lock | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.github | ||
.idea/ | ||
src/ | ||
dist/test | ||
*.iml | ||
tsconfig.json | ||
*.map | ||
*.lock | ||
package-lock.json | ||
.prettier* | ||
.env | ||
*.tgz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
registry=https://registry.npmjs.org/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist/ | ||
node_modules/* |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#Testrail Reporter for Mocha | ||
|
||
[![npm version](https://badge.fury.io/js/mocha-testrail-reporter.svg)](https://badge.fury.io/js/mocha-testrail-reporter) | ||
|
||
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 | ||
$ npm install mocha-testrail-reporter --save-dev | ||
``` | ||
|
||
## Usage | ||
Ensure that your testrail installation API is enabled and generate your API keys. See http://docs.gurock.com/ | ||
|
||
Run mocha with `mocha-testrail-reporter`: | ||
|
||
```shell | ||
$ mocha test --reporter mocha-testrail-reporter --reporter-options domain=instance.testrail.net,[email protected],password=12345678,projectId=1,suiteId=1 | ||
``` | ||
|
||
or use a mocha.options file | ||
```shell | ||
mocha --opts mocha-testrail.opts build/test | ||
--recursive | ||
--reporter mocha-testrail-reporter | ||
--reporter-options domain=instance.testrail.net,[email protected],password=12345678,projectId=1,suiteId=1 | ||
--no-exit | ||
``` | ||
|
||
|
||
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", () => {}) | ||
``` | ||
|
||
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. | ||
|
||
## Options | ||
|
||
**domain**: *string* domain name of your Testrail instance (e.g. for a hosted instance instance.testrail.net) | ||
|
||
**username**: *string* user under which the test run will be created (e.g. jenkins or ci) | ||
|
||
**password**: *string* password or API token for user | ||
|
||
**projectId**: *number* projet number with which the tests are associated | ||
|
||
**suiteId**: *number* suite number with which the tests are associated | ||
|
||
**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 | ||
- TESTRAIL_DOMAIN=XXX.testrail.io | ||
- TESTRAIL_USERNAME=XXX | ||
- TESTRAIL_PASSWORD=XXX | ||
- TESTRAIL_PROJECTID=1 | ||
- TESTRAIL_SUITEID=1 | ||
- TESTRAIL_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 | ||
- http://docs.gurock.com/testrail-api2/start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package-lock.json | ||
yarn.lock | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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:.." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require("./dist/lib/mocha-testrail-reporter").MochaTestRailReporter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"name": "mocha-testrail-reporter", | ||
"version": "2.0.5", | ||
"description": "A Testrail reporter for mocha utilising TestRail API", | ||
"main": "index.js", | ||
"private": false, | ||
"keywords": [ | ||
"mocha", | ||
"testrail", | ||
"reporter" | ||
], | ||
"author": { | ||
"name": "Pierre Awaragi", | ||
"email": "[email protected]" | ||
}, | ||
"license": "MIT", | ||
"readmeFilename": "README.md", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/awaragi/mocha-testrail-reporter.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/awaragi/mocha-testrail-reporter/issues" | ||
}, | ||
"scripts": { | ||
"build": "tsc", | ||
"clean": "rimraf dist", | ||
"test": "mocha dist/test", | ||
"test:ts": "mocha -r ts-node/register src/test/*", | ||
"format": "prettier --check ./**/* --write" | ||
}, | ||
"dependencies": { | ||
"btoa": "^1.1.2", | ||
"unirest": "^0.6.0" | ||
}, | ||
"peerDependencies": { | ||
"mocha": "9.2.2" | ||
}, | ||
"devDependencies": { | ||
"@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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
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[] = []; | ||
|
||
constructor(runner: any, options: any) { | ||
super(runner); | ||
|
||
let reporterOptions: TestRailOptions = <TestRailOptions>( | ||
options.reporterOptions | ||
); | ||
|
||
// validate options | ||
["domain", "username", "password", "projectId", "suiteId"].forEach( | ||
(option) => MochaTestRailReporter.validate(reporterOptions, option) | ||
); | ||
|
||
runner.on("start", () => {}); | ||
|
||
runner.on("suite", () => {}); | ||
|
||
runner.on("suite end", () => {}); | ||
|
||
runner.on("pending", (test) => { | ||
this.pending++; | ||
this.out.push(test.fullTitle() + ": pending"); | ||
}); | ||
|
||
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} | ||
Execution summary: | ||
Passes: ${this.passes} | ||
Fails: ${this.fails} | ||
Pending: ${this.pending} | ||
Total: ${total} | ||
Execution details: | ||
${this.out.join("\n")} | ||
`; | ||
new TestRail(reporterOptions).publish(name, description, this.results); | ||
}); | ||
} | ||
|
||
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` | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Search for all applicable test cases | ||
* @param title | ||
* @returns {any} | ||
*/ | ||
export function titleToCaseIds(title: string): 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; | ||
} |
Oops, something went wrong.