File tree 1 file changed +14
-1
lines changed
1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change 1
1
"use strict" ;
2
2
3
3
const path = require ( "path" ) ;
4
+ const os = require ( "os" ) ;
4
5
const { test, expect, mergeExpects } = require ( "@playwright/test" ) ;
5
6
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
+
6
19
/**
7
20
* Custom Playwright matcher to match a snapshot with an array.
8
21
*
@@ -37,7 +50,7 @@ const toMatchSnapshotWithArray = expect.extend({
37
50
) ;
38
51
39
52
try {
40
- const serialized = JSON . stringify ( received ) ;
53
+ const serialized = normalizeLineEndings ( JSON . stringify ( received ) ) ;
41
54
await expect ( serialized ) . toMatchSnapshot ( {
42
55
name : snapshotFilePath ,
43
56
} ) ;
You can’t perform that action at this time.
0 commit comments