Skip to content

Commit

Permalink
Run 'next build' during plugin-next test to make it pass correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
yamalight committed Sep 14, 2020
1 parent 25fa8aa commit 4f93a34
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/graffiti/test/helpers/exec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const { spawn } = require('child_process');

exports.exec = async ({ workdir, command, args }) => {
return new Promise((resolve, reject) => {
const proc = spawn(command, args, { cwd: workdir });
const log = [];
const errorLog = [];
proc.stdout.on('data', (data) => {
const message = data.toString();
log.push(message);
});
proc.stderr.on('data', (data) => {
const message = data.toString();
errorLog.push(message);
});
proc.on('exit', (code) => {
if (errorLog.length > 0 || code !== 0) {
reject({ code: code.toString(), log, errorLog });
} else {
resolve({ code: code.toString(), log, errorLog });
}
});
});
};
3 changes: 3 additions & 0 deletions packages/graffiti/test/plugin.next.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const path = require('path');
const { build } = require('../lib');
const { executeGraphql } = require('./helpers/graphql');
const { exec } = require('./helpers/exec');
const { CREATE_NOTE_QUERY } = require('./fixtures/queries.basic');

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

beforeAll(async () => {
// run "next build" in project workdirn
await exec({ workdir: testPath, command: 'npx', args: ['next', 'build'] });
// build new server
const fastifyServer = await build();
server = fastifyServer;
Expand Down

0 comments on commit 4f93a34

Please sign in to comment.