简体   繁体   English

AWS Amplify Deploy(构建和测试)React JS + Jest + Enzyme

[英]AWS Amplify Deploy (Build & Test) React JS + Jest + Enzyme

I've deployed a React JS project on AWS Amplify and everything ran ok.我在 AWS Amplify 上部署了一个 React JS 项目,一切正常。 But I have some test scripts that I would like to run before Amplify deploy a new build at every deploy.但是我有一些测试脚本,我想在 Amplify 在每次部署时部署一个新版本之前运行它们。 The problem is when I changed the amplify.yml to try running my test scripts before building the code now it doesn't finish building anymore (loading indefinetily without finishing building & deploy).问题是当我更改amplify.yml以尝试在构建代码之前运行我的测试脚本时,它现在不再完成构建(无限加载而没有完成构建和部署)。

amplify.yml before changes:更改前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 after changes:更改后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

By default, create-react-app runs your Jest tests in interactive mode.默认情况下, create-react-app以交互模式运行您的 Jest 测试。 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.要了解这意味着什么,请在终端中运行npm run test ,并注意您必须更改一些代码或点击“a”才能实际运行测试。 You don't want this behavior in your Amplify deploy process.您不希望在 Amplify 部署过程中出现这种行为。 In the amplify.yml file, run your tests in non-interactive mode with npm test -- --watchAll=false .在 amplify.yml 文件中,使用npm test -- --watchAll=false在非交互模式下运行测试。 Or with yarn, yarn test --watchAll=false .或者使用纱线, yarn test --watchAll=false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM