Amplify React App Stuck Running Tests and Never Deploys - reactjs

I feel like I'm missing something simple but I can't find anything on the web on what I'm doing wrong. Here's my yml file
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm test --watchAll=false && npm run build
artifacts:
baseDirectory: build
files:
- '**/*'
cache:
paths:
- node_modules/**/*
It's basically the default but I want tests (and eventual a coverage report) to run before moving on to the next step. Currently it just sits there after spitting out: "No tests found related to files changed since last commit."
I want all tests to run every single time and for the deployment to complete. What am I doing wrong?

I change my tests to this:
npm test -- --coverage --watchAll=false
Now the tests run and everything continues as normal.

Related

Build Failed - Non-Zero Exit Code Detected after 'npm build' in AWS Amplify

I am linked my AWS Amplify app to a new React Gatsby GitHub repo for continuous deployment. The app compiles fine locally, but I am getting an error in the 'Frontend' during the AWS build, saying that the amplify.sh file is 'killed' at the npm run build line, followed by 'Non-Zero Exit Code Detected' error. Below is a link to a screenshot of the error:
AWS Amplify Error
Below are the contents of my amplify.yml file in AWS:
version: 1
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run build
artifacts:
baseDirectory: public
files:
- '**/*'
cache:
paths:
- node_modules/**/*
Do I need to edit the amplify.yml file, or maybe add something to a package-lock or gatsby-node file?
Your script looks fine.
Would you be able to confirm that the IAM Role 'AWSAmplifyExecutionRole' has the AdministratorAccess permission? In order to do a CloudFormation deploy the role needs that permission in order to create all the resources in the stack.
OR
Please share the error log content, if possible.
I was able to solve this by running npm install (locally) and push to the branch. The error was invalid package-lock file version.
This was the step suggested in the build fail log.

React source code exposed in AWS amplify deployment

I am testing deployment of an app on AWS amplify. These are the steps I followed:
created a sample create-react-app (called deploy_test app here),
Pushed the code to a GitHub repo
AWS Amplify console > Deploy app > linked GitHub repo > used default config (as shown below)
version: 1
frontend:
phases:
preBuild:
commands:
- yarn install
build:
commands:
- yarn run build
artifacts:
baseDirectory: build
files:
- '**/*'
cache:
paths:
- node_modules/**/*
The deployment works beautifully, even when I push new changes. The issue is that I can see the entire source code in the Chrome Dev Tools (as shown below). Any tips on how I can resolve this?
by default, create-react-app will generate full sourcemaps:
A build script to bundle JS, CSS, and images for production, with hashes and sourcemaps.
https://github.com/facebook/create-react-app#whats-included
you can set GENERATE_SOURCEMAP=false before the build script:
build:
commands:
- GENERATE_SOURCEMAP=false yarn run build
you can see it defined in the source code of create-react-app webpack config:
https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/config/webpack.config.js#L43-L46

Create React App - Can't run npm run test

I've had to eject my Create React App and now I can run my tests but the watch is completely broken.
If my tests fail or pass they do not carry on watching and I get the below error instead.
Error watching file for changes: EMFILE
Failed at the portfolio#0.1.0 test script 'node scripts/test.js --env=jsdom'.
I get this error when running npm run test
I've tried installing watchman to see if this made a difference with no success.
another thing that I've tried is adding the below line to my package.json file:
"setupTestFrameworkScriptFile": "<rootDir>/src/setupTests.js",
I feel like someone else might get this issue so I'm going to say how I fixed it.
It turns out that I need to run the below commands and your tests will be watching test files again.
rm -rf ./node_modules
npm cache clean
npm install
I must of been out of sync or something.. Such a simple thing to do to fix a really annoying problem.

npm test does not detect new test file changes in jenkins

Jenkins/jest and CI ,
I have created a react APP using create-react-app and I use JEST for testing and I did some new changes in a file created app.test.js and committed to git-hub- hooked it with jenkins -when I run npm test in the local machine the tests are run fine and they all pass ..
BUT when i run the jenkins pipeline script it says the following :
No tests found related to files changed since last commit.
Press a to run all tests, or run Jest with --watchAll.
Watch Usage
› Press a to run all tests.
› Press p to filter by a filename regex pattern.
› Press q to quit watch mode.
› Press Enter to trigger a test run.
I have tried changing app.test.js -created a new file commit changes and then created a new pipeline in jenkins and tried again ( I have also tried these discussed here :https://github.com/facebookincubator/create-react-app/issues/930) but I still get the above error : my pipeline script is shown below:
node{
stage "CI"
git 'https://github.com/NaveenDK/mentalshortcuts.git'
bat "npm install"
stage " Unit testing"
bat "npm test"
}
def notify(status){
emailext (
to: "dd#dd.com",
subject: "${status}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
body: """<p>${status}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
<p>Check console output at <a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a></p>""",
)
}
node {
notify("Deploy to staging?")
}
input 'Deploy to Staging?'
node {
bat "npm run-script build"
}
Any help any links anything at all would be great!
The tests did not run on jenkins as Jenkins was running on Windows, and Windows doesn't support glob, which is src/**/*.js.
this problem was not encountered when the project was build on Jenkins that was installed on a Linux OS!
I also faced the same issue. As mentioned above by Naveen, Windows doesn't support glob, which is src/**/*.js.
That's why in Jenkins configuration, change the label to Linux. Check here to see a preview.
Jenkins configuration
And then in the build section, add the following line as shell commands:
npm install
npm run build
CI=true npm test
Always run npm install first. It will install all the packages.
Then run npm run build to build the app
In the end, make sure to write CI=true npm test. It will run test cases only once. If you write npm test instead, then it will run the test and go into watch mode forever.
I hope this helps.
I encounter this problem on my local machine like this,
"test": "jest --watchAll"

yarn / npm bulld completes then hangs indefinitely

Anyone have any experience with this? Running yarn build completes the build but never exits the process, it just hangs... The same thing happens when i run npm run build
stars-app|master⚡ ⇒ yarn build
yarn build v0.27.5
$ react-scripts build
Creating an optimized production build...
Compiled successfully.
File sizes after gzip:
132.04 KB build/static/js/main.54f97667.js
24.93 KB build/static/css/main.43aab3e7.css
The project was built assuming it is hosted at the server root.
To override this, specify the homepage in your package.json.
For example, add this to build it for GitHub Pages:
"homepage" : "http://myname.github.io/myapp",
The build folder is ready to be deployed.
You may serve it with a static server:
yarn global add serve
serve -s build
Totally fine build, no errors. Yet the process never completes and just hangs... Ideas? There's nothing special about my package.json either. Also, building any other project completes fine so I know it's not my global yarn / npm packages... it is something with this particular project... Suggestions on how to even begin to troubleshoot this sort of thing?

Resources