GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — SchematicTestRunner: ability to run scheduled tasks · Issue #11739 · angular/angular-cli

SchematicTestRunner: ability to run scheduled tasks #11739

New issue
Copy link
New issue
Copy link
Open
Enhancement
Open
SchematicTestRunner: ability to run scheduled tasks#11739
Enhancement
Copy link
Labels
area: @angular-devkit/schematicsfeatureLabel used to distinguish feature request from other issuesLabel used to distinguish feature request from other issues
Milestone
Backlog

Description

@devversion
devversion
opened on Aug 1, 2018
Issue body actions

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.
 */
export function runPostScheduledTasks(runner: SchematicTestRunner, taskName: string) {

  const host = runner.engine['_host'] as EngineHost<{}, {}>;
  const tasks = runner.engine['_taskSchedulers'] as TaskScheduler[];

  return observableFrom(tasks).pipe(
    concatMap(scheduler => scheduler.finalize()),
    filter(task => task.configuration.name === taskName),
    concatMap(task => {
      return host.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()
  );
}

cc. @jelbourn @hansl

Reacted by daiscog

Activity

  1. hansl
    added
    area: @angular-devkit/schematics
    on Aug 1, 2018
  2. jelbourn
    added
    hotlist: angular material
    on Aug 1, 2018
  3. Brocco
    added
    featureLabel used to distinguish feature request from other issuesLabel used to distinguish feature request from other issues
    on Aug 2, 2018
  4. ngbot
    added this to the Backlog milestone on Jan 24, 2019
  5. clydin
    added
    triage #1
    on May 27, 2020
  6. alan-agius4
    removed
    triage #1
    on Jun 24, 2022
  7. alan-agius4
    removed
    hotlist: angular material
    on Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: @angular-devkit/schematicsfeatureLabel used to distinguish feature request from other issuesLabel used to distinguish feature request from other issues

    Type

    Enhancement

    Projects

    No projects

      Milestone

      • BacklogNo due date

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.