Skip to content

Commit

Permalink
Unit whitespace in windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Machy8 committed Jan 18, 2023
1 parent 1773f9b commit e84b6b5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ jobs:
- name: Jest tests
run: yarn jest:test

#tests-windows:
# name: Tests - Windows
# runs-on: windows-latest
tests-windows:
name: Tests - Windows
runs-on: windows-latest

# steps:
# - uses: actions/checkout@v2
steps:
- uses: actions/checkout@v2

# - name: Install packages
# run: yarn repo:init
- name: Install packages
run: yarn repo:init

# - name: Build
# run: yarn build
- name: Build
run: yarn build

# - name: Jest tests
# run: yarn jest:test
- name: Jest tests
run: yarn jest:test

tests-ubuntu:
name: Tests - Ubuntu
Expand Down
27 changes: 22 additions & 5 deletions tests/TestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,18 @@ export default class TestUtils {
fs.writeFileSync(tmpFilePath, `${fileContentToSave.trim()}\n`);
}

public testToBe(actual: any, expected: any, tmpFileName: string = null): void {
this.saveTmpFile(tmpFileName, actual);
expect(actual).toBe(expected);
public testToBe(actual: any, expected: any, tmpFileName: string|null = null): void {
if (tmpFileName) {
this.saveTmpFile(tmpFileName, actual);
}
expect(this.unitWhiteSpace(actual)).toBe(this.unitWhiteSpace(expected));
}

public testMatchObject(actual: Record<any, any>, expected: Record<any, any>, tmpFileName: string = null): void {
this.saveTmpFile(tmpFileName, actual);
public testMatchObject(actual: Record<any, any>, expected: Record<any, any>, tmpFileName: string|null = null): void {
if (tmpFileName) {
this.saveTmpFile(tmpFileName, actual);
}

expect(actual).toMatchObject(expected);
}

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

private unitWhiteSpace(content: string) {
if (typeof content !== 'string') {
return content;
};

return content
.replace(/\r|\rn/g, '\n')
.replace(/\n/g, '___NEWLINE___')
.replace(/\s+/g, ' ')
.replace(/___NEWLINE___/g, '\n');
}

}

0 comments on commit e84b6b5

Please sign in to comment.