amazon-web-services - TestCafe 与 SAM Local 一起工作,但在 SAM Deploy 之后不工作

标签 amazon-web-services testing aws-lambda puppeteer testcafe

我目前正在尝试设置一个应该执行简单 TestCafe 测试的 AWS Lambda (nodejs10.x) 函数。

如果我使用 sam local invoke --no-event 在本地运行我的 Lambda,它执行得很好:

2019-12-03T13:39:46.345Z 7b906b79-d7e5-1aa6-edb7-3e749d4e4b08
INFO hello world ✓ My first test 1 passed (1s) 2019-12-03T13:39:46.578Z 7b906b79-d7e5-1aa6-edb7-3e749d4e4b08
INFO Tests failed: 0

在我使用 sam buildsam deploy 部署它后,它停止工作。它只会在 AWS 中抛出以下错误:

{
  "errorType": "Runtime.UnhandledPromiseRejection",
  "errorMessage": "Error: Page crashed!",
  "trace": [
    "Runtime.UnhandledPromiseRejection: Error: Page crashed!",
    "    at process.on (/var/runtime/index.js:37:15)",
    "    at process.emit (events.js:203:15)",
    "    at process.EventEmitter.emit (domain.js:448:20)",
    "    at emitPromiseRejectionWarnings (internal/process/promises.js:140:18)",
    "    at process._tickCallback (internal/process/next_tick.js:69:34)"
  ]
}

我的 lambda 处理程序如下所示:

const createTestCafe = require("testcafe");
const chromium = require("chrome-aws-lambda");
let testcafe = null;

exports.lambdaHandler = async (event, context) => {
  const executablePath = await chromium.executablePath;

  await createTestCafe()
    .then(tc => {
      testcafe = tc;
      const runner = testcafe.createRunner();

      return runner
        .src("sample-fixture.js")
        .browsers(
          "puppeteer-core:launch?arg=--no-sandbox&arg=--disable-gpu&arg=--disable-setuid-sandbox&path=" + executablePath
        )
        .run({
          skipJsErrors: true,
          selectorTimeout: 50000
        });
    })
    .then(failedCount => {
      console.log("Tests failed: " + failedCount);
      testcafe.close();
    });

  return {
    statusCode: 200
  };
};

我的 sample-fixture.js 看起来像这样:

fixture `Getting Started`
    .page `http://devexpress.github.io/testcafe/example`;

test('My first test', async t => {
  console.log('hello world');
});

我正在使用以下依赖项:

  • "testcafe": "^1.7.0"

  • "chrome-aws-lambda": "^2.0.1"

  • "testcafe-browser-provider-puppeteer-core": "^1.1.0"

有人知道为什么我的 Lambda 函数可以在我的机器上本地运行,但不能在 AWS 上运行吗?

最佳答案

我目前不能仅根据这些信息说出任何准确的信息。 我建议您尝试以下操作:

关于amazon-web-services - TestCafe 与 SAM Local 一起工作,但在 SAM Deploy 之后不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59158717/

相关文章:

python - 如何在 Python 中本地部署 Amazon-SageMaker

amazon-web-services - 我应该如何处理 Terraform 中的 `deposed` 资源?

javascript - Jasmine - 如何模拟 history.pushState 和假事件发射?

aws-lambda - 从 Cognito 触发器发送消息

amazon-web-services - Amazon SQS FIFO 队列

java - 一个亚马逊请求可以发送多少件商品?

c# - 在 Visual Studio 2012 中保存测试

ruby-on-rails - 一个简单的factory_girl问题

javascript - AWS Lambda JS 上出现意外解析错误

python - AWS Lambda 中 Python 全局变量的范围