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

Fix/e2e tests #1061

Merged
merged 45 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
909133c
chore: added all selected columns to the groupBy function
JohnAllenTech Oct 2, 2024
b685436
Merge branch 'develop' into fix/broken-article-query
JohnAllenTech Oct 3, 2024
389acab
chore: updated drizzle orm dep and tested it works
JohnAllenTech Oct 3, 2024
6649e50
fix: e2e tests back working
JohnAllenTech Oct 3, 2024
3066351
fix: removing flaky part of e2e test
JohnAllenTech Oct 3, 2024
94f8c72
chore: removing more flakiness
JohnAllenTech Oct 4, 2024
b2d088d
chore: working but still flaky
JohnAllenTech Oct 4, 2024
abdd4d1
chore: attempting to reuse single login across multiple tests
JohnAllenTech Oct 8, 2024
489c459
chore: still not working in headless mode
JohnAllenTech Oct 11, 2024
60ad7a8
Merge branch 'develop' into fix/e2e-tests
JohnAllenTech Oct 11, 2024
a0f3387
chore: reverted merge and added autheticated browser state to gitignore
JohnAllenTech Oct 11, 2024
5cf2438
chore: removing browser.json to safeguard against people uploading th…
JohnAllenTech Oct 11, 2024
9db35ca
chore: removed playwright workflow
JohnAllenTech Oct 11, 2024
28098da
Merge branch 'develop' into fix/e2e-tests
JohnAllenTech Oct 11, 2024
91ea958
chore: classic hackerman stuff here
JohnAllenTech Oct 12, 2024
97a9545
Merge branch 'develop' into fix/e2e-tests
JohnAllenTech Oct 13, 2024
8415a67
chore: removing some unused code and making the authenticated browser…
JohnAllenTech Oct 13, 2024
ec6172c
chore: some logging for future humans
JohnAllenTech Oct 13, 2024
144a5bf
chore: nearly there. testing workflow
JohnAllenTech Oct 13, 2024
ed447a3
chore: updated e2e workflow to input new seed script
JohnAllenTech Oct 13, 2024
9312347
chore: now logging error when browser.json fails
JohnAllenTech Oct 13, 2024
7ac5ebc
chore: more logging around file creation errors
JohnAllenTech Oct 13, 2024
732b6b0
chore: removed logging
JohnAllenTech Oct 13, 2024
82ba182
Merge branch 'develop' into fix/e2e-tests
JohnAllenTech Oct 13, 2024
86c3f68
chore: updated some naming
JohnAllenTech Oct 13, 2024
6676d88
chore: now creating folder and file in workflow
JohnAllenTech Oct 13, 2024
f42dbf1
Merge branch 'develop' into fix/e2e-tests
NiallJoeMaher Oct 14, 2024
78a03ba
chore: add more logging to file creation process
JohnAllenTech Oct 14, 2024
3c8b921
chore: async file and folder creation added
JohnAllenTech Oct 14, 2024
e7f8d4f
chore: back to sync and more logging in folder/file creation
JohnAllenTech Oct 14, 2024
d62f95c
chore: removed throw errors for testing
JohnAllenTech Oct 14, 2024
bf7d103
chore: added hacky wait step
JohnAllenTech Oct 14, 2024
acf2e05
chore: new way of creating the files/folders added
JohnAllenTech Oct 14, 2024
e6bca18
chore: creating files successfully but module import failing
JohnAllenTech Oct 14, 2024
a75a83f
chore: now creating files in workflow step
JohnAllenTech Oct 14, 2024
1da9338
chore: moved file/folder creation into seed step
JohnAllenTech Oct 14, 2024
6154e0d
chore: removed git ignore as browser state is now fully mocked
JohnAllenTech Oct 14, 2024
e9fbb34
chore: now not depending on process env var
JohnAllenTech Oct 14, 2024
d5468c8
chore: made authenticated homepage test more robust
JohnAllenTech Oct 14, 2024
fbed02d
chore: replaced order of tests to see if cookies are cleared at a tes…
JohnAllenTech Oct 14, 2024
5f89326
chore: now seeding e2e user in normal seed script
JohnAllenTech Oct 14, 2024
fc64a92
chore: cleanup before PR review
JohnAllenTech Oct 14, 2024
0ae6105
Merge branch 'develop' into fix/e2e-tests
JohnAllenTech Oct 14, 2024
b2f994f
chore: cleaning up old script
JohnAllenTech Oct 14, 2024
cb662cc
chore: prettier fix
JohnAllenTech Oct 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 76 additions & 73 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ jobs:
initial-checks:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
cache: 'npm'
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"
cache: "npm"

- name: Install dependencies
run: npm ci
- name: Install dependencies
run: npm ci

e2e:
needs: initial-checks
Expand All @@ -44,66 +44,69 @@ jobs:
GITHUB_ID: ${{ secrets.E2E_GITHUB_ID }}
GITHUB_SECRET: ${{ secrets.E2E_GITHUB_SECRET }}
NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }}
E2E_USER_EMAIL: [email protected]
E2E_USER_ID: 8e3179ce-f32b-4d0a-ba3b-234d66b836ad
E2E_USER_SESSION_ID: df8a11f2-f20a-43d6-80a0-a213f1efedc1

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
cache: 'npm'

- name: Cache Playwright browsers
uses: actions/cache@v3
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-playwright-

- name: Run docker-compose
uses: isbang/[email protected]
with:
compose-file: "./docker-compose.yml"
down-flags: "--volumes"
services: |
db

- name: Wait for DB to be ready
run: |
timeout 60s bash -c 'until nc -z localhost 5432; do echo "Waiting for database connection..."; sleep 2; done'
shell: bash

- name: Install dependencies
run: npm ci

- name: Install Playwright browsers
run: npx playwright install --with-deps
if: steps.playwright-cache.outputs.cache-hit != 'true'

- name: Seed database
run: |
npm run db:push
npm run db:seed

- name: Run Playwright tests
id: playwright-tests
run: npx playwright test
continue-on-error: true

- name: Upload Playwright report
uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30

- name: Check test results
if: steps.playwright-tests.outcome == 'failure'
run: exit 1
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"
cache: "npm"

- name: Cache Playwright browsers
uses: actions/cache@v3
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-playwright-

- name: Run docker-compose
uses: isbang/[email protected]
with:
compose-file: "./docker-compose.yml"
down-flags: "--volumes"
services: |
db

- name: Wait for DB to be ready
run: |
timeout 60s bash -c 'until nc -z localhost 5432; do echo "Waiting for database connection..."; sleep 2; done'
shell: bash

- name: Install dependencies
run: npm ci

- name: Install Playwright browsers
run: npx playwright install --with-deps
if: steps.playwright-cache.outputs.cache-hit != 'true'

- name: Seed database
run: |
npm run db:push
npm run db:seed

- name: Run Playwright tests
id: playwright-tests
run: npx playwright test
continue-on-error: true

- name: Upload Playwright report
uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30

- name: Check test results
if: steps.playwright-tests.outcome == 'failure'
run: exit 1
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ ssmSetup.zsh


# open-next
.open-next
.open-next
63 changes: 60 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ We have a fantastic community growing on Discord. Click [here](https://discord.g
```bash
npm install
```

- If you have any issues installing dependencies, check your node version against that defined in the `.nvmrc`. If you're using `nvm`, you can run `nvm use` before installing dependencies.

5. Create a `.env` file and add the following variables. You can copy the contents of `sample.env` with `cat sample.env > .env`.
Expand All @@ -46,17 +47,18 @@ For a more detailed how to guide on setting them up [go to the Environment Varia

6. Setup the tables in the database with Drizzle by running:


```bash
npm run db:push
```

The full command can be seen in our [package.json](/package.json#16) file

7. Seed the database with some mock data by running:

```bash
npm run db:seed
```

The full command can be seen in our [package.json](/package.json#19) file

8. Finally, run the development server:
Expand Down Expand Up @@ -94,17 +96,21 @@ Alternatively, if you have PostgreSQL running locally then you can use your loca
Currently, we only allow authentication via GitHub. To enable this you need to have a `GITHUB_ID` and `GITHUB_SECRET` value.

Setup your GitHub ID & Secret on GitHub:
- [Click here](https://github.com/settings/applications/new) to setup New OAuth App and fill in the details as shown below.

- [Click here](https://github.com/settings/applications/new) to setup New OAuth App and fill in the details as shown below.

For development, make sure you setup this with a **Homepage URL** of

```
http://localhost:3000/
```

and **Authorization callback URL** of
```

```
http://localhost:3000/api/auth
```

as shown in the image below:

![Screenshot 2022-10-25 at 08 22 03](https://user-images.githubusercontent.com/12615742/197709325-50766dc2-2245-438c-8f71-09064fc3b123.png)
Expand Down Expand Up @@ -135,6 +141,16 @@ You shouldn't need to change the default value here. This is a variable used by
NEXTAUTH_URL=http://localhost:3000/api/auth
```

### E2E_USER_SESSION_ID

This is the sessionToken uuid that .
This is currently hardcoded and there is no reason to change this until we require multiple E2E test users within the same test suite

### E2E_USER_ID

This is the userId if the E2E user used for testing .
This is currently hardcoded and there is no reason to change this until we require multiple E2E test users within the same test suite

For more information, you can read the documentation [here](https://next-auth.js.org/configuration/options).
**Example .env file can be found [here](./sample.env). You can rename this to .env to get started**

Expand All @@ -147,6 +163,47 @@ For more information, you can read the documentation [here](https://next-auth.js
- Run Tests
- Also, Style Guide for Commit Messages

## End-to-End Testing with Playwright

To run the end-to-end tests using Playwright, you need to configure your environment and follow these steps:

### Environment Variables

Please ensure you have the following variables set in your `.env` file:

- `E2E_USER_ID`: The id of the E2E user for testing.
- `E2E_USER_EMAIL`: The email of the E2E user for testing.
- `E2E_USER_SESSION_ID`: The session id that the user will use to authenticate.


Note the sample .env [here](./sample.env) is fine to use.

### Session and User setup

First you need to add your E2E test user to your locally running database. Do this by running the following script if you havent already

```
npm run db:seed
```

This will create a user and session for your E2E tests. Details of the E2E user created can be seen [here](./drizzle/seedE2E.ts)

### Running the Tests

You can run the end-to-end tests using one of the following commands:

For headless mode:

```zsh
npx playwright test
```

For UI mode:

```zsh
npx playwright test --ui
```

## 📙 Prerequisite Skills to Contribute

- [Git](https://git-scm.com/)
Expand Down
2 changes: 2 additions & 0 deletions app/(app)/get-started/_client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const GetStarted: NextPage = () => {
)}

<button
data-testid="github-login-button"
type="button"
onClick={async () => {
await signIn("github", { callbackUrl: redirectTo });
Expand Down Expand Up @@ -117,6 +118,7 @@ const GetStarted: NextPage = () => {
Continue with GitHub
</button>
<button
data-testid="gitlab-login-button"
type="button"
onClick={async () => {
await signIn("gitlab", { callbackUrl: redirectTo });
Expand Down
Loading
Loading