Skip to content

Commit 7a78abd

Browse files
committed
chore: fix tests on windows
1 parent 6df1555 commit 7a78abd

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

test/helpers/playwright-custom-expects.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
"use strict";
22

33
const path = require("path");
4+
const os = require("os");
45
const { test, expect, mergeExpects } = require("@playwright/test");
56

7+
/**
8+
* Returns a new string with all the EOL markers from the string passed in
9+
* replaced with the Operating System specific EOL marker.
10+
* Useful for guaranteeing two transform outputs have the same EOL marker format.
11+
* @param {string} input the string which will have its EOL markers replaced
12+
* @returns {string} a new string with all EOL markers replaced
13+
* @private
14+
*/
15+
const normalizeLineEndings = (input) => {
16+
return input.replace(/(\r\n|\n|\r)/gmu, os.EOL);
17+
};
18+
619
/**
720
* Custom Playwright matcher to match a snapshot with an array.
821
*
@@ -37,7 +50,7 @@ const toMatchSnapshotWithArray = expect.extend({
3750
);
3851

3952
try {
40-
const serialized = JSON.stringify(received);
53+
const serialized = normalizeLineEndings(JSON.stringify(received));
4154
await expect(serialized).toMatchSnapshot({
4255
name: snapshotFilePath,
4356
});

0 commit comments

Comments
 (0)