Skip to content

Commit 0250d4f

Browse files
committed
Windows and macos unit tests
1 parent 1140bfc commit 0250d4f

File tree

2 files changed

+100
-38
lines changed

2 files changed

+100
-38
lines changed

.github/workflows/tests.yaml

Lines changed: 79 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,46 +9,92 @@ on:
99
- main
1010

1111
jobs:
12-
tests:
13-
name: Tests build
14-
runs-on: ubuntu-latest
12+
tests-ubuntu:
13+
name: Tests - Ubuntu
14+
runs-on: ubuntu-latest
1515

16-
steps:
17-
- uses: actions/checkout@v3
16+
steps:
17+
- uses: actions/checkout@v3
1818

19-
- uses: pnpm/action-setup@v2
19+
- uses: pnpm/action-setup@v2
2020

21-
- uses: actions/setup-node@v3
22-
with:
23-
node-version: 18
24-
cache: pnpm
21+
- uses: actions/setup-node@v3
22+
with:
23+
node-version: 18
24+
cache: pnpm
2525

26-
- name: Versions
27-
run: node -v && pnpm -v
26+
- name: Versions
27+
run: node -v && pnpm -v
2828

29-
- name: Install packages
30-
run: pnpm repo:init
29+
- name: Install packages
30+
run: pnpm repo:init
3131

32-
- name: Build
33-
run: pnpm build
32+
- name: Build
33+
run: pnpm build
3434

35-
- name: Eslint
36-
run: pnpm eslint:check
35+
- name: Eslint
36+
run: pnpm eslint:check
3737

38-
- name: Jest tests
39-
run: pnpm jest:test+coverage
38+
- name: Jest tests
39+
run: pnpm jest:test+coverage
4040

41-
- name: 'Upload Artifacts'
42-
if: ${{ failure() }}
43-
uses: actions/upload-artifact@v3
44-
with:
45-
name: artifacts
46-
path: |
47-
packages
48-
!node_modules
49-
!packages/*/**/node_modules
41+
- name: 'Upload Artifacts'
42+
if: ${{ failure() }}
43+
uses: actions/upload-artifact@v3
44+
with:
45+
name: artifacts
46+
path: |
47+
packages
48+
!node_modules
49+
!packages/*/**/node_modules
5050
51-
- name: Upload coverage to Codecov
52-
uses: codecov/codecov-action@v1
53-
with:
54-
token: ${{ secrets.CODECOV_TOKEN }}
51+
- name: Upload coverage to Codecov
52+
uses: codecov/codecov-action@v1
53+
with:
54+
token: ${{ secrets.CODECOV_TOKEN }}
55+
56+
tests-macos:
57+
name: Tests - Mac OS
58+
runs-on: macos-latest
59+
60+
steps:
61+
- uses: actions/checkout@v3
62+
63+
- uses: pnpm/action-setup@v2
64+
65+
- uses: actions/setup-node@v3
66+
with:
67+
node-version: 18
68+
cache: pnpm
69+
70+
- name: Install packages
71+
run: pnpm repo:init
72+
73+
- name: Build
74+
run: pnpm build
75+
76+
- name: Jest tests
77+
run: pnpm jest:test
78+
79+
tests-windows:
80+
name: Tests - Windows
81+
runs-on: windows-latest
82+
83+
steps:
84+
- uses: actions/checkout@v3
85+
86+
- uses: pnpm/action-setup@v2
87+
88+
- uses: actions/setup-node@v3
89+
with:
90+
node-version: 18
91+
cache: pnpm
92+
93+
- name: Install packages
94+
run: pnpm repo:init
95+
96+
- name: Build
97+
run: pnpm build
98+
99+
- name: Jest tests
100+
run: pnpm jest:test

tests/TestUtils.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
const fs = require('fs');
22
const path = require('path');
3+
const os = require('os')
34

45
export default class TestUtils {
56

67
private packageName: string|null = null;
78

89
private testName: string|null = null;
910

11+
private isWindowsEnv = os.platform() === 'win32'
12+
1013
constructor(packageName: string, testName: string) {
1114
this.packageName = packageName;
1215
this.testName = testName;
@@ -89,13 +92,18 @@ export default class TestUtils {
8992
fs.writeFileSync(tmpFilePath, `${fileContentToSave.trim()}\n`);
9093
}
9194

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

97-
public testMatchObject(actual: Record<any, any>, expected: Record<any, any>, tmpFileName: string = null): void {
98-
this.saveTmpFile(tmpFileName, actual);
102+
public testMatchObject(actual: Record<any, any>, expected: Record<any, any>, tmpFileName: string|null = null): void {
103+
if (tmpFileName) {
104+
this.saveTmpFile(tmpFileName, actual);
105+
}
106+
99107
expect(actual).toMatchObject(expected);
100108
}
101109

@@ -120,4 +128,12 @@ export default class TestUtils {
120128
this.testToBe(actualContent, this.getExpectedFile(expecedFile), expecedFile);
121129
}
122130

131+
private unitWhiteSpace(content: string) {
132+
if (typeof content !== 'string' || !this.isWindowsEnv) {
133+
return content;
134+
};
135+
136+
return content.replace(/\s+/g, ' ');
137+
}
138+
123139
}

0 commit comments

Comments
 (0)