diff --git a/README.md b/README.md index e9591a9..3962175 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,7 @@ [![version](https://img.shields.io/npm/v/azuredevops-test-reporter-ts.svg)](https://www.npmjs.com/package/azuredevops-test-reporter-ts) [![downloads](https://img.shields.io/npm/dt/azuredevops-test-reporter-ts.svg)](https://www.npmjs.com/package/azuredevops-test-reporter-ts) -Using this package with [WDIO Azure Devops Service](https://github.com/techconative/wdio-azure-devops-service) to publish WDIO test results to Azure Test Plan. \ No newline at end of file +Using this package with [WDIO Azure Devops Service](https://github.com/techconative/wdio-azure-devops-service) to publish WDIO test results to Azure Test Plan. + +### Pre-requisite to run test: +create a `.env` file at root directory of this project and add value for `AZURE_DEVOPS_PAT`=***$$##*** \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index bfbc4f4..7607286 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,17 +1,18 @@ { "name": "azuredevops-test-reporter-ts", - "version": "0.0.9", + "version": "1.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "azuredevops-test-reporter-ts", - "version": "0.0.9", + "version": "1.1.0", "hasInstallScript": true, "license": "MIT", "dependencies": { "axios": "^0.27.2", "azure-devops-node-api": "^11.1.1", + "dotenv": "^16.4.5", "validate": "^5.2.0" }, "devDependencies": { @@ -3514,6 +3515,17 @@ "node": ">=8" } }, + "node_modules/dotenv": { + "version": "16.4.5", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", + "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/electron-to-chromium": { "version": "1.3.838", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.838.tgz", diff --git a/package.json b/package.json index f0f537b..8fae81d 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "dependencies": { "axios": "^0.27.2", "azure-devops-node-api": "^11.1.1", + "dotenv": "^16.4.5", "validate": "^5.2.0" }, "devDependencies": { diff --git a/test/azureTestPlanReporter.test.ts b/test/azureTestPlanReporter.test.ts index 1212dc3..c30c752 100644 --- a/test/azureTestPlanReporter.test.ts +++ b/test/azureTestPlanReporter.test.ts @@ -2,12 +2,13 @@ import { AxiosInstance } from 'axios' import { ITestApi } from 'azure-devops-node-api/TestApi' import { IAzureConfig } from '../src/interfaces/IAzureConfig' import { AzureTestPlanReporter } from '../src/index' +import TestConfig from './test-config' const validAzureConfig: IAzureConfig = { - pat: 'v3e3pg4njfmzzcuoxwb4vja3trwbyafim4x4oww7sbcfbopfb3bq', + pat: TestConfig.pat, organizationUrl: 'https://dev.azure.com/organization', projectId: '3cf7dbc9-cb1e-4240-93f2-9a5960ab3945', planId: 12, diff --git a/test/test-config.ts b/test/test-config.ts new file mode 100644 index 0000000..45d050c --- /dev/null +++ b/test/test-config.ts @@ -0,0 +1,23 @@ +import * as dotenv from 'dotenv'; +dotenv.config(); + +const Config = { + //Env variables + pat: getEnv("AZURE_DEVOPS_PAT"), +} as const; + +export default Config; + +/** + * function used to verify env values are defined and + * returns envValue + * @param {string} envValue + * @returns string + */ +function getEnv(envValue: string): string { + const value = process.env[envValue]; + if (value === undefined) { + throw new Error(`Environment variable ${envValue} is not set.`); + } + return value; +} diff --git a/test/testCasePoints.test.ts b/test/testCasePoints.test.ts index 3b3beb2..c89aa5d 100644 --- a/test/testCasePoints.test.ts +++ b/test/testCasePoints.test.ts @@ -2,10 +2,11 @@ import { AxiosInstance } from 'axios' import { ITestApi } from 'azure-devops-node-api/TestApi' import { IAzureConfig } from '../src/interfaces/IAzureConfig' import { getPoints } from '../src/services/azure/testCasePoints' +import TestConfig from './test-config' const azureConfig: IAzureConfig = { - pat: 'v3e3pg4njfmzzcuoxwb4vja3trwbyafim4x4oww7sbcfbopfb3bq', + pat: TestConfig.pat, organizationUrl: 'https://dev.azure.com/organization', projectId: '3cf7dbc9-cb1e-4240-93f2-9a5960ab3945', planId: 12, @@ -14,7 +15,7 @@ const azureConfig: IAzureConfig = { } const azureConfigWithConfigName: IAzureConfig = { - pat: 'v3e3pg4njfmzzcuoxwb4vja3trwbyafim4x4oww7sbcfbopfb3bq', + pat: TestConfig.pat, organizationUrl: 'https://dev.azure.com/organization', projectId: '3cf7dbc9-cb1e-4240-93f2-9a5960ab3945', planId: 12, diff --git a/test/testResults.test.ts b/test/testResults.test.ts index 8d91884..bb78375 100644 --- a/test/testResults.test.ts +++ b/test/testResults.test.ts @@ -3,10 +3,11 @@ import { ITestApi } from 'azure-devops-node-api/TestApi' import { IAzureConfig } from '../src/interfaces/IAzureConfig' import { ITestResult } from '../src/interfaces/ITestResult' import { setTestResult } from '../src/services/azure/testResults' +import TestConfig from './test-config' const azureConfig: IAzureConfig = { - pat: 'v3e3pg4njfmzzcuoxwb4vja3trwbyafim4x4oww7sbcfbopfb3bq', + pat: TestConfig.pat, organizationUrl: 'https://dev.azure.com/organization', projectId: '3cf7dbc9-cb1e-4240-93f2-9a5960ab3945', planId: 12, diff --git a/test/validate.test.ts b/test/validate.test.ts index 221a4bb..8547db6 100644 --- a/test/validate.test.ts +++ b/test/validate.test.ts @@ -1,5 +1,6 @@ import { IAzureConfig } from '../src/interfaces/IAzureConfig'; -import {validate} from '../src/services/validation/index' +import { validate } from '../src/services/validation/index' +import TestConfig from './test-config' describe("Validate Azure DevOps config provided", () => { @@ -11,7 +12,7 @@ describe("Validate Azure DevOps config provided", () => { it("validate should fail if are missing required params", ()=>{ const conf = { - pat: "vgrdpg4njfmzzcuoxwb4vja3trwbyafim4x4oww7sbcfbopfb3bq", + pat: TestConfig.pat, organizationUrl: "{Organization Name}", projectId: "{Project Name}", runName: "{The Test Run name that should be assigned for Runs created by this reporter}" @@ -23,7 +24,7 @@ describe("Validate Azure DevOps config provided", () => { it("validate should success if are present all the required params", ()=>{ const completeConf = { - pat: "vgrdpg4njfmzzcuoxwb4vja3trwbyafim4x4oww7sbcfbopfb3bq", + pat: TestConfig.pat, organizationUrl: "{Organization Name}", projectId: "11", planId: 1,