Skip to content

Commit 269d6aa

Browse files
resources/util: spawn command fail on error (#3745)
1 parent 87d003d commit 269d6aa

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

integrationTests/node/index.cjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const assert = require('assert');
2+
const { readFileSync } = require('fs');
3+
4+
const { graphqlSync } = require('graphql');
5+
const { buildSchema } = require('graphql/utilities');
6+
const { version } = require('graphql/version');
7+
8+
assert.deepStrictEqual(
9+
version,
10+
JSON.parse(readFileSync('./node_modules/graphql/package.json')).version,
11+
);
12+
13+
const schema = buildSchema('type Query { hello: String }');
14+
15+
const result = graphqlSync({
16+
schema,
17+
source: '{ hello }',
18+
rootValue: { hello: 'world' },
19+
});
20+
21+
assert.deepStrictEqual(result, {
22+
data: {
23+
__proto__: null,
24+
hello: 'world',
25+
},
26+
});

resources/utils.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ function spawnOutput(
9999
encoding: 'utf-8',
100100
...options,
101101
});
102+
103+
if (result.status !== 0) {
104+
throw new Error(`Command failed: ${command} ${args.join(' ')}`);
105+
}
106+
102107
return result.stdout.toString().trimEnd();
103108
}
104109

@@ -107,7 +112,13 @@ function spawn(
107112
args: ReadonlyArray<string>,
108113
options?: SpawnOptions,
109114
): void {
110-
childProcess.spawnSync(command, args, { stdio: 'inherit', ...options });
115+
const result = childProcess.spawnSync(command, args, {
116+
stdio: 'inherit',
117+
...options,
118+
});
119+
if (result.status !== 0) {
120+
throw new Error(`Command failed: ${command} ${args.join(' ')}`);
121+
}
111122
}
112123

113124
function* readdirRecursive(dirPath: string): Generator<{

0 commit comments

Comments
 (0)