Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AzureTestPlanTask: Implemented support for Jest #20035

Merged
merged 5 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 44 additions & 6 deletions Tasks/AzureTestPlanV0/Invokers/jestinvoker.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,52 @@
import tl = require('azure-pipelines-task-lib/task');
import utils = require('../utils');
import constants = require('../constants');
import { executeJestCommand } from '../testLibExecutor';

//Jest command like: >set JEST_JUNIT_OUTPUT_NAME=TEST-Jest0-junit.xml
//>npx jest --ci --reporters=default --reporters=jest-junit -t "JestTestName"
export async function executeJestTests(testsToBeExecuted: string[]): Promise<number> {

// jest execution will be added
/*executable = npm
args = test
*/
//Jest-Junit Link:https://github.com/jest-community/jest-junit
let finalStatus = 0;
let npmPath = tl.which("npm", true);
try {
await executeJestCommand(npmPath, constants.INSTALL_JESTJUNIT);
} catch (error) {
tl.error(`Error installing Jest-Junit: ${error}`);
return 1;
}
//testToBeExecuted: <TestSuiteName1> <TestCase1>. <TestSuiteName1> <TestCase1>,<TestSuiteName2> <TestCase3>. <TestSuiteName2> <TestCase3>
let npxPath = tl.which("npx", true);
let i = 0;
for (let tests of testsToBeExecuted) {
const JestTestName = utils.separateJestTestName(tests);
try {
let junitFileName: string = `TEST-Jest${i}-junit.xml`;
try {
tl.setVariable('JEST_JUNIT_OUTPUT_NAME', junitFileName);
let junitName = tl.getVariable('JEST_JUNIT_OUTPUT_NAME');
if (junitName !== junitFileName) {
throw new Error(`Retrieved JEST_JUNIT_OUTPUT_NAME (${junitName}) does not match the set value (${junitFileName})`);
}
tl.debug(`Junit Filename ${junitName} environment set and retrieved successfully.`);
} catch (error) {
tl.error(`Error setting or getting JEST_JUNIT_OUTPUT_NAME variable: ${error}`);
finalStatus = 1;
continue;
}

console.log("jest changes1");
return 1;
const jestCommand = `jest --ci --reporters=default --reporters=jest-junit -t "${JestTestName}"`;
t-shreysingh marked this conversation as resolved.
Show resolved Hide resolved
const status = await executeJestCommand(npxPath, jestCommand);
if (status != 0) {
finalStatus = 1;
}
tl.debug(`Test case ${JestTestName} executed successfully.`);
t-shreysingh marked this conversation as resolved.
Show resolved Hide resolved
} catch (error) {
tl.error(`Error executing ${JestTestName} test case: ${error}`);
finalStatus = 1;
}
i++;
}
return finalStatus;
}
3 changes: 2 additions & 1 deletion Tasks/AzureTestPlanV0/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export const MERGE_THRESHOLD = 100;
export const AUTOMATED_EXECUTION = "AutomatedExecutionPhase";
export const AUTOMATED_PUBLISHING = "PublishingAutomatedResultsPhase";
export const MANUALTESTS_PUBLISHING = "ManualTestResultsPublishingPhase";
export const INSTALL_GOTESTSUM = "install gotest.tools/gotestsum@latest";
export const INSTALL_GOTESTSUM = "install gotest.tools/gotestsum@latest";
export const INSTALL_JESTJUNIT = "i jest-junit";
2 changes: 1 addition & 1 deletion Tasks/AzureTestPlanV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 0,
"Minor": 241,
"Patch": 6
"Patch": 8
},
"preview": true,
"demands": [],
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureTestPlanV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 0,
"Minor": 241,
"Patch": 6
"Patch": 8
},
"preview": true,
"demands": [],
Expand Down
6 changes: 6 additions & 0 deletions Tasks/AzureTestPlanV0/testLibExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,10 @@ export async function executeGoCommand(goPath: string, argument: string): Promis
let go: tr.ToolRunner = tl.tool(goPath);
go.line(argument);
return await go.exec(<tr.IExecOptions>{ cwd: "" });
}

export async function executeJestCommand(jestPath: string, argument: string): Promise<number> {
let jest: tr.ToolRunner = tl.tool(jestPath);
jest.line(argument);
return await jest.exec(<tr.IExecOptions>{ cwd: "" });
}
11 changes: 11 additions & 0 deletions Tasks/AzureTestPlanV0/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,15 @@ export function separateGoTestName(inputString) {
// If there is no dot in the string, return the original string
return inputString;
}
}

export function separateJestTestName(inputString) {
const lastDotIndex = inputString.lastIndexOf('.');

if (lastDotIndex !== -1) {
const testName = inputString.slice(lastDotIndex + 1);
return testName;
} else {
return inputString;
}
}
4 changes: 2 additions & 2 deletions _generated/AzureTestPlanV0.versionmap.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Default|0.241.6
Node20-225|0.241.7
Default|0.241.8
Node20-225|0.241.9
50 changes: 44 additions & 6 deletions _generated/AzureTestPlanV0/Invokers/jestinvoker.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,52 @@
import tl = require('azure-pipelines-task-lib/task');
import utils = require('../utils');
import constants = require('../constants');
import { executeJestCommand } from '../testLibExecutor';

//Jest command like: >set JEST_JUNIT_OUTPUT_NAME=TEST-Jest0-junit.xml
//>npx jest --ci --reporters=default --reporters=jest-junit -t "JestTestName"
export async function executeJestTests(testsToBeExecuted: string[]): Promise<number> {

// jest execution will be added
/*executable = npm
args = test
*/
//Jest-Junit Link:https://github.com/jest-community/jest-junit
let finalStatus = 0;
let npmPath = tl.which("npm", true);
try {
await executeJestCommand(npmPath, constants.INSTALL_JESTJUNIT);
} catch (error) {
tl.error(`Error installing Jest-Junit: ${error}`);
return 1;
}
//testToBeExecuted: <TestSuiteName1> <TestCase1>. <TestSuiteName1> <TestCase1>,<TestSuiteName2> <TestCase3>. <TestSuiteName2> <TestCase3>
let npxPath = tl.which("npx", true);
let i = 0;
for (let tests of testsToBeExecuted) {
const JestTestName = utils.separateJestTestName(tests);
try {
let junitFileName: string = `TEST-Jest${i}-junit.xml`;
try {
tl.setVariable('JEST_JUNIT_OUTPUT_NAME', junitFileName);
let junitName = tl.getVariable('JEST_JUNIT_OUTPUT_NAME');
if (junitName !== junitFileName) {
throw new Error(`Retrieved JEST_JUNIT_OUTPUT_NAME (${junitName}) does not match the set value (${junitFileName})`);
}
tl.debug(`Junit Filename ${junitName} environment set and retrieved successfully.`);
} catch (error) {
tl.error(`Error setting or getting JEST_JUNIT_OUTPUT_NAME variable: ${error}`);
finalStatus = 1;
continue;
}

console.log("jest changes1");
return 1;
const jestCommand = `jest --ci --reporters=default --reporters=jest-junit -t "${JestTestName}"`;
const status = await executeJestCommand(npxPath, jestCommand);
if (status != 0) {
finalStatus = 1;
}
tl.debug(`Test case ${JestTestName} executed successfully.`);
} catch (error) {
tl.error(`Error executing ${JestTestName} test case: ${error}`);
finalStatus = 1;
}
i++;
}
return finalStatus;
}
3 changes: 2 additions & 1 deletion _generated/AzureTestPlanV0/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export const MERGE_THRESHOLD = 100;
export const AUTOMATED_EXECUTION = "AutomatedExecutionPhase";
export const AUTOMATED_PUBLISHING = "PublishingAutomatedResultsPhase";
export const MANUALTESTS_PUBLISHING = "ManualTestResultsPublishingPhase";
export const INSTALL_GOTESTSUM = "install gotest.tools/gotestsum@latest";
export const INSTALL_GOTESTSUM = "install gotest.tools/gotestsum@latest";
export const INSTALL_JESTJUNIT = "i jest-junit";
6 changes: 3 additions & 3 deletions _generated/AzureTestPlanV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 0,
"Minor": 241,
"Patch": 6
"Patch": 8
},
"preview": true,
"demands": [],
Expand Down Expand Up @@ -178,7 +178,7 @@
"MultipleMatchingGradlewFound": "Multiple gradlew files found. Selecting the first matched instance"
},
"_buildConfigMapping": {
"Default": "0.241.6",
"Node20-225": "0.241.7"
"Default": "0.241.8",
"Node20-225": "0.241.9"
}
}
6 changes: 3 additions & 3 deletions _generated/AzureTestPlanV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 0,
"Minor": 241,
"Patch": 6
"Patch": 8
},
"preview": true,
"demands": [],
Expand Down Expand Up @@ -178,7 +178,7 @@
"MultipleMatchingGradlewFound": "ms-resource:loc.messages.MultipleMatchingGradlewFound"
},
"_buildConfigMapping": {
"Default": "0.241.6",
"Node20-225": "0.241.7"
"Default": "0.241.8",
"Node20-225": "0.241.9"
}
}
6 changes: 6 additions & 0 deletions _generated/AzureTestPlanV0/testLibExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,10 @@ export async function executeGoCommand(goPath: string, argument: string): Promis
let go: tr.ToolRunner = tl.tool(goPath);
go.line(argument);
return await go.exec(<tr.IExecOptions>{ cwd: "" });
}

export async function executeJestCommand(jestPath: string, argument: string): Promise<number> {
let jest: tr.ToolRunner = tl.tool(jestPath);
jest.line(argument);
return await jest.exec(<tr.IExecOptions>{ cwd: "" });
}
11 changes: 11 additions & 0 deletions _generated/AzureTestPlanV0/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,15 @@ export function separateGoTestName(inputString) {
// If there is no dot in the string, return the original string
return inputString;
}
}

export function separateJestTestName(inputString) {
const lastDotIndex = inputString.lastIndexOf('.');

if (lastDotIndex !== -1) {
const testName = inputString.slice(lastDotIndex + 1);
return testName;
} else {
return inputString;
}
}
50 changes: 44 additions & 6 deletions _generated/AzureTestPlanV0_Node20/Invokers/jestinvoker.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,52 @@
import tl = require('azure-pipelines-task-lib/task');
import utils = require('../utils');
import constants = require('../constants');
import { executeJestCommand } from '../testLibExecutor';

//Jest command like: >set JEST_JUNIT_OUTPUT_NAME=TEST-Jest0-junit.xml
//>npx jest --ci --reporters=default --reporters=jest-junit -t "JestTestName"
export async function executeJestTests(testsToBeExecuted: string[]): Promise<number> {

// jest execution will be added
/*executable = npm
args = test
*/
//Jest-Junit Link:https://github.com/jest-community/jest-junit
let finalStatus = 0;
let npmPath = tl.which("npm", true);
try {
await executeJestCommand(npmPath, constants.INSTALL_JESTJUNIT);
} catch (error) {
tl.error(`Error installing Jest-Junit: ${error}`);
return 1;
}
//testToBeExecuted: <TestSuiteName1> <TestCase1>. <TestSuiteName1> <TestCase1>,<TestSuiteName2> <TestCase3>. <TestSuiteName2> <TestCase3>
let npxPath = tl.which("npx", true);
let i = 0;
for (let tests of testsToBeExecuted) {
const JestTestName = utils.separateJestTestName(tests);
try {
let junitFileName: string = `TEST-Jest${i}-junit.xml`;
try {
tl.setVariable('JEST_JUNIT_OUTPUT_NAME', junitFileName);
let junitName = tl.getVariable('JEST_JUNIT_OUTPUT_NAME');
if (junitName !== junitFileName) {
throw new Error(`Retrieved JEST_JUNIT_OUTPUT_NAME (${junitName}) does not match the set value (${junitFileName})`);
}
tl.debug(`Junit Filename ${junitName} environment set and retrieved successfully.`);
} catch (error) {
tl.error(`Error setting or getting JEST_JUNIT_OUTPUT_NAME variable: ${error}`);
finalStatus = 1;
continue;
}

console.log("jest changes1");
return 1;
const jestCommand = `jest --ci --reporters=default --reporters=jest-junit -t "${JestTestName}"`;
const status = await executeJestCommand(npxPath, jestCommand);
if (status != 0) {
finalStatus = 1;
}
tl.debug(`Test case ${JestTestName} executed successfully.`);
} catch (error) {
tl.error(`Error executing ${JestTestName} test case: ${error}`);
finalStatus = 1;
}
i++;
}
return finalStatus;
}
3 changes: 2 additions & 1 deletion _generated/AzureTestPlanV0_Node20/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export const MERGE_THRESHOLD = 100;
export const AUTOMATED_EXECUTION = "AutomatedExecutionPhase";
export const AUTOMATED_PUBLISHING = "PublishingAutomatedResultsPhase";
export const MANUALTESTS_PUBLISHING = "ManualTestResultsPublishingPhase";
export const INSTALL_GOTESTSUM = "install gotest.tools/gotestsum@latest";
export const INSTALL_GOTESTSUM = "install gotest.tools/gotestsum@latest";
export const INSTALL_JESTJUNIT = "i jest-junit";
6 changes: 3 additions & 3 deletions _generated/AzureTestPlanV0_Node20/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 0,
"Minor": 241,
"Patch": 7
"Patch": 9
},
"preview": true,
"demands": [],
Expand Down Expand Up @@ -182,7 +182,7 @@
"MultipleMatchingGradlewFound": "Multiple gradlew files found. Selecting the first matched instance"
},
"_buildConfigMapping": {
"Default": "0.241.6",
"Node20-225": "0.241.7"
"Default": "0.241.8",
"Node20-225": "0.241.9"
}
}
6 changes: 3 additions & 3 deletions _generated/AzureTestPlanV0_Node20/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 0,
"Minor": 241,
"Patch": 7
"Patch": 9
},
"preview": true,
"demands": [],
Expand Down Expand Up @@ -182,7 +182,7 @@
"MultipleMatchingGradlewFound": "ms-resource:loc.messages.MultipleMatchingGradlewFound"
},
"_buildConfigMapping": {
"Default": "0.241.6",
"Node20-225": "0.241.7"
"Default": "0.241.8",
"Node20-225": "0.241.9"
}
}
6 changes: 6 additions & 0 deletions _generated/AzureTestPlanV0_Node20/testLibExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,10 @@ export async function executeGoCommand(goPath: string, argument: string): Promis
let go: tr.ToolRunner = tl.tool(goPath);
go.line(argument);
return await go.exec(<tr.IExecOptions>{ cwd: "" });
}

export async function executeJestCommand(jestPath: string, argument: string): Promise<number> {
let jest: tr.ToolRunner = tl.tool(jestPath);
jest.line(argument);
return await jest.exec(<tr.IExecOptions>{ cwd: "" });
}
11 changes: 11 additions & 0 deletions _generated/AzureTestPlanV0_Node20/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,15 @@ export function separateGoTestName(inputString) {
// If there is no dot in the string, return the original string
return inputString;
}
}

export function separateJestTestName(inputString) {
const lastDotIndex = inputString.lastIndexOf('.');

if (lastDotIndex !== -1) {
const testName = inputString.slice(lastDotIndex + 1);
return testName;
} else {
return inputString;
}
}