SchematicTestRunner: ability to run scheduled tasks

Đang mở
#11,739 0 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
typescript
Lĩnh vực
testing, tooling

Hướng nghiên cứu

Bắt đầu với phần triển khai SchematicTestRunner và đường đi lập lịch tác vụ xung quanh context.addTask và runner.engine.executePostTasks(); kiểm tra cách RunSchematicTask sử dụng quy trình làm việc của engine. Hoàn tất có nghĩa là các bài kiểm thử có thể chỉ thực thi các tác vụ đã được lập lịch với một tên được chọn, hoặc RunSchematicTask hoạt động trong SchematicTestRunner, với độ bao phủ cho hành vi được hỗ trợ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

area: @angular-devkit/schematics feature

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

Ngôn ngữ chính
TypeScript
Star
27k
Fork
11.8k
Merge trung bình
16 giờ 35 phút
Pull request đã merge (30 ngày)
176

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của angular/angular-cli

Tất cả issue của angular/angular-cli

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.