This package contains automated tests for validating functionality E2E in Node.
- All tests within
nodeshare a single "long-lived" Amplify backend (added to the shared Cypress account). - Sample will use
amplify-js@unstableand local versions of packages in this repo. - See test utils for helpers that configure Amplify, generate / configure the API client, as well as for additional test utilities and types.
- Create a new file under
__tests__ - Use the helpers to configure Amplify and generate / configure the API client.
- To install dependencies / run the tests, either use the
e2escripts at the root of the monorepo, or the scripts in thee2e-testspackage. Both will ensure that apackage-lockfile is not generated for this sample. - [TODO] subscription testing (will be added with follow-up PR)
Add a check to clean up potential orphaned records after all tests have run (see https://jestjs.io/docs/configuration#globalteardown-string).
Tests that use Hub currently emit the following warning when running the tests:
A worker process has failed to exit gracefully and has been force exited. This is likely caused by tests leaking due to improper teardown. Try running with --detectOpenHandles to find leaks. Active timers can also cause this, ensure that .unref() was called on them.The problem seems to be related to Amplify Core's detectFramework function, and
is likely due to the fact that we are running the tests in Node (which is not
officially supported by amplify-js).
TODO: Investigate and/or fix.
All tests within the sandbox directory deploy a new sandbox for each test run.
CLI commands are managed by the process controller. The process controller is responsible for executing CLI commands, and listening for output from the CLI. Test setup / execution is structured as follows:
- Each test has a corresponding project directory with a particular backend
config in
amplify-backends - Sandbox is deployed within the corresponding project directory, generating
amplify_outputs.json. - Once it is determined that
amplify_outputs.jsonis generated, we configure Amplify and generate / configure the API client. - Tests are executed.
- Sandbox is torn down after the tests are complete.
.amplify/andamplify_outputs.jsonare deleted.
We follow the recommended OS approach to get AWS account credentials: https://w.amazon.com/bin/view/Open_Source/GitHub/Actions. Specifically, we use the aws-actions/configure-aws-credentials GH Action to obtain credentials from the IAM OIDC provider.
Currently, the trust policy for the OIDC provider is set to only allow execution
of the main branch on amplify-data, since this branch contains appropriate
restrictions to limit E2E runs (test runs only occur when an approved PR has
been merged to main).
If we want to extend this policy to allow us to run tests on other branches, we
could update the Trust Relationship configuration of the IAM role to be
restricted to a repository environment, instead.
To view identify provider details in the console, see: Console > IAM > Identity Providers
- https://w.amazon.com/bin/view/Open_Source/GitHub/Actions
- https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services
- https://github.com/aws-actions/configure-aws-credentials
- Add a new project directory under
amplify-backends. Must also contain a basicpackage.json. - Add a corresponding test file under
__tests__. - Use the utils to generate / teardown the sandbox withthe process controller.
Execa is the primary dependency used to run CLI commands in the process
controller, and it is a pure ES module. Unlike amplify-backend, which uses the
Node test runner, our tests are written in Jest. This results in this issue.
The workaround is to use Jest's experimental support for ECMAScript Modules. There is a backlog item to investigate other potential solutions.
This is the general guidance for testing module bundlers. When testing other tools in the future, please adapt these guidelines accordingly and update this file.
- Add a sample in this directory following the structure
e2e-tests/<framework>. - Add configs for your test to the local-integ-all.yml file.
- Create a script command for your test and call it from callable-local-e2e-test.
- Update the e2e test coverage for
amplify-datarepo in e2e test coverage table.