Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to run functional tests in build script? #39

Closed
janhesters opened this issue Aug 8, 2019 · 9 comments
Closed

How to run functional tests in build script? #39

janhesters opened this issue Aug 8, 2019 · 9 comments
Labels
archived This issue has been locked. question Further information is requested

Comments

@janhesters
Copy link

janhesters commented Aug 8, 2019

** Please describe which feature you have a question about? **
I'm trying to run functional tests with TestCafe when building. Here are my build settings:

version: 0.1
frontend:
  phases:
    preBuild:
      commands:
        - yarn install
        - yarn validate
    build:
      commands:
        - yarn run build
  artifacts:
    baseDirectory: build
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*

And here is how the "validate" script looks like:

"validate": "yarn -s unit-tests && yarn -s lint && yarn -s functional-tests",
"functional-tests": "testcafe 'chrome:headless' src/functional-tests/",

But this throws the error:

2019-08-08T15:36:17.385Z [WARNING]: ERROR Unable to find the browser. "chrome:headless" is not a browser alias or path to an executable file.

How can I add Chrome to the Amplify console, or run functional tests with it?

** Provide additional details**

@swaminator swaminator added 4 question Further information is requested labels Aug 8, 2019
@garyleefight
Copy link

@janhesters You have to install the missing dependency yourself. You can add commands to install chrome dependencies in prebuild.

@janhesters
Copy link
Author

janhesters commented Aug 8, 2019

@garyleefight Do you know which dependencies and how to install them exactly?

I can't find how to install chrome for the Amplify console. I only found this, which tackles docker. And these Google docs are for Travis CI. As far as I can tell, there is no addons key for the Amplify build settings.

@garyleefight
Copy link

@janhesters
Copy link
Author

@garyleefight Thank you for your help. Managed to solve the install problem by adding

- wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
- yum install -y ./google-chrome-stable_current_*.rpm

to my build settings.

My question is now: How can I run yarn start so that the tests can pass? Currently the functional tests run, but fail, because no server is running.

@garyleefight
Copy link

@janhesters You can use https://stackoverflow.com/questions/30950032/how-can-i-run-multiple-npm-scripts-in-parallel concurrently package to run yarn start and your test command in parallel.
It will kill yarn start when your test commands finished. But the exit code is 1, which is considered build failure in our console.
You can read this post to get rid of exit code 1.
https://github.com/kimmobrunfeldt/concurrently/issues/127

Hope it works for you.

Besides, AWS Amplify Console baked Cypress test in the default image. You can choose it as an alternative selection.

Thanks,
Gary

@janhesters
Copy link
Author

@garyleefight

You can use https://stackoverflow.com/questions/30950032/how-can-i-run-multiple-npm-scripts-in-parallel concurrently package to run yarn start and your test command in parallel.
It will kill yarn start when your test commands finished. But the exit code is 1, which is considered build failure in our console.
You can read this post to get rid of exit code 1.
kimmobrunfeldt/concurrently#127

Thank you I will try concurrently.

I also found the --app flag for TestCafe which does exactly what I want (= run yarn start when the test starts, and terminate the app afterwards). But, for some reason if I test in headless mode in the console or locally, the tests fail. I created a SO question here.

Besides, AWS Amplify Console baked Cypress test in the default image. You can choose it as an alternative selection.

Really? I didn't know that and could'n find anything in the docs about this. Do Cypress tests "just work"? Or is there extra configuration needed.

@janhesters
Copy link
Author

janhesters commented Aug 9, 2019

I got it working by adding a delay to launch the app.

"functional-tests": "testcafe 'chrome:headless' src/functional-tests/ --app 'yarn start' --app-init-delay 4000",

@rudyhadoux
Copy link

@janhesters Do you know the npm lib start-server-and-test (no need to add delay) ?
I achieve same tests with
start-server-and-test angular-http-server --path ./dist/site -p 4200 http://localhost:4200 testcafe chrome:headless ./testcafe/test.js

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot added the archived This issue has been locked. label Oct 28, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Oct 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived This issue has been locked. question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants