Skip to content

Commit e84b6b5

Browse files
committed
Unit whitespace in windows
1 parent 1773f9b commit e84b6b5

2 files changed

Lines changed: 33 additions & 16 deletions

File tree

.github/workflows/tests.yaml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@ jobs:
2525
- name: Jest tests
2626
run: yarn jest:test
2727

28-
#tests-windows:
29-
# name: Tests - Windows
30-
# runs-on: windows-latest
28+
tests-windows:
29+
name: Tests - Windows
30+
runs-on: windows-latest
3131

32-
# steps:
33-
# - uses: actions/checkout@v2
32+
steps:
33+
- uses: actions/checkout@v2
3434

35-
# - name: Install packages
36-
# run: yarn repo:init
35+
- name: Install packages
36+
run: yarn repo:init
3737

38-
# - name: Build
39-
# run: yarn build
38+
- name: Build
39+
run: yarn build
4040

41-
# - name: Jest tests
42-
# run: yarn jest:test
41+
- name: Jest tests
42+
run: yarn jest:test
4343

4444
tests-ubuntu:
4545
name: Tests - Ubuntu

tests/TestUtils.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,18 @@ export default class TestUtils {
8989
fs.writeFileSync(tmpFilePath, `${fileContentToSave.trim()}\n`);
9090
}
9191

92-
public testToBe(actual: any, expected: any, tmpFileName: string = null): void {
93-
this.saveTmpFile(tmpFileName, actual);
94-
expect(actual).toBe(expected);
92+
public testToBe(actual: any, expected: any, tmpFileName: string|null = null): void {
93+
if (tmpFileName) {
94+
this.saveTmpFile(tmpFileName, actual);
95+
}
96+
expect(this.unitWhiteSpace(actual)).toBe(this.unitWhiteSpace(expected));
9597
}
9698

97-
public testMatchObject(actual: Record<any, any>, expected: Record<any, any>, tmpFileName: string = null): void {
98-
this.saveTmpFile(tmpFileName, actual);
99+
public testMatchObject(actual: Record<any, any>, expected: Record<any, any>, tmpFileName: string|null = null): void {
100+
if (tmpFileName) {
101+
this.saveTmpFile(tmpFileName, actual);
102+
}
103+
99104
expect(actual).toMatchObject(expected);
100105
}
101106

@@ -119,4 +124,16 @@ export default class TestUtils {
119124
this.testToBe(actualContent, this.getExpectedFile(`${expectedFileName}.${suffix}`), `${expectedFileName}.${suffix}`);
120125
}
121126

127+
private unitWhiteSpace(content: string) {
128+
if (typeof content !== 'string') {
129+
return content;
130+
};
131+
132+
return content
133+
.replace(/\r|\rn/g, '\n')
134+
.replace(/\n/g, '___NEWLINE___')
135+
.replace(/\s+/g, ' ')
136+
.replace(/___NEWLINE___/g, '\n');
137+
}
138+
122139
}

0 commit comments

Comments
 (0)