Skip to content

Commit

Permalink
eureka! separate out build step to improve test speed
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan-Arrowood committed Dec 1, 2024
1 parent ca16551 commit f84b972
Show file tree
Hide file tree
Showing 28 changed files with 244 additions and 157 deletions.
42 changes: 0 additions & 42 deletions fixtures/Dockerfile

This file was deleted.

12 changes: 0 additions & 12 deletions fixtures/next-10/index.js

This file was deleted.

4 changes: 0 additions & 4 deletions fixtures/next-10/package.json

This file was deleted.

12 changes: 0 additions & 12 deletions fixtures/next-11/index.js

This file was deleted.

4 changes: 0 additions & 4 deletions fixtures/next-11/package.json

This file was deleted.

12 changes: 0 additions & 12 deletions fixtures/next-12/index.js

This file was deleted.

4 changes: 0 additions & 4 deletions fixtures/next-12/package.json

This file was deleted.

13 changes: 13 additions & 0 deletions fixtures/next-13/app/layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const metadata = {
title: 'HarperDB - Next.js v15 App',
};

export default function RootLayout({ children }) {
return (
<html>
<body>
{children}
</body>
</html>
);
}
7 changes: 7 additions & 0 deletions fixtures/next-13/app/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default async function Page() {
return (
<div>
<h1>Next.js v15</h1>
</div>
);
}
4 changes: 4 additions & 0 deletions fixtures/next-13/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'@harperdb/nextjs':
package: '@harperdb/nextjs'
files: '/*'
port: 9926
12 changes: 0 additions & 12 deletions fixtures/next-13/index.js

This file was deleted.

1 change: 1 addition & 0 deletions fixtures/next-13/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
15 changes: 13 additions & 2 deletions fixtures/next-13/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
{
"name": "next-13",
"type": "module"
}
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@harperdb/nextjs": "file:/harperdb-nextjs",
"next": "13.5.7"
}
}

13 changes: 13 additions & 0 deletions fixtures/next-14/app/layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const metadata = {
title: 'HarperDB - Next.js v15 App',
};

export default function RootLayout({ children }) {
return (
<html>
<body>
{children}
</body>
</html>
);
}
7 changes: 7 additions & 0 deletions fixtures/next-14/app/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default async function Page() {
return (
<div>
<h1>Next.js v15</h1>
</div>
);
}
4 changes: 4 additions & 0 deletions fixtures/next-14/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'@harperdb/nextjs':
package: '@harperdb/nextjs'
files: '/*'
port: 9926
12 changes: 0 additions & 12 deletions fixtures/next-14/index.js

This file was deleted.

1 change: 1 addition & 0 deletions fixtures/next-14/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
14 changes: 13 additions & 1 deletion fixtures/next-14/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
{
"name": "next-14",
"type": "module"
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@harperdb/nextjs": "file:/harperdb-nextjs",
"react": "^18",
"react-dom": "^18",
"next": "14.2.18"
}
}
12 changes: 0 additions & 12 deletions fixtures/next-9/index.js

This file was deleted.

4 changes: 0 additions & 4 deletions fixtures/next-9/package.json

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"format": "prettier .",
"format:check": "npm run format -- --check",
"format:write": "npm run format -- --write",
"pretest": "node scripts/pretest.js",
"test": "node --test"
},
"dependencies": {
Expand Down
27 changes: 3 additions & 24 deletions test/next-15-node-18.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { suite, test, before, after } from 'node:test';

import { base, next15 } from '../util/tests.js';
import { Fixture } from '../util/fixture.js';

suite('Next.js v15 - Node.js v18', async () => {
Expand All @@ -8,31 +8,10 @@ suite('Next.js v15 - Node.js v18', async () => {
before(async () => {
ctx.fixture = new Fixture({ nextMajor: '15', nodeMajor: '18' });
await ctx.fixture.ready;
ctx.rest = `http://${ctx.fixture.portMap.get('9926')}`;
});

await test('should run base component', async (t) => {
const response = await fetch(`${ctx.rest}/Dog/0`, {
headers: {
'Content-Type': 'application/json',
'Authorization': 'Basic aGRiX2FkbWluOnBhc3N3b3Jk',
},
});
const json = await response.json();

t.assert.deepStrictEqual(json, { id: '0', name: 'Lincoln', breed: 'Shepherd' });
ctx.rest = new URL(`http://${ctx.fixture.portMap.get('9926')}`);
});

await test('should reach home page', async (t) => {
const response = await fetch(`${ctx.rest}/`, {
headers: {
'Content-Type': 'text/html',
}
});

const text = await response.text();
t.assert.match(text, /Next\.js v15/);
});
await Promise.all(base.concat(next15).map(async ({ name, testFunction }) => test(name, t => testFunction(t, ctx))));

after(async () => {
await ctx.fixture.clear();
Expand Down
27 changes: 27 additions & 0 deletions util/base.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
ARG NODE_MAJOR

FROM node:${NODE_MAJOR}

RUN apt-get update && apt-get install -y \
curl \
&& rm -rf /var/lib/apt/lists/*

RUN mkdir -p /@harperdb/nextjs

COPY --exclude=.github --exclude=fixtures --exclude=test --exclude=util --exclude=node_modules --exclude=.node-version --exclude=.git \
. /@harperdb/nextjs

RUN npm install -C /@harperdb/nextjs

RUN npm install -g harperdb

RUN mkdir -p /hdb/components

ENV TC_AGREEMENT=yes
ENV HDB_ADMIN_USERNAME=hdb_admin
ENV HDB_ADMIN_PASSWORD=password
ENV ROOTPATH=/hdb
ENV OPERATIONSAPI_NETWORK_PORT=9925
ENV HTTP_PORT=9926

COPY /fixtures/harperdb-base-component /hdb/components/harperdb-base-component
17 changes: 17 additions & 0 deletions util/getContainerEngine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { spawnSync } from 'child_process';


const CONTAINER_ENGINE_LIST = ['podman', 'docker'];

export function getContainerEngine() {
for (const engine of CONTAINER_ENGINE_LIST) {
const { status } = spawnSync(engine, ['--version'], { stdio: 'ignore' });
if (status === 0) {
return engine;
}
}

throw new Error(`No container engine found in ${CONTAINER_ENGINE_LIST.join(', ')}`);
}

export const containerEngine = getContainerEngine();
13 changes: 13 additions & 0 deletions util/next.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ARG BASE_IMAGE

FROM ${BASE_IMAGE}

ARG NEXT_MAJOR

COPY fixtures/next-${NEXT_MAJOR} /hdb/components/next-${NEXT_MAJOR}

RUN npm install -C hdb/components/next-${NEXT_MAJOR}

EXPOSE 9925 9926

CMD ["harperdb", "run"]
Loading

0 comments on commit f84b972

Please sign in to comment.