-
Notifications
You must be signed in to change notification settings - Fork 156
chore: run e2e tests on demand #441
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
Changes from 31 commits
c3b427d
27bfa90
cd7b015
7015f64
d1acd31
b367d80
52a20d8
c0a4301
38fdb75
ea45fdf
bdf800f
e3a83ce
6db56fa
6046c08
08e8050
ff9a87f
13103b8
3a189ba
5fbdc66
f86e54f
065e538
29ed2e7
0cfb133
92f1183
e196ae1
9c1e339
33d87f7
19c10c4
f792e5c
ba91ab7
51677d8
9f9b6d6
d0f9736
530d50d
df4e51a
5ff1931
9d0daa8
1d22541
1e4c897
ee00ffc
57c3bb0
0de1d03
64304ce
4f62c1a
973a9d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ on: | |
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: "Checkout" | ||
uses: actions/checkout@v2 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: run-e2e-tests | ||
on: | ||
workflow_dispatch: {} | ||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
id-token: write # needed to interact with GitHub's OIDC Token endpoint. | ||
contents: read | ||
steps: | ||
- name: "Checkout" | ||
uses: actions/checkout@v2 | ||
######################### | ||
# Release new version | ||
######################### | ||
- name: "Use NodeJS 14" | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '14' | ||
- name: Install packages | ||
run: | | ||
npm ci | ||
npm run lerna-ci | ||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@master | ||
flochaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
with: | ||
role-to-assume: ${{ secrets.AWS_ROLE_ARN_TO_ASSUME }} | ||
aws-region: eu-west-1 | ||
- name: Run integration tests | ||
run: npm run lerna-test:e2e |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,81 @@ You can build and start a local docs website by running these two commands. | |
- `npm run docs-buildDockerImage` OR `docker build -t squidfunk/mkdocs-material ./docs/` | ||
- `npm run docs-runLocalDocker` OR `docker run --rm -it -p 8000:8000 -v ${PWD}:/docs squidfunk/mkdocs-material` | ||
|
||
### Tests | ||
|
||
Tests are under `tests` folder of each modules and split into two categories: unit tests and e2e tests. | ||
flochaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
You can run each group separately or all together thanks to [jest-runner-groups](https://www.npmjs.com/package/jest-runner-groups). | ||
|
||
Unit tests, under `tests/unit` folder are standard [Jest](https://jestjs.io) tests. | ||
|
||
End-to-end tests, under `tests/e2e` folder, will test the module features by deploying Lambdas functions into your AWS Account. We use CDK lib for Typescript for creating infrastructure, and `aws sdk` for invoking the functions and assert on the expected behaviors. All steps are also executed by Jest. | ||
flochaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Running end-to-end tests will deploy AWS resources. You will need an AWS account and the tests might incur costs. The cost from **some services** are covered by the [AWS Free Tier](https://aws.amazon.com/free/?all-free-tier.sort-by=item.additionalFields.SortRank&all-free-tier.sort-order=asc&awsf.Free%20Tier%20Types=*all&awsf.Free%20Tier%20Categories=*all) but not all of them. If you don't have an AWS Account follow [these instructions to create one](https://aws.amazon.com/premiumsupport/knowledge-center/create-and-activate-aws-account/). | ||
|
||
When contributing to this repository, these end-to-end tests are run by the maintainers before merging a PR. | ||
|
||
|
||
**Unit testing** | ||
flochaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
**Write** | ||
|
||
As mentioned before, tests are split into groups thanks to [jest-runner-groups](https://www.npmjs.com/package/jest-runner-groups) and therefore each test needs to be tagged properly by adding the following comments in the header of your unit test file: | ||
|
||
```typescript | ||
/** | ||
* Tests metrics | ||
* | ||
* @group unit/<YOUR CATEGORY>/<YOUR SUB CATEGORY> | ||
*/ | ||
``` | ||
|
||
**Run** | ||
flochaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
`npm run test` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency with the e2e test, can we change this command to be everywhere:
So that in the future we can (if we want or need):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: this is not much about the unique command, but more of a matter of naming consistency. |
||
|
||
You can run selective tests by restricting the group to the one you want. For instance `npx jest --group=unit/metrics/all`. | ||
|
||
**e2e tests** | ||
|
||
**Write** | ||
|
||
As mentioned in the previous section, tests are split into groups thanks to [jest-runner-groups](https://www.npmjs.com/package/jest-runner-groups) and therefore each test needs to be tagged properly by adding the following comments in the header of your unit test file: | ||
|
||
```typescript | ||
/** | ||
* Tests data lake catalog | ||
* | ||
* @group e2e/<YOUR CATEGORY>/<YOUR SUB CATEGORY> | ||
*/ | ||
``` | ||
|
||
and leverage `aws-cdk` package to programatically deploy and destroy stacks. See `metrics/tests/e2e/decorator.test.ts` as an example. | ||
flochaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
**Run** | ||
|
||
To run unit tests you can either use projen task | ||
* `npm run test:e2e` which will only run jest integ tests | ||
* or jest directly `npx jest --group=e2e` | ||
|
||
You can run selective tests by restricting the group to the one you want. For instance `npx jest --group=e2e/other/example`. | ||
|
||
Two important env variable can be used: | ||
saragerion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* `AWS_PROFILE` to use the right credentials | ||
* `DISABLE_TEARDOWN` if you don't want your stack to be destroyed at the end of the test (useful in dev mode when iterating over your code). | ||
|
||
Example: `DISABLE_TEARDOWN=true AWS_PROFILE=ara npx jest --group=integ/other/example` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: can we add a real example? |
||
|
||
**Automate** | ||
|
||
flochaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
You can run the end-to-end tests automatically on your forked project by following these step. | ||
flochaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
1. Create AWS Role | ||
flochaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
As mention earlier we are leveraging CDK to deploy and clean resources on AWS. Therefore to run those tests through github actions you will need to grant specific permissions to your workflow. To do so you can leverage [@pahud/cdk-github-oidc](https://constructs.dev/packages/@pahud/cdk-github-oidc) construct which setup the right resources to leverage [Github OpenID Connect](https://github.blog/changelog/2021-10-27-github-actions-secure-cloud-deployments-with-openid-connect/) mechanism. | ||
flochaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
1. Add your new role into your Github fork secrets under `AWS_ROLE_ARN_TO_ASSUME`. | ||
1. Run manually `run-e2e-tests` workflow. | ||
flochaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
flochaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
> :Warning: **Don't automatically run end-to-end tests on branch push or PRs**. A malicious attacker can submit a pull request to attack your AWS account. Ideally, use a blank account without any important workload/data, and limit `AWS_ROLE_ARN_TO_ASSUME` permission to least minimum privilege. | ||
### Conventions | ||
|
||
Category | Convention | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.