test: 💍 修正测试用例中对实际和期望的 diff 的逻辑

This commit is contained in:
牧毅 2020-08-12 10:54:35 +08:00
parent a66ec82879
commit c46af6376f

View File

@ -31,11 +31,9 @@ function defineTest(caseDirName: string) {
runPrettierSync(actualFiles, actualDir); runPrettierSync(actualFiles, actualDir);
const diffRes = diffActualAndExpectedSync(caseFullDir); const differences = diffActualAndExpectedSync(caseFullDir);
if (diffRes) { if (differences) {
t.fail(diffRes); t.fail(differences);
} else {
t.pass();
} }
} catch (e) { } catch (e) {
throw e; // just for debugger throw e; // just for debugger
@ -64,8 +62,11 @@ function runPrettierSync(files: string[], cwd: string) {
} }
function diffActualAndExpectedSync(caseFullDir: string): string { function diffActualAndExpectedSync(caseFullDir: string): string {
const res = ensureShellExec('diff', ['-wur', 'expected', 'actual'], { const res = spawnSync('diff', ['-wur', 'expected', 'actual'], {
cwd: caseFullDir, cwd: caseFullDir,
stdio: 'pipe',
shell: true,
encoding: 'utf-8',
}); });
return colorizeDiffOutput(res.stdout); return colorizeDiffOutput(res.stdout);
@ -84,7 +85,7 @@ function ensureShellExec(
}); });
if (res.status !== 0) { if (res.status !== 0) {
throw new Error(`Shell command "${shellCmd}" failed with status: ${res.status}`); throw new Error(`Shell command "${shellCmd} ${args.slice(0,2).join(' ')}..." failed with status: ${res.status} (Full command: "${shellCmd} ${args.join(' ')}" )`);
} }
return res; return res;