create-test-run-plugin.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /**
  2. * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
  3. * SPDX-License-Identifier: MIT
  4. */
  5. import { definePluginCreator } from '@flowgram.ai/core';
  6. import { TestRunFormEntity, TestRunFormFactory, TestRunFormManager } from './services/form';
  7. import {
  8. TestRunService,
  9. TestRunPipelineEntity,
  10. TestRunPipelineFactory,
  11. TestRunConfig,
  12. defineConfig,
  13. } from './services';
  14. export const createTestRunPlugin = definePluginCreator<Partial<TestRunConfig>>({
  15. onBind: ({ bind }, opt) => {
  16. /** service */
  17. bind(TestRunService).toSelf().inSingletonScope();
  18. /** config */
  19. bind(TestRunConfig).toConstantValue(defineConfig(opt));
  20. /** form manager */
  21. bind(TestRunFormManager).toSelf().inSingletonScope();
  22. /** form entity */
  23. bind<TestRunFormFactory>(TestRunFormFactory).toFactory<TestRunFormEntity>((context) => () => {
  24. const e = context.container.resolve(TestRunFormEntity);
  25. return e;
  26. });
  27. /** pipeline entity */
  28. bind<TestRunPipelineFactory>(TestRunPipelineFactory).toFactory<TestRunPipelineEntity>(
  29. (context) => () => {
  30. const e = context.container.resolve(TestRunPipelineEntity);
  31. e.container = context.container.createChild();
  32. return e;
  33. }
  34. );
  35. },
  36. });