Skip to content

Commit

Permalink
Update github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
trurl-master committed Jul 30, 2022
1 parent d699db1 commit 824062f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 15 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
name: CI
name: Validate

on: [push]

jobs:
build:
name: Build, lint, and test on Node ${{ matrix.node }} and ${{ matrix.os }}

runs-on: ${{ matrix.os }}
strategy:
matrix:
node: ['12.x', '14.x', '16.x']
node: ['14.x', '16.x', '18.x']
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
Expand All @@ -21,12 +23,16 @@ jobs:

- name: Install deps and build (with cache)
uses: bahmutov/npm-install@v1
with:
working-directory: |
.
examples
- name: Lint
run: npm run lint

- name: Test
run: npm run test --ci --coverage --maxWorkers=2
run: npm run test:all --ci --coverage --maxWorkers=2

- name: Build
run: npm run build
29 changes: 26 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ on:
types: [published]

jobs:
publish-npm:
name: 'Publish to npm'
publish:
name: 'Publish'
runs-on: ubuntu-latest
if: "!contains(github.ref_name, 'beta')"
steps:
- uses: actions/checkout@v2

Expand All @@ -17,10 +18,32 @@ jobs:
node-version: 'lts/*'
registry-url: https://registry.npmjs.org/

- run: npm run install
- name: Install deps and build (with cache)
uses: bahmutov/npm-install@v1

- run: npm run build

- run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

publish_beta:
name: 'Publish beta'
runs-on: ubuntu-latest
if: contains(github.ref_name, 'beta')
steps:
- uses: actions/checkout@v2

- uses: actions/setup-node@v2
with:
node-version: 'lts/*'
registry-url: https://registry.npmjs.org/

- name: Install deps and build (with cache)
uses: bahmutov/npm-install@v1

- run: npm run build

- run: npm publish --tag beta --access public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
7 changes: 3 additions & 4 deletions examples/src/tests/viewport.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { render, act, screen } from '@testing-library/react';

import { mockViewport, mockViewportForTestGroup } from '../../../dist';
import { MockedMediaQueryListEvent } from '../../../src/mocks/MediaQueryListEvent';

import CustomUseMedia from '../components/viewport/custom-use-media/CustomUseMedia';
import DeprecatedUseMedia from '../components/viewport/deprecated-use-media/DeprecatedUseMedia';
Expand Down Expand Up @@ -77,7 +76,7 @@ describe('mockViewport', () => {
expect(screen.getByText('not desktop')).toBeInTheDocument();
expect(screen.queryByText('desktop')).not.toBeInTheDocument();
expect(cb).toHaveBeenCalledTimes(1);
expect(event).toBeInstanceOf(MockedMediaQueryListEvent);
expect(event).toBeInstanceOf(MediaQueryListEvent);
expect(event.media).toBe('(min-width: 640px)');
expect(event.matches).toBe(false);

Expand All @@ -101,7 +100,7 @@ describe('mockViewport', () => {
const [event] = cb.mock.calls[0];

expect(cb).toHaveBeenCalledTimes(1);
expect(event).toBeInstanceOf(MockedMediaQueryListEvent);
expect(event).toBeInstanceOf(MediaQueryListEvent);
expect(event.media).toBe('(min-width: 640px)');
expect(event.matches).toBe(false);

Expand All @@ -125,7 +124,7 @@ describe('mockViewport', () => {
const [event] = cb.mock.calls[0];

expect(cb).toHaveBeenCalledTimes(1);
expect(event).toBeInstanceOf(MockedMediaQueryListEvent);
expect(event).toBeInstanceOf(MediaQueryListEvent);
expect(event.media).toBe('(min-width: 640px)');
expect(event.matches).toBe(false);

Expand Down
1 change: 1 addition & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
setupFilesAfterEnv: ['<rootDir>/jest-setup.ts'],
testPathIgnorePatterns: ['/node_modules/', '/examples/'],
globals: {
'ts-jest': {
tsconfig: {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jsdom-testing-mocks",
"version": "1.5.0-beta.1",
"version": "1.5.0-beta.5",
"author": "Ivan Galiatin",
"license": "MIT",
"description": "A set of tools for emulating browser behavior in jsdom environment",
Expand Down Expand Up @@ -33,6 +33,8 @@
"start": "tsup --watch",
"build": "tsup",
"test": "jest",
"test:examples": "npm --prefix ./examples run test",
"test:all": "npm run test && npm run test:examples",
"lint": "eslint src/ --ext .ts,.tsx",
"prepare": "tsup"
},
Expand Down
8 changes: 4 additions & 4 deletions src/mocks/viewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type ListenerOrListenerObject = Listener | ListenerObject;
function isEventListenerObject(
obj: ListenerOrListenerObject
): obj is ListenerObject {
return (obj as any).handleEvent !== undefined;
return (obj as ListenerObject).handleEvent !== undefined;
}

function mockViewport(desc: ViewportDescription): MockViewport {
Expand Down Expand Up @@ -104,17 +104,17 @@ function mockViewport(desc: ViewportDescription): MockViewport {
},
media: query,
onchange: null,
addListener: function(listener) {
addListener: function (listener) {
if (listener) {
addOldListener(this, this.matches, listener);
}
}, // deprecated
removeListener: listener => {
removeListener: (listener) => {
if (listener) {
removeOldListener(listener);
}
}, // deprecated
addEventListener: function(
addEventListener: function (
eventType: Parameters<MediaQueryList['addEventListener']>[0],
listener: Parameters<MediaQueryList['addEventListener']>[1]
) {
Expand Down

0 comments on commit 824062f

Please sign in to comment.