Skip to content

Commit

Permalink
resources/util: spawn command fail on error (#3745)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Sep 21, 2022
1 parent 87d003d commit 269d6aa
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
26 changes: 26 additions & 0 deletions integrationTests/node/index.cjs
@@ -0,0 +1,26 @@
const assert = require('assert');
const { readFileSync } = require('fs');

const { graphqlSync } = require('graphql');
const { buildSchema } = require('graphql/utilities');
const { version } = require('graphql/version');

assert.deepStrictEqual(
version,
JSON.parse(readFileSync('./node_modules/graphql/package.json')).version,
);

const schema = buildSchema('type Query { hello: String }');

const result = graphqlSync({
schema,
source: '{ hello }',
rootValue: { hello: 'world' },
});

assert.deepStrictEqual(result, {
data: {
__proto__: null,
hello: 'world',
},
});
13 changes: 12 additions & 1 deletion resources/utils.ts
Expand Up @@ -99,6 +99,11 @@ function spawnOutput(
encoding: 'utf-8',
...options,
});

if (result.status !== 0) {
throw new Error(`Command failed: ${command} ${args.join(' ')}`);
}

return result.stdout.toString().trimEnd();
}

Expand All @@ -107,7 +112,13 @@ function spawn(
args: ReadonlyArray<string>,
options?: SpawnOptions,
): void {
childProcess.spawnSync(command, args, { stdio: 'inherit', ...options });
const result = childProcess.spawnSync(command, args, {
stdio: 'inherit',
...options,
});
if (result.status !== 0) {
throw new Error(`Command failed: ${command} ${args.join(' ')}`);
}
}

function* readdirRecursive(dirPath: string): Generator<{
Expand Down

0 comments on commit 269d6aa

Please sign in to comment.