Skip to content

Commit 5519499

Browse files
testing matrix (#3)
* init testing matrix * add hdb stop * try timeout * add || true * try this * try sleep 30 * whoops * oh actions I love you * . * use docker and js. wip * update dockerfil to copy the base component * fix arg order in dockerfile * use node test runner * try out some concurrency * add debugging and make operations non-blocking * DRY * progress * ci? * debug in ci * try localhost: * okay working(ish). component loading issue related to dep install. * install install * eureka! separate out build step to improve test speed * lots of progress. but why do the tests fail in concurrency mode? * no more concurrency. breaks computer * prepare for review * fix CONTRIBUTING * fix workflow * come on docker * podman? * ugh * playwright this time
1 parent c9a6219 commit 5519499

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+737
-3
lines changed

.github/workflows/test.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: '22'
20+
cache: 'npm'
21+
22+
- name: Install dependencies
23+
run: npm ci
24+
25+
- name: Install Playwright Browsers
26+
run: npx playwright install --with-deps
27+
28+
- name: Run tests
29+
run: npm run test
30+
31+
- uses: actions/upload-artifact@v4
32+
if: ${{ !cancelled() }}
33+
with:
34+
name: playwright-report
35+
path: playwright-report/
36+
retention-days: 30

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
node_modules/
1+
node_modules/
2+
.next/
3+
test-results/

.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
22.11.0

CONTRIBUTING.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Contributing
2+
3+
## Code Organization
4+
5+
All code should abide by the following organization rules:
6+
7+
- `fixtures/` is for directories that will be utilized in testing.
8+
- They should be fully executable locally for debugging purposes
9+
- They should be as minimal as possible
10+
- `test/` is for Playwright based test files that are executed by `npm run test`
11+
- Test files should use `import { test, expect } from '../util/test-fixture.js';` so that the correct **Fixture** is managed for the test script
12+
- Test files should execute serially, and relevant to the given Next.js versions
13+
- `util/` is for any non-module source code. This includes scripts (`util/scripts/`), docker configurations (`util/docker/`), or any other utility based code.
14+
- Prime examples include the source code responsible for [_building_](./util/scripts/pretest.js) the **Fixtures**, or the custom Playwright [test fixture](./util/test-fixture.js)
15+
16+
The key source files for the repo are:
17+
18+
- `cli.js`
19+
- `extension.js`
20+
- `config.yaml`
21+
- `schema.graphql`
22+
23+
## Testing
24+
25+
Testing for this repo uses containers in order to generate stable, isolated environments containing:
26+
27+
- HarperDB
28+
- Node.js
29+
- A HarperDB Base Component (responsible for seeding the database)
30+
- A Next.js application Component (which uses this `@harperdb/nextjs` extension)
31+
32+
To execute tests, run `npm run test`
33+
34+
The first run may take some time as the pretest script is building 12 separate images (3 Node.js ones, 9 Next.js ones). Note, at the moment this operation is parallelized as building is very expensive and can result in the system running out of resources (and crashing the build processes). Subsequent runs utilize the Docker build step cache and are very fast.
35+
36+
After the images are built, [Playwright](https://playwright.dev/) will run the tests. These tests each utilize an image, and will manage a container instance relevant to the given Next.js and Node.js pair.
37+
38+
The tests are configured with generous timeouts and limited to 3 workers at a time to not cause the system to run out of resources.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
rest: true
2+
graphqlSchema:
3+
files: './schema.graphql'
4+
jsResource:
5+
files: './resources.js'
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "harperdb-base-component",
3+
"private": true
4+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const dogs = [
2+
{ id: '0', name: 'Lincoln', breed: 'Shepherd' },
3+
{ id: '1', name: 'Max', breed: 'Cocker Spaniel' },
4+
{ id: '2', name: 'Bella', breed: 'Lab' },
5+
{ id: '3', name: 'Charlie', breed: 'Great Dane' },
6+
{ id: '4', name: 'Lucy', breed: 'Newfoundland' },
7+
{ id: '5', name: 'Cooper', breed: 'Pug' },
8+
{ id: '6', name: 'Daisy', breed: 'Bull Dog' },
9+
{ id: '7', name: 'Rocky', breed: 'Akita' },
10+
{ id: '8', name: 'Luna', breed: 'Wolf' },
11+
{ id: '9', name: 'Buddy', breed: 'Border Collie' },
12+
{ id: '10', name: 'Bailey', breed: 'Golden Retriever' },
13+
{ id: '11', name: 'Sadie', breed: 'Belgian Malinois' },
14+
];
15+
16+
for (const dog of dogs) {
17+
tables.Dog.put(dog);
18+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type Dog @table @export {
2+
id: ID @primaryKey
3+
name: String
4+
breed: String
5+
}

fixtures/next-13/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

fixtures/next-13/app/layout.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export const metadata = {
2+
title: 'HarperDB - Next.js v13 App',
3+
};
4+
5+
export default function RootLayout({ children }) {
6+
return (
7+
<html>
8+
<body>{children}</body>
9+
</html>
10+
);
11+
}

fixtures/next-13/app/page.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default async function Page() {
2+
return (
3+
<div>
4+
<h1>Next.js v13</h1>
5+
</div>
6+
);
7+
}

fixtures/next-13/config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'@harperdb/nextjs':
2+
package: '@harperdb/nextjs'
3+
files: '/*'
4+
port: 9926

fixtures/next-13/next.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {};

fixtures/next-13/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "next-13",
3+
"private": true,
4+
"scripts": {
5+
"dev": "next dev",
6+
"build": "next build",
7+
"start": "next start",
8+
"lint": "next lint",
9+
"postinstall": "npm link @harperdb/nextjs"
10+
},
11+
"dependencies": {
12+
"@harperdb/nextjs": "*",
13+
"react": "^18",
14+
"react-dom": "^18",
15+
"next": "^13"
16+
}
17+
}

fixtures/next-14/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

fixtures/next-14/app/layout.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export const metadata = {
2+
title: 'HarperDB - Next.js v14 App',
3+
};
4+
5+
export default function RootLayout({ children }) {
6+
return (
7+
<html>
8+
<body>{children}</body>
9+
</html>
10+
);
11+
}

fixtures/next-14/app/page.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default async function Page() {
2+
return (
3+
<div>
4+
<h1>Next.js v14</h1>
5+
</div>
6+
);
7+
}

fixtures/next-14/config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'@harperdb/nextjs':
2+
package: '@harperdb/nextjs'
3+
files: '/*'
4+
port: 9926

fixtures/next-14/next.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {};

fixtures/next-14/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "next-14",
3+
"private": true,
4+
"scripts": {
5+
"dev": "next dev",
6+
"build": "next build",
7+
"start": "next start",
8+
"lint": "next lint",
9+
"postinstall": "npm link @harperdb/nextjs"
10+
},
11+
"dependencies": {
12+
"@harperdb/nextjs": "*",
13+
"react": "^18",
14+
"react-dom": "^18",
15+
"next": "^14"
16+
}
17+
}

fixtures/next-15/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

fixtures/next-15/app/layout.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export const metadata = {
2+
title: 'HarperDB - Next.js v15 App',
3+
};
4+
5+
export default function RootLayout({ children }) {
6+
return (
7+
<html>
8+
<body>{children}</body>
9+
</html>
10+
);
11+
}

fixtures/next-15/app/page.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default async function Page() {
2+
return (
3+
<div>
4+
<h1>Next.js v15</h1>
5+
</div>
6+
);
7+
}

fixtures/next-15/config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'@harperdb/nextjs':
2+
package: '@harperdb/nextjs'
3+
files: '/*'
4+
port: 9926

fixtures/next-15/next.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {};

fixtures/next-15/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "next-15",
3+
"private": true,
4+
"scripts": {
5+
"dev": "next dev",
6+
"build": "next build",
7+
"start": "next start",
8+
"lint": "next lint",
9+
"postinstall": "npm link @harperdb/nextjs"
10+
},
11+
"dependencies": {
12+
"@harperdb/nextjs": "*",
13+
"react": "19.0.0-rc-66855b96-20241106",
14+
"react-dom": "19.0.0-rc-66855b96-20241106",
15+
"next": "^15"
16+
}
17+
}

package-lock.json

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,18 @@
3333
"schema.graphql"
3434
],
3535
"scripts": {
36-
"format": "prettier --write ."
36+
"format": "prettier .",
37+
"format:check": "npm run format -- --check",
38+
"format:fix": "npm run format -- --write",
39+
"pretest": "node util/scripts/pretest.js",
40+
"test": "playwright test --workers 3"
3741
},
3842
"dependencies": {
3943
"shell-quote": "^1.8.1"
4044
},
4145
"devDependencies": {
4246
"@harperdb/code-guidelines": "^0.0.2",
47+
"@playwright/test": "^1.49.0",
4348
"prettier": "^3.3.3"
4449
},
4550
"prettier": "@harperdb/code-guidelines/prettier"

playwright.config.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { defineConfig, devices } from '@playwright/test';
2+
3+
const NEXT_MAJORS = ['13', '14', '15'];
4+
const NODE_MAJORS = ['18', '20', '22'];
5+
6+
export default defineConfig({
7+
testDir: 'test',
8+
fullyParallel: true,
9+
forbidOnly: !!process.env.CI,
10+
workers: 3,
11+
retries: 2,
12+
expect: {
13+
timeout: 30000,
14+
},
15+
projects: NEXT_MAJORS.flatMap((nextMajor) =>
16+
NODE_MAJORS.map((nodeMajor) => ({
17+
name: `Next.js v${nextMajor} - Node.js v${nodeMajor}`,
18+
use: { versions: { nextMajor, nodeMajor }, ...devices['Desktop Chrome'] },
19+
testMatch: [`test/next-${nextMajor}.test.js`],
20+
}))
21+
),
22+
});

schema.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
type NextCache @table(database: "cache" expiration: 3600) @export {
1+
type NextCache @table(database: "cache", expiration: 3600) @export {
22
id: ID @primaryKey
33
headers: Any
44
content: Bytes

0 commit comments

Comments
 (0)