Skip to content

Commit 1b6318c

Browse files
sanjuyadav24Sanju Yadav
andauthored
Updated mock test to support test cases for Node24 in task (#1132)
* Updated mock test to support test cases for Node24 in task * Changes to add support for Node 24 --------- Co-authored-by: Sanju Yadav <sanjuyadav@microsoft.com>
1 parent 8aee318 commit 1b6318c

File tree

10 files changed

+77
-15
lines changed

10 files changed

+77
-15
lines changed

node/README.md

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,32 @@ Documentation: [TypeScript API](https://github.com/microsoft/azure-pipelines-tas
1717

1818
Guidance: [Finding Files](https://github.com/microsoft/azure-pipelines-task-lib/blob/master/node/docs/findingfiles.md), [Minimum agent version](https://github.com/microsoft/azure-pipelines-task-lib/blob/master/node/docs/minagent.md), [Proxy](https://github.com/microsoft/azure-pipelines-task-lib/blob/master/node/docs/proxy.md), [Certificate](https://github.com/microsoft/azure-pipelines-task-lib/blob/master/node/docs/cert.md)
1919

20-
## Node 10 Upgrade Notice
20+
## Node Runtime Support
2121

22-
Azure DevOps is currently working to establish Node 10 as the new preferred runtime for tasks, upgrading from Node 6.
23-
Relevant work is happening in the `master` branch and the major version should be used with Node 10 is 3.
24-
Previous major version is stored in the `releases/2.x`
22+
Azure Pipelines supports multiple Node.js runtimes for task execution:
2523

26-
### Upgrading to Node 10
24+
* **Node 6** - Supported
25+
* **Node 10** - Supported
26+
* **Node 16** - Supported
27+
* **Node 20** - Current recommended version
28+
* **Node 24** - Latest version with modern JavaScript features
2729

28-
Upgrading your tasks from Node 6 should be relatively painless, however there are some things to note:
29-
* Typescript has been upgraded to TS 4. Older versions of TS may or may not work with Node 14 or the 3.x branch. We recommend upgrading to TS 4 when upgrading to task-lib 3.x.
30-
* Node has made some changes to `fs` between Node 6 and Node 10. It is worth reviewing and testing your tasks thoroughly before publishing updates to Node 10.
30+
### Node Version Selection
31+
32+
The Node runtime used depends on the `execution` handler specified in your task's `task.json`:
33+
* `Node` - Uses Node 6
34+
* `Node10` - Uses Node 10
35+
* `Node16` - Uses Node 16
36+
* `Node20_1` - Uses Node 20 (Note: handler name includes _1 suffix)
37+
* `Node24` - Uses Node 24
38+
39+
### Upgrading to Newer Node Versions
40+
41+
When upgrading your tasks to newer Node versions:
42+
* **TypeScript**: Ensure you're using a compatible TypeScript version (TS 4.0+ for Node 10+, TS 5.0+ for Node 20+, TS 5.7+ for Node 24)
43+
* **Dependencies**: Review and update npm dependencies for compatibility with the target Node version
44+
* **Testing**: Thoroughly test your tasks with the new Node runtime before publishing
45+
* **Breaking Changes**: Review Node.js release notes for breaking changes between versions (especially `fs` module changes)
3146

3247
## Reference Examples
3348

node/docs/minagent.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ Use the details below to determine when specific agent features were added:
3030
- Added in 2.144.0. Used node v10.x
3131
* `node16` handler
3232
- Added in 2.206.1. Used node v16.x
33+
* `node20` handler
34+
- Added in 2.214.1. Used node v20.x
35+
* `node24` handler
36+
- Added in 3.250.0. Uses node v24.x
3337
* `powershell3` handler
3438
- Added in 1.95.1
3539
- Updated in 1.97 to propagate `Data` property for endpoints

node/docs/nodeVersioning.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
## Agent Node Handler
44

5-
The agent currently has 3 different node handlers that it can use to execute node tasks: Node 6, Node 10, Node 16.
5+
The agent currently has multiple node handlers that it can use to execute node tasks: Node 6, Node 10, Node 16, Node 20, and Node 24.
66
The handler used depends on the `execution` property specified in the tasks `task.json`.
7-
If the `execution` property is specified to be `Node`, the task will run on the Node 6 handler, for `Node10` it will run on the Node 10 handler, for `Node16` it will run on the Node 16 handler.
7+
If the `execution` property is specified to be `Node`, the task will run on the Node 6 handler, for `Node10` it will run on the Node 10 handler, for `Node16` it will run on the Node 16 handler, for `Node20_1` it will run on the Node 20 handler, and for `Node24` it will run on the Node 24 handler.
88

99
## Mock-test Node Handler
1010

@@ -16,5 +16,5 @@ If this version of node is not found on the path, the library downloads the appr
1616

1717
### Behavior overrides
1818

19-
To specify a specific version of node to use, set the `nodeVersion` optional parameter in the `run` function of the `MockTestRunner` to the integer major version (e.g. `mtr.run(5)`).
19+
To specify a specific version of node to use, set the `nodeVersion` optional parameter in the `run` function of the `MockTestRunner` to the integer major version (e.g. `mtr.run(20)` for Node 20, `mtr.run(24)` for Node 24).
2020
To specify the location of a `task.json` file, set the `taskJsonPath` optional parameter in the `MockTestRunner` constructor to the path of the file (e.g. `let mtr = new mt.MockTaskRunner('<pathToTest>', '<pathToTask.json>'`).

node/mock-test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ export class MockTestRunner {
166166
private async getNodePath(nodeVersion?: number): Promise<string> {
167167
const version: number = nodeVersion || this.getNodeVersion();
168168
const versions = {
169+
24: 'v24.10.0',
169170
20: 'v20.13.1',
170171
16: 'v16.20.2',
171172
10: 'v10.24.1',
@@ -174,7 +175,7 @@ export class MockTestRunner {
174175

175176
const downloadVersion: string = versions[version];
176177
if (!downloadVersion) {
177-
throw new Error('Invalid node version, must be 6, 10, 16 or 20 (received ' + version + ')');
178+
throw new Error('Invalid node version, must be 6, 10, 16, 20 or 24 (received ' + version + ')');
178179
}
179180

180181
// Install node in home directory if it isn't already there.

node/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "azure-pipelines-task-lib",
3-
"version": "5.2.1",
3+
"version": "5.2.2",
44
"description": "Azure Pipelines Task SDK",
55
"main": "./task.js",
66
"typings": "./task.d.ts",
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Minimal entry point for Node 24 task testing
2+
console.log('Node 24 task entry point');
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"id": "id",
3+
"name": "Node24Task",
4+
"execution": {
5+
"Node": {
6+
"target": "usedotnet.js"
7+
},
8+
"Node10": {
9+
"target": "usedotnet.js"
10+
},
11+
"Node16": {
12+
"target": "usedotnet.js"
13+
},
14+
"Node20_1": {
15+
"target": "usedotnet.js"
16+
},
17+
"Node24": {
18+
"target": "usedotnet.js"
19+
}
20+
}
21+
}

node/test/mocktests.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,16 @@ describe('Mock Tests', function () {
348348
await Promise.resolve()
349349
})
350350

351+
it('MockTest handles node 24 tasks correctly', async function () {
352+
this.timeout(30000);
353+
const runner = await (new mtm.MockTestRunner).LoadAsync(path.join(__dirname, 'fakeTasks', 'node24task', 'entry.js'));
354+
const nodePath = runner.nodePath;
355+
assert(nodePath, 'node path should have been correctly set');
356+
const version = ncp.execSync(nodePath + ' -v').toString().trim();
357+
assert(semver.satisfies(version, '24.x'), 'Downloaded node version should be Node 24 instead of ' + version);
358+
await Promise.resolve()
359+
})
360+
351361
it('MockTest handles node tasks correctly by async call', async () => {
352362
this.timeout(30000);
353363
const runner = await (new mtm.MockTestRunner).LoadAsync(path.join(__dirname, 'fakeTasks', 'node16task', 'entry.js'));

tasks.schema.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,9 @@
394394
"additionalProperties": false,
395395
"description": "Execution options for this task (on Pre-Job stage)",
396396
"properties": {
397+
"Node24": {
398+
"$ref": "#/definitions/executionObject"
399+
},
397400
"Node20_1": {
398401
"$ref": "#/definitions/executionObject"
399402
},
@@ -419,6 +422,9 @@
419422
"additionalProperties": false,
420423
"description": "Execution options for this task",
421424
"properties": {
425+
"Node24": {
426+
"$ref": "#/definitions/executionObject"
427+
},
422428
"Node20_1": {
423429
"$ref": "#/definitions/executionObject"
424430
},
@@ -444,6 +450,9 @@
444450
"additionalProperties": false,
445451
"description": "Execution options for this task (on Post-Job stage)",
446452
"properties": {
453+
"Node24": {
454+
"$ref": "#/definitions/executionObject"
455+
},
447456
"Node20_1": {
448457
"$ref": "#/definitions/executionObject"
449458
},

0 commit comments

Comments
 (0)