Skip to content

Commit

Permalink
test(cli): normalize EOL values when comparing snapshots
Browse files Browse the repository at this point in the history
On Windows, the actual value and the expected value loaded from the
snapshot file can use different values for line endings. As a result,
many snapshot-based tests are failing on Windows.

In this commit, I am modifying the code comparing snapshots to always
normalize line endings in both values (actual & expected).
  • Loading branch information
bajtos committed Feb 14, 2020
1 parent 9e2ffca commit 4c8cbad
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/cli/test/snapshot-matcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,16 @@ function matchSnapshot(snapshotDir, currentTest, actualValue) {
);
}

assert.deepStrictEqual(actualValue, snapshotData[key]);
// When running on Windows, `actualValue` may be using `\r\n` as EOL.
// We are normalizing snapshot data to use `\n` as EOL, but depending on
// git settings, the content can be converted during git checkout to
// use `\r\n` instead.
// For maximum safety, we normalize line endings in both actual and expected
// values.
assert.deepStrictEqual(
normalizeNewlines(actualValue),
normalizeNewlines(snapshotData[key]),
);
}

function recordSnapshot(snapshots, currentTest, actualValue) {
Expand Down

0 comments on commit 4c8cbad

Please sign in to comment.