Skip to content

Commit

Permalink
test: test updates for env value
Browse files Browse the repository at this point in the history
  • Loading branch information
sundarlogan committed May 8, 2024
1 parent 4332813 commit 63db40e
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 10 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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`=***$$##***
16 changes: 14 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
3 changes: 2 additions & 1 deletion test/azureTestPlanReporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 23 additions & 0 deletions test/test-config.ts
Original file line number Diff line number Diff line change
@@ -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;
}
5 changes: 3 additions & 2 deletions test/testCasePoints.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion test/testResults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions test/validate.test.ts
Original file line number Diff line number Diff line change
@@ -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", () => {

Expand All @@ -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}"
Expand All @@ -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,
Expand Down

0 comments on commit 63db40e

Please sign in to comment.