Skip to content

Commit 2837596

Browse files
committed
test(project): Update TaskRunner tests
1 parent a9b68df commit 2837596

2 files changed

Lines changed: 414 additions & 302 deletions

File tree

packages/project/lib/build/TaskRunner.js

Lines changed: 109 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@ import {createReaderCollection, createMonitor} from "@ui5/fs/resourceFactory";
55
/**
66
* TaskRunner
77
*
8-
* @private
8+
* Manages the execution of build tasks for a project, including task composition,
9+
* dependency management, and custom task integration.
10+
*
911
* @hideconstructor
1012
*/
1113
class TaskRunner {
1214
/**
1315
* Constructor
1416
*
15-
* @param {object} parameters
16-
* @param {object} parameters.graph
17-
* @param {object} parameters.project
17+
* @param {object} parameters Parameters
18+
* @param {@ui5/project/graph/ProjectGraph} parameters.graph Project graph instance
19+
* @param {@ui5/project/specifications/Project} parameters.project Project instance
1820
* @param {@ui5/logger/loggers/ProjectBuild} parameters.log Logger to use
1921
* @param {@ui5/project/build/cache/ProjectBuildCache} parameters.buildCache Build cache instance
2022
* @param {@ui5/project/build/helpers/TaskUtil} parameters.taskUtil TaskUtil instance
@@ -37,6 +39,16 @@ class TaskRunner {
3739
this._directDependencies = new Set(this._taskUtil.getDependencies());
3840
}
3941

42+
/**
43+
* Initializes the task list based on the project type
44+
*
45+
* This method:
46+
* 1. Loads the appropriate build definition for the project type
47+
* 2. Adds all standard tasks from the definition
48+
* 3. Adds any custom tasks configured for the project
49+
*
50+
* @returns {Promise<void>}
51+
*/
4052
async _initTasks() {
4153
if (this._tasks) {
4254
return;
@@ -84,10 +96,18 @@ class TaskRunner {
8496
}
8597

8698
/**
87-
* Takes a list of tasks which should be executed from the available task list of the current builder
99+
* Executes all configured tasks for the project
88100
*
89-
* @param {AbortSignal} [signal] Abort signal
90-
* @returns {Promise<string[]>} Resolves with list of changed resources since the last build
101+
* This method:
102+
* 1. Initializes the task list if not already done
103+
* 2. Ensures dependency reader is ready
104+
* 3. Composes the final list of tasks to execute based on build configuration
105+
* 4. Executes each task in order, respecting cache and abort signals
106+
* 5. Returns the list of changed resources after all tasks complete
107+
*
108+
* @public
109+
* @param {AbortSignal} [signal] Abort signal to cancel task execution
110+
* @returns {Promise<string[]>} Array of changed resource paths since the last build
91111
*/
92112
async runTasks(signal) {
93113
await this._initTasks();
@@ -125,10 +145,15 @@ class TaskRunner {
125145
}
126146

127147
/**
128-
* First compiles a list of all tasks that will be executed, then a list of all direct project
129-
* dependencies that those tasks require access to.
148+
* Determines which project dependencies are required by the tasks that will be executed
149+
*
150+
* This method:
151+
* 1. Initializes the task list if needed
152+
* 2. Composes the list of tasks that will be executed
153+
* 3. Collects all dependencies required by those tasks
130154
*
131-
* @returns {Set<string>} Returns a set containing the names of all required direct project dependencies
155+
* @public
156+
* @returns {Promise<Set<string>>} Set containing the names of all required direct project dependencies
132157
*/
133158
async getRequiredDependencies() {
134159
if (this._requiredDependencies) {
@@ -163,14 +188,19 @@ class TaskRunner {
163188
/**
164189
* Adds an executable task to the builder
165190
*
166-
* The order this function is being called defines the build order. FIFO.
191+
* The order this function is called defines the build order (FIFO).
192+
* Tasks can be explicitly skipped by setting taskFunction to null.
167193
*
168-
* @param {string} taskName Name of the task which should be in the list availableTasks.
169-
* @param {object} [parameters]
170-
* @param {boolean} [parameters.requiresDependencies]
171-
* @param {boolean} [parameters.supportsDifferentialUpdates]
172-
* @param {object} [parameters.options]
173-
* @param {Function} [parameters.taskFunction]
194+
* @param {string} taskName Name of the task to add
195+
* @param {object} [parameters] Task parameters
196+
* @param {boolean} [parameters.requiresDependencies=false]
197+
* Whether the task requires access to project dependencies
198+
* @param {boolean} [parameters.supportsDifferentialUpdates=false]
199+
* Whether the task supports differential updates using cache
200+
* @param {object} [parameters.options={}] Options to pass to the task
201+
* @param {Function|null} [parameters.taskFunction]
202+
* Task function to execute, or null to explicitly skip the task
203+
* @returns {void}
174204
*/
175205
_addTask(taskName, {
176206
requiresDependencies = false, supportsDifferentialUpdates = false, options = {}, taskFunction
@@ -243,8 +273,11 @@ class TaskRunner {
243273
}
244274

245275
/**
276+
* Adds all custom tasks configured for the project
277+
*
278+
* Processes custom tasks in the order they are defined in the project configuration.
246279
*
247-
* @private
280+
* @returns {Promise<void>}
248281
*/
249282
async _addCustomTasks() {
250283
const projectCustomTasks = this._project.getCustomTasks();
@@ -257,10 +290,21 @@ class TaskRunner {
257290
}
258291
}
259292
/**
260-
* Adds custom tasks to execute
293+
* Adds a single custom task to the task execution order
261294
*
262-
* @private
263-
* @param {object} taskDef
295+
* This method:
296+
* 1. Validates the custom task definition
297+
* 2. Loads the task extension from the project graph
298+
* 3. Determines required dependencies via callback if provided
299+
* 4. Creates a wrapper function for the custom task
300+
* 5. Inserts the task at the correct position based on beforeTask/afterTask configuration
301+
*
302+
* @param {object} taskDef Custom task definition from project configuration
303+
* @param {string} taskDef.name Name of the custom task
304+
* @param {string} [taskDef.beforeTask] Name of task to insert before
305+
* @param {string} [taskDef.afterTask] Name of task to insert after
306+
* @param {object} [taskDef.configuration] Custom task configuration
307+
* @returns {Promise<void>}
264308
*/
265309
async _addCustomTask(taskDef) {
266310
const project = this._project;
@@ -418,6 +462,30 @@ class TaskRunner {
418462
}
419463
}
420464

465+
/**
466+
* Creates a wrapper function for executing a custom task
467+
*
468+
* The wrapper:
469+
* 1. Validates cache and determines if task can be skipped
470+
* 2. Prepares workspace and dependencies readers
471+
* 3. Builds the parameter object for the custom task interface
472+
* 4. Executes the custom task function
473+
* 5. Records the task result in the build cache
474+
*
475+
* @param {object} parameters Parameters
476+
* @param {@ui5/project/specifications/Project} parameters.project Project instance
477+
* @param {@ui5/project/build/helpers/TaskUtil} parameters.taskUtil TaskUtil instance
478+
* @param {Function} parameters.getDependenciesReaderCb
479+
* Callback to get dependencies reader on-demand
480+
* @param {boolean} parameters.provideDependenciesReader
481+
* Whether to provide dependencies reader to the task
482+
* @param {boolean} parameters.supportsDifferentialUpdates
483+
* Whether the task supports differential updates
484+
* @param {@ui5/project/specifications/Extension} parameters.task Task extension instance
485+
* @param {string} parameters.taskName Runtime name of the task (may include suffix)
486+
* @param {object} [parameters.taskConfiguration] Task configuration from ui5.yaml
487+
* @returns {Function} Async wrapper function for the custom task
488+
*/
421489
_createCustomTaskWrapper({
422490
project, taskUtil, getDependenciesReaderCb, provideDependenciesReader, supportsDifferentialUpdates,
423491
task, taskName, taskConfiguration
@@ -497,13 +565,14 @@ class TaskRunner {
497565
}
498566

499567
/**
500-
* Adds progress related functionality to task function.
568+
* Executes a task function with performance tracking
569+
*
570+
* Wraps task execution with performance measurements and logging.
501571
*
502-
* @private
503572
* @param {string} taskName Name of the task
504-
* @param {Function} taskFunction Function which executed the task
573+
* @param {Function} taskFunction Function which executes the task
505574
* @param {object} taskParams Base parameters for all tasks
506-
* @returns {Promise} Resolves when task has finished
575+
* @returns {Promise<void>} Resolves when task has finished
507576
*/
508577
async _executeTask(taskName, taskFunction, taskParams) {
509578
this._taskStart = performance.now();
@@ -515,8 +584,22 @@ class TaskRunner {
515584
}
516585
}
517586

587+
/**
588+
* Creates a reader collection for the specified project dependencies
589+
*
590+
* This method:
591+
* 1. Returns a cached reader if all direct dependencies are requested and available
592+
* 2. Resolves transitive dependencies for the requested dependency names
593+
* 3. Creates a reader collection containing readers for all required dependencies
594+
* 4. Caches the reader if it covers all direct dependencies
595+
*
596+
* @public
597+
* @param {Set<string>} dependencyNames Set of dependency project names to include
598+
* @param {boolean} [forceUpdate=false] Force creation of a new reader even if cached
599+
* @returns {Promise<@ui5/fs/ReaderCollection>} Reader collection for the requested dependencies
600+
*/
518601
async getDependenciesReader(dependencyNames, forceUpdate = false) {
519-
if (!forceUpdate && dependencyNames.size === this._directDependencies.size) {
602+
if (!forceUpdate && dependencyNames.size === this._directDependencies.size && this._cachedDependenciesReader) {
520603
// Shortcut: If all direct dependencies are required, just return the already created reader
521604
return this._cachedDependenciesReader;
522605
}

0 commit comments

Comments
 (0)