Skip to content

Commit

Permalink
Improve debug message when json parsing fails in e2e tests (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
BPScott authored Nov 29, 2024
1 parent a9056ce commit 286e6a1
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions test/stylelint-prettier-e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,17 @@ function runStylelint(pattern) {
const result = spawnSync(stylelintCmd, ['--formatter=json', pattern], {
cwd: stylelintCwd,
});

const jsonErrors = JSON.parse(result.stderr.toString().trim());
const resultContent = result.stderr.toString().trim();

let jsonErrors;
try {
jsonErrors = JSON.parse(resultContent);
} catch (err) {
throw new Error(
`Could not parse json from stderr. Attempted to parse:\n${resultContent}`,
{cause: err}
);
}

const errorLines = [];

Expand Down

0 comments on commit 286e6a1

Please sign in to comment.