| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 87f78a3 commit 99566ae
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -60,13 +60,14 @@ function checkOutput(str, check) { | |||
| 60 | 60 | return { passed: true }; | |
| 61 | 61 | } | |
| 62 | 62 | ||
| 63 | - function expectSyncExit(child, { | ||
| 63 | + function expectSyncExit(caller, spawnArgs, { | ||
| 64 | 64 | status, | |
| 65 | 65 | signal, | |
| 66 | 66 | stderr: stderrCheck, | |
| 67 | 67 | stdout: stdoutCheck, | |
| 68 | 68 | trim = false, | |
| 69 | 69 | }) { | |
| 70 | + const child = spawnSync(...spawnArgs); | ||
| 70 | 71 | const failures = []; | |
| 71 | 72 | let stderrStr, stdoutStr; | |
| 72 | 73 | if (status !== undefined && child.status !== status) { | |
@@ -83,7 +84,18 @@ function expectSyncExit(child, { | |||
| 83 | 84 | console.error(`${tag} --- stdout ---`); | |
| 84 | 85 | console.error(stdoutStr === undefined ? child.stdout.toString() : stdoutStr); | |
| 85 | 86 | console.error(`${tag} status = ${child.status}, signal = ${child.signal}`); | |
| 86 | - throw new Error(`${failures.join('\n')}`); | ||
| 87 | + | ||
| 88 | + const error = new Error(`${failures.join('\n')}`); | ||
| 89 | + if (spawnArgs[2]) { | ||
| 90 | + error.options = spawnArgs[2]; | ||
| 91 | + } | ||
| 92 | + let command = spawnArgs[0]; | ||
| 93 | + if (Array.isArray(spawnArgs[1])) { | ||
| 94 | + command += ' ' + spawnArgs[1].join(' '); | ||
| 95 | + } | ||
| 96 | + error.command = command; | ||
| 97 | + Error.captureStackTrace(error, caller); | ||
| 98 | + throw error; | ||
| 87 | 99 | } | |
| 88 | 100 | ||
| 89 | 101 | // If status and signal are not matching expectations, fail early. | |
@@ -114,21 +126,19 @@ function expectSyncExit(child, { | |||
| 114 | 126 | function spawnSyncAndExit(...args) { | |
| 115 | 127 | const spawnArgs = args.slice(0, args.length - 1); | |
| 116 | 128 | const expectations = args[args.length - 1]; | |
| 117 | - const child = spawnSync(...spawnArgs); | ||
| 118 | - return expectSyncExit(child, expectations); | ||
| 129 | + return expectSyncExit(spawnSyncAndExit, spawnArgs, expectations); | ||
| 119 | 130 | } | |
| 120 | 131 | ||
| 121 | 132 | function spawnSyncAndExitWithoutError(...args) { | |
| 122 | - return expectSyncExit(spawnSync(...args), { | ||
| 133 | + return expectSyncExit(spawnSyncAndExitWithoutError, [...args], { | ||
| 123 | 134 | status: 0, | |
| 124 | 135 | signal: null, | |
| 125 | 136 | }); | |
| 126 | 137 | } | |
| 127 | 138 | ||
| 128 | 139 | function spawnSyncAndAssert(...args) { | |
| 129 | 140 | const expectations = args.pop(); | |
| 130 | - const child = spawnSync(...args); | ||
| 131 | - return expectSyncExit(child, { | ||
| 141 | + return expectSyncExit(spawnSyncAndAssert, [...args], { | ||
| 132 | 142 | status: 0, | |
| 133 | 143 | signal: null, | |
| 134 | 144 | ...expectations, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments