Skip to content
This repository was archived by the owner on Sep 28, 2025. It is now read-only.

Commit 4f93a34

Browse files
committed
Run 'next build' during plugin-next test to make it pass correctly
1 parent 25fa8aa commit 4f93a34

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const { spawn } = require('child_process');
2+
3+
exports.exec = async ({ workdir, command, args }) => {
4+
return new Promise((resolve, reject) => {
5+
const proc = spawn(command, args, { cwd: workdir });
6+
const log = [];
7+
const errorLog = [];
8+
proc.stdout.on('data', (data) => {
9+
const message = data.toString();
10+
log.push(message);
11+
});
12+
proc.stderr.on('data', (data) => {
13+
const message = data.toString();
14+
errorLog.push(message);
15+
});
16+
proc.on('exit', (code) => {
17+
if (errorLog.length > 0 || code !== 0) {
18+
reject({ code: code.toString(), log, errorLog });
19+
} else {
20+
resolve({ code: code.toString(), log, errorLog });
21+
}
22+
});
23+
});
24+
};

packages/graffiti/test/plugin.next.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
const path = require('path');
33
const { build } = require('../lib');
44
const { executeGraphql } = require('./helpers/graphql');
5+
const { exec } = require('./helpers/exec');
56
const { CREATE_NOTE_QUERY } = require('./fixtures/queries.basic');
67

78
// mock current workdir
@@ -31,6 +32,8 @@ const testNote = { name: 'test note', body: 'test note body' };
3132
afterAll(() => server?.close());
3233

3334
beforeAll(async () => {
35+
// run "next build" in project workdirn
36+
await exec({ workdir: testPath, command: 'npx', args: ['next', 'build'] });
3437
// build new server
3538
const fastifyServer = await build();
3639
server = fastifyServer;

0 commit comments

Comments
 (0)