Skip to content

Commit 4801750

Browse files
docker is flaky. ci is broken. but it works locally i guess
1 parent 935c69f commit 4801750

26 files changed

+162
-194
lines changed

.dockerignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/workflows/test.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Test
1+
name: Test Next.js v14
22

33
on:
44
push:
@@ -22,6 +22,9 @@ jobs:
2222
- name: Install dependencies
2323
run: npm ci
2424

25+
- name: Install HarperDB
26+
run: npm i -g [email protected]
27+
2528
- name: Install Playwright Browsers
2629
run: npx playwright install --with-deps
2730

fixtures/harperdb-base-component/resources.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,9 @@ const dogs = [
33
{ id: '1', name: 'Max', breed: 'Cocker Spaniel' },
44
{ id: '2', name: 'Bella', breed: 'Lab' },
55
{ 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' },
6+
{ id: '4', name: 'Lucy', breed: 'Newfoundland' }
147
];
15-
console.log('testing');
8+
169
for (const dog of dogs) {
17-
await tables.Dog.put(dog);
10+
tables.Dog.put(dog);
1811
}

fixtures/next-14/.dockerignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

fixtures/next-14/config.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
rest: true
2-
graphqlSchema:
3-
files: './schema.graphql'
4-
jsResource:
5-
files: './resources.mjs'
61
'@harperdb/nextjs':
72
package: '@harperdb/nextjs'
83
files: '/*'

fixtures/next-14/middleware.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { NextResponse, NextRequest } from 'next/server';
2+
3+
export function middleware(request) {
4+
return new NextResponse('Hello from middleware', { headers: { 'x-middleware': 'true' } });
5+
}
6+
7+
export const config = {
8+
matcher: '/test-middleware'
9+
}

fixtures/next-14/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
"build": "next build",
77
"start": "next start",
88
"lint": "next lint",
9-
"postinstall": "npm link @harperdb/nextjs",
9+
"postinstall": "npm link harperdb",
1010
"test": "playwright test"
1111
},
1212
"dependencies": {
13-
"@harperdb/nextjs": "*",
14-
"harperdb": "^4.4.8",
13+
"@harperdb/nextjs": "file:../../",
1514
"next": "^14",
1615
"react": "^18",
1716
"react-dom": "^18"
1817
},
1918
"devDependencies": {
20-
"@playwright/test": "^1.49.0"
19+
"@playwright/test": "^1.49.0",
20+
"test-utils": "file:../../test-utils/"
2121
}
2222
}

fixtures/next-14/playwright.config.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
const { defineConfig, devices } = require('@playwright/test');
2-
const { join } = require('node:path');
32

43
module.exports = defineConfig({
5-
testDir: 'test',
64
fullyParallel: true,
75
forbidOnly: !!process.env.CI,
6+
retries: 2,
7+
expect: {
8+
timeout: 30000,
9+
},
810
projects: [
911
{
10-
use: { ...devices['Desktop Chrome'] },
12+
name: 'chromium',
13+
use: { ...devices['Desktop Chrome'], channel: 'chromium' },
1114
}
1215
],
13-
globalSetup: join(__dirname, './util/global-setup.js'),
14-
globalTeardown: join(__dirname, './util/global-teardown.js'),
16+
globalSetup: require.resolve('test-utils/global-setup.js'),
17+
globalTeardown: require.resolve('test-utils/global-teardown.js'),
1518
});

fixtures/next-14/resources.mjs

Lines changed: 0 additions & 11 deletions
This file was deleted.

fixtures/next-14/schema.graphql

Lines changed: 0 additions & 5 deletions
This file was deleted.

fixtures/next-14/test/next-14.test.js renamed to fixtures/next-14/test/index.test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { test, expect } from '@playwright/test';
22

3-
// test.describe.configure({ mode: 'serial' });
43
const baseURL = 'http://localhost:9926';
54

65
test('home page', async ({ page }) => {
@@ -95,3 +94,10 @@ test.describe('caching', () => {
9594
expect(when1).not.toBe(when2);
9695
});
9796
});
97+
98+
test('middleware', async ({ page }) => {
99+
const response = await fetch(`${baseURL}/test-middleware`);
100+
expect(response.headers.get('x-middleware')).toBe('true');
101+
const text = await response.text();
102+
expect(text).toBe('Hello from middleware');
103+
});

fixtures/next-9/playwright.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const { defineConfig, devices } = require('@playwright/test');
2+
const { join } = require('node:path');
3+
4+
module.exports = defineConfig({
5+
testDir: 'test',
6+
fullyParallel: true,
7+
forbidOnly: !!process.env.CI,
8+
projects: [
9+
{
10+
use: { ...devices['Desktop Chrome'] },
11+
}
12+
],
13+
globalSetup: join(__dirname, './util/global-setup.js'),
14+
globalTeardown: join(__dirname, './util/global-teardown.js'),
15+
});

fixtures/next-9/test/next-9.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
const baseURL = 'http://localhost:9926';
4+
5+
test('home page', async ({ page }) => {
6+
await page.goto(baseURL);
7+
await expect(page.locator('h1')).toHaveText('Next.js v9');
8+
});
9+
10+
test('title', async ({ page }) => {
11+
await page.goto(baseURL);
12+
await expect(page).toHaveTitle('HarperDB - Next.js v9 App');
13+
});
14+
15+
test('page 2', async ({ page }) => {
16+
await page.goto(baseURL);
17+
await page.locator('a').click();
18+
await expect(page.locator('h1')).toHaveText('Page 2');
19+
});

fixtures/next-14/util/global-setup.js renamed to fixtures/next-9/util/global-setup.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ module.exports = function globalSetup(config) {
1111

1212
harperdbProcess.stdout.pipe(new Transform({
1313
transform(chunk, encoding, callback) {
14-
const data = chunk.toString();
15-
if (/HarperDB \d+.\d+.\d+ successfully started/.test(data)) {
14+
if (/HarperDB \d+.\d+.\d+ successfully started/.test(chunk.toString())) {
1615
resolve();
1716
}
1817
callback(null, chunk);

playwright.config.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

test-utils/global-setup.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
const { spawn, execSync, exec } = require('node:child_process');
2+
const { Transform } = require('node:stream');
3+
const { join } = require('node:path');
4+
const { symlinkSync } = require('node:fs');
5+
const { setTimeout } = require('node:timers/promises');
6+
7+
const ROOT = join(__dirname, '..');
8+
9+
function getComponents() {
10+
const componentsString = execSync(`npx harperdb get_components json=true`, { encoding: 'utf-8' });
11+
return JSON.parse(componentsString);
12+
}
13+
14+
function getConfiguration() {
15+
const configurationString = execSync(`npx harperdb get_configuration json=true`, { encoding: 'utf-8' });
16+
return JSON.parse(configurationString);
17+
}
18+
19+
module.exports = async function globalSetup(config) {
20+
execSync('npx harperdb start', { stdio: 'inherit' });
21+
await setTimeout(2000);
22+
23+
const components = getComponents();
24+
if (!components.entries.some(({ name }) => name === 'harperdb-base-component')) {
25+
const configuration = getConfiguration();
26+
const componentsRoot = configuration.componentsRoot;
27+
28+
symlinkSync(join(ROOT, 'fixtures', 'harperdb-base-component'), join(componentsRoot, 'harperdb-base-component'));
29+
30+
execSync(`npx harperdb restart`);
31+
32+
await setTimeout(5000);
33+
}
34+
35+
execSync('npx harperdb stop', { stdio: 'inherit' });
36+
37+
await new Promise((resolve, reject) => {
38+
console.log('npx harperdb run', config.rootDir);
39+
const harperdbProcess = spawn('npx', ['harperdb', 'run', config.rootDir]);
40+
41+
harperdbProcess.on('error', reject);
42+
harperdbProcess.on('exit', resolve);
43+
44+
harperdbProcess.stdout.pipe(new Transform({
45+
transform(chunk, encoding, callback) {
46+
if (/HarperDB \d+.\d+.\d+ successfully started/.test(chunk.toString())) {
47+
resolve();
48+
}
49+
callback(null, chunk);
50+
}
51+
})).pipe(process.stdout);
52+
});
53+
}

test-utils/global-teardown.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const { spawn } = require('node:child_process');
2+
3+
module.exports = function globalTeardown(config) {
4+
return new Promise((resolve, reject) => {
5+
const harperdbProcess = spawn('npx', ['harperdb', 'stop']);
6+
harperdbProcess.on('error', reject);
7+
harperdbProcess.on('exit', resolve);
8+
});
9+
}

test-utils/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "test-utils",
3+
"private": true,
4+
"files": [
5+
"global-setup.js",
6+
"global-teardown.js"
7+
]
8+
}

test.Dockerfile

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
ARG NODE_VERSION=22
2-
FROM docker.io/node:${NODE_VERSION}-slim
2+
FROM docker.io/node:${NODE_VERSION}-slim as base
33

44
EXPOSE 9925 9926
55

6-
RUN npx -y playwright install --with-deps
7-
86
# Install HarperDB Globally
97
RUN npm install -g [email protected]
108

@@ -20,20 +18,31 @@ ENV LOGGING_STDSTREAMS=true
2018
ENV LOGGING_LEVEL=debug
2119
ENV AUTHENTICATION_AUTHORIZELOCAL=false
2220

21+
RUN harperdb start && sleep 5
22+
23+
COPY /fixtures/harperdb-base-component/ /hdb/components/harperdb-base-component/
24+
25+
RUN harperdb start && sleep 5
26+
27+
COPY /test-utils/ /test-utils/
28+
2329
# Create the @harperdb/nextjs module directory so it can be linked locally
24-
RUN mkdir -p /@harperdb/nextjs
30+
RUN mkdir -p /@harperdb/nextjs/
2531
COPY config.yaml extension.js cli.js package.json /@harperdb/nextjs/
26-
WORKDIR /@harperdb/nextjs
32+
WORKDIR /@harperdb/nextjs/
2733
# Install dependencies for the @harperdb/nextjs module
2834
RUN npm install --omit=dev
2935
# Create link to the @harperdb/nextjs module
3036
RUN npm link
3137

3238
WORKDIR /
3339

40+
FROM base as test
41+
3442
ARG FIXTURE
35-
COPY /fixtures/${FIXTURE} /fixture
36-
WORKDIR /fixture
43+
COPY /fixtures/${FIXTURE}/ /fixtures/${FIXTURE}/
44+
WORKDIR /fixtures/${FIXTURE}/
3745
RUN npm install
46+
RUN npx -y playwright install chromium --with-deps
3847

3948
CMD npm run test

test.Dockerfile.dockerignore

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

test/next-13.test.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)