Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows and macos unit tests #172

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 79 additions & 33 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,92 @@ on:
- main

jobs:
tests:
name: Tests build
runs-on: ubuntu-latest
tests-ubuntu:
name: Tests - Ubuntu
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
steps:
- uses: actions/checkout@v3

- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v2

- uses: actions/setup-node@v3
with:
node-version: 18
cache: pnpm
- uses: actions/setup-node@v3
with:
node-version: 18
cache: pnpm

- name: Versions
run: node -v && pnpm -v
- name: Versions
run: node -v && pnpm -v

- name: Install packages
run: pnpm repo:init
- name: Install packages
run: pnpm repo:init

- name: Build
run: pnpm build
- name: Build
run: pnpm build

- name: Eslint
run: pnpm eslint:check
- name: Eslint
run: pnpm eslint:check

- name: Jest tests
run: pnpm jest:test+coverage
- name: Jest tests
run: pnpm jest:test+coverage

- name: 'Upload Artifacts'
if: ${{ failure() }}
uses: actions/upload-artifact@v3
with:
name: artifacts
path: |
packages
!node_modules
!packages/*/**/node_modules
- name: 'Upload Artifacts'
if: ${{ failure() }}
uses: actions/upload-artifact@v3
with:
name: artifacts
path: |
packages
!node_modules
!packages/*/**/node_modules

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}

tests-macos:
name: Tests - Mac OS
runs-on: macos-latest

steps:
- uses: actions/checkout@v3

- uses: pnpm/action-setup@v2

- uses: actions/setup-node@v3
with:
node-version: 18
cache: pnpm

- name: Install packages
run: pnpm repo:init

- name: Build
run: pnpm build

- name: Jest tests
run: pnpm jest:test

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

steps:
- uses: actions/checkout@v3

- uses: pnpm/action-setup@v2

- uses: actions/setup-node@v3
with:
node-version: 18
cache: pnpm

- name: Install packages
run: pnpm repo:init

- name: Build
run: pnpm build

- name: Jest tests
run: pnpm jest:test
26 changes: 21 additions & 5 deletions tests/TestUtils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
const fs = require('fs');
const path = require('path');
const os = require('os')

export default class TestUtils {

private packageName: string|null = null;

private testName: string|null = null;

private isWindowsEnv = os.platform() === 'win32'

constructor(packageName: string, testName: string) {
this.packageName = packageName;
this.testName = testName;
Expand Down Expand Up @@ -89,13 +92,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 @@ -120,4 +128,12 @@ export default class TestUtils {
this.testToBe(actualContent, this.getExpectedFile(expecedFile), expecedFile);
}

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

return content.replace(/\s+/g, ' ');
}

}
Loading