Skip to content

Commit 286e6a1

Browse files
authored
Improve debug message when json parsing fails in e2e tests (#376)
1 parent a9056ce commit 286e6a1

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

test/stylelint-prettier-e2e.test.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,17 @@ function runStylelint(pattern) {
113113
const result = spawnSync(stylelintCmd, ['--formatter=json', pattern], {
114114
cwd: stylelintCwd,
115115
});
116-
117-
const jsonErrors = JSON.parse(result.stderr.toString().trim());
116+
const resultContent = result.stderr.toString().trim();
117+
118+
let jsonErrors;
119+
try {
120+
jsonErrors = JSON.parse(resultContent);
121+
} catch (err) {
122+
throw new Error(
123+
`Could not parse json from stderr. Attempted to parse:\n${resultContent}`,
124+
{cause: err}
125+
);
126+
}
118127

119128
const errorLines = [];
120129

0 commit comments

Comments
 (0)