首页 > 解决方案 > AWS Amplify Deploy(构建和测试)React JS + Jest + Enzyme

问题描述

我在 AWS Amplify 上部署了一个 React JS 项目,一切正常。但是我有一些测试脚本,我想在 Amplify 在每次部署时部署一个新版本之前运行它们。问题是当我更改为amplify.yml在构建代码之前尝试运行我的测试脚本时,它现在不再完成构建(无限加载而没有完成构建和部署)。

amplify.yml更改前:

version: 1
applications:
  - frontend:
      phases:
        preBuild:
          commands:
            - npm ci
        build:
          commands:
            - npm run build
      artifacts:
        baseDirectory: build
        files:
          - '**/*'
      cache:
        paths:
          - node_modules/**/*
    appRoot: burger-builder

amplify.yml更改后:

version: 1
applications:
  - frontend:
      phases:
        preBuild:
          commands:
            - npm ci
        build:
          commands:
            - npm run build
      artifacts:
        baseDirectory: build
        files:
          - '**/*'
      cache:
        paths:
          - node_modules/**/*
  - test:
      phases:
        preTest:
          commands:
            - npm ci
        test:
          commands:
            - npm run test
    appRoot: burger-builder

标签: reactjsamazon-web-servicesdeploymentjestjsaws-amplify

解决方案


By default, create-react-app runs your Jest tests in interactive mode. To understand what that means, run npm run test in your terminal and note that you'll have to change some code or hit 'a' to actually run your tests. You don't want this behavior in your Amplify deploy process. In the amplify.yml file, run your tests in non-interactive mode with npm test -- --watchAll=false. Or with yarn, yarn test --watchAll=false.


推荐阅读