You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If someone uses the SchematicTestRunner and runs a schematic that schedules specific tasks using the context.addTask method, those tasks cannot be run in the tests.
I figured that there is a method (runner.engine.executePostTasks() that runs all scheduled tasks. This is not really helpful though, since there are situations where we only want to run specific tasks and not all scheduled tasks.
This is because some tasks like RunSchematicTask depend on a engine.workflow that is not set up in the SchematicTestRunner. It would be either nice if the RunSchematicTask could work properly in the tests, or there is a method that runs tasks with a specific name.
Current workaround:
/** * Due to the fact that the Angular devkit does not support running scheduled tasks from a * schematic that has been launched through the TestRunner, we need to manually find the task * executor for the given task name and run all scheduled instances. * * Note that this means that there can be multiple tasks with the same name. The observable emits * only when all tasks finished executing. */exportfunctionrunPostScheduledTasks(runner: SchematicTestRunner,taskName: string){consthost=runner.engine['_host']asEngineHost<{},{}>;consttasks=runner.engine['_taskSchedulers']asTaskScheduler[];returnobservableFrom(tasks).pipe(concatMap(scheduler=>scheduler.finalize()),filter(task=>task.configuration.name===taskName),concatMap(task=>{returnhost.createTaskExecutor(task.configuration.name).pipe(concatMap(executor=>executor(task.configuration.options,task.context)));}),// Only emit the last emitted value because there can be multiple tasks with the same name.// The observable should only emit a value if all tasks completed.last());}
If someone uses the
SchematicTestRunner
and runs a schematic that schedules specific tasks using thecontext.addTask
method, those tasks cannot be run in the tests.I figured that there is a method (
runner.engine.executePostTasks()
that runs all scheduled tasks. This is not really helpful though, since there are situations where we only want to run specific tasks and not all scheduled tasks.This is because some tasks like
RunSchematicTask
depend on aengine.workflow
that is not set up in theSchematicTestRunner
. It would be either nice if theRunSchematicTask
could work properly in the tests, or there is a method that runs tasks with a specific name.Current workaround:
cc. @jelbourn @hansl
The text was updated successfully, but these errors were encountered: