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

Add Integration tests #1

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 4 additions & 5 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,14 @@ function assertNextJSApp (componentPath) {
*/
async function executeCommand(commandInput, componentPath) {
const [ command, ...args ] = shellQuote.parse(commandInput);

const cp = child_process.spawn(command, args, {
cwd: componentPath,
stdio: logger.log_level === 'debug' ? 'inherit' : 'ignore'
});

const exitCode = await events.once(cp, 'exit');
const [exitCode] = await events.once(cp, 'exit');

logger.debug(`${commandInput} exited with ${exitCode}`);
logger.debug(`Command: \`${commandInput}\` exited with ${exitCode}`);
}

/**
Expand All @@ -155,7 +154,7 @@ async function executeCommand(commandInput, componentPath) {
* @param {ExtensionOptions} options
* @returns
*/
export async function startOnMainThread (options) {
export function startOnMainThread (options = {}) {
const config = resolveConfig(options);

logger.debug('Next.js Extension Configuration:', JSON.stringify(config, undefined, 2));
Expand Down Expand Up @@ -190,7 +189,7 @@ export async function startOnMainThread (options) {
* @param {ExtensionOptions} options
* @returns
*/
export function start (options) {
export function start (options = {}) {
const config = resolveConfig(options);

return {
Expand Down
31 changes: 31 additions & 0 deletions extension.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { describe, it, before, after } from "node:test";
import assert from "node:assert";
import child_process from 'node:child_process';

const fixtures_path = path.join(import.meta.dirname, 'fixtures');
const nextjs_app_path = path.join(fixtures_path, 'nextjs_app');

describe("nextjs_app integration test", () => {
let dir;
let hdb;
before(async () => {
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'hdb-nextjs-extension-'));
fs.cpSync(nextjs_app_path, dir, { recursive: true });

hdb = child_process.spawn('npx', ['harperdb', 'run', dir], {
cwd: dir,
stdio: 'ignore'
});
});

after(async () => {
hdb.kill();
});

it('should build and serve the Next.js app', () => {

});
});
9 changes: 9 additions & 0 deletions fixtures/nextjs_app/app/layout.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function Layout({ children }) {
return (
<html>
<body>
{children}
</body>
</html>
)
}
6 changes: 6 additions & 0 deletions fixtures/nextjs_app/app/page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const dynamic = 'force-dynamic';
export default function Page() {
return (
<h1>Hello, World!</h1>
)
}
3 changes: 3 additions & 0 deletions fixtures/nextjs_app/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'@harperdb/nextjs':
package: '@harperdb/nextjs'
files: '/*'
1 change: 1 addition & 0 deletions fixtures/nextjs_app/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
12 changes: 12 additions & 0 deletions fixtures/nextjs_app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "nextjs-app",
"scripts": {
"build": "next build"
},
"dependencies": {
"harperdb": "^4.3.20",
"next": "^14.2.6",
"react": "^18",
"react-dom": "^18"
}
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"version": "0.0.1",
"type": "module",
"files": ["config.yaml", "extension.js", "package.json", "README.md"],
"scripts": {
"test": "node --test"
},
"dependencies": {
"next": "^14.2.6",
"semver": "^7.6.3",
Expand Down