0

我有一个 NX 工作区,其中有一个名为my-app. 我想my-app使用 NX 控制台为应用程序运行 Playwright 测试。目前 NX 不支持 Playwright 插件,所以我根据本教程创建了一个自定义的 NX 执行器。我已经为执行者创建了必要的文件。project.json之后,我在应用程序文件中注册了自定义 e2e 命令。playwright 配置文件保留在该my-app文件夹中。

当我运行nx run my-app:e2e时,执行程序被执行,但是由于某种原因,剧作家没有启动。相反,我看到了一个错误。

在此处输入图像描述

当我在控制台中手动运行时,由剧作家触发的命令nx run my-app:e2e启动npx playwright test --config=apps/my-app/playwright.config.ts并进行必要的测试。

项目.json

...
...
...
"e2e": {
  "executor": "./tools/executors/playwright:playwright",
  "options": {
    "path": "apps/my-app/playwright.config.ts"
  }
}

执行器.json

{
  "executors": {
    "playwright": {
      "implementation": "./impl",
      "schema": "./schema.json",
      "description": "Runs Playwright Test "
    }
  }
}

impl.ts

export default async function echoExecutor(
  options: PlaywrightExecutorOptions,
  context: ExecutorContext
) {
  console.info(`Executing "Playwright"...`);
  console.info(`Options: ${JSON.stringify(options, null, 2)}`);

  const { stdout, stderr } = await promisify(exec)(
    `npx playwright test --config=${options.path}`,
  );
  console.log(stdout);
  console.error(stderr);

  const success = !stderr;
  return { success };
}

模式.json

{
  "$schema": "http://json-schema.org/schema",
  "type": "object",
  "cli": "nx",
  "properties": {
    "path": {
      "type": "string",
      "description": "Path to the project"
    }
  }
}

包.json

{
  "executors": "./executor.json"
}

我不确定,但也许问题出在promisify?我正试着npx用它打电话。也许在这种情况下有不同的调用方式npx

  const { stdout, stderr } = await promisify(exec)(
    `npx playwright test --config=${options.path}`,
  );
4

0 回答 0