From 824062fee49f19b255af50a57d96762b778a2259 Mon Sep 17 00:00:00 2001 From: Ivan Galiatin Date: Sat, 30 Jul 2022 17:02:00 +0200 Subject: [PATCH] Update github actions --- .github/workflows/main.yml | 12 +++++++++--- .github/workflows/publish.yml | 29 +++++++++++++++++++++++++--- examples/src/tests/viewport.test.tsx | 7 +++---- jest.config.ts | 1 + package.json | 4 +++- src/mocks/viewport.ts | 8 ++++---- 6 files changed, 46 insertions(+), 15 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c319156..225c601 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,5 +1,7 @@ -name: CI +name: Validate + on: [push] + jobs: build: name: Build, lint, and test on Node ${{ matrix.node }} and ${{ matrix.os }} @@ -7,7 +9,7 @@ jobs: 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: @@ -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 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 26a5da4..2e25842 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -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 @@ -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}} diff --git a/examples/src/tests/viewport.test.tsx b/examples/src/tests/viewport.test.tsx index df29b58..525fe45 100644 --- a/examples/src/tests/viewport.test.tsx +++ b/examples/src/tests/viewport.test.tsx @@ -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'; @@ -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); @@ -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); @@ -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); diff --git a/jest.config.ts b/jest.config.ts index ae6727e..3bceb33 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -3,6 +3,7 @@ module.exports = { preset: 'ts-jest', testEnvironment: 'jsdom', setupFilesAfterEnv: ['/jest-setup.ts'], + testPathIgnorePatterns: ['/node_modules/', '/examples/'], globals: { 'ts-jest': { tsconfig: { diff --git a/package.json b/package.json index 54fb1db..bf500b3 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" }, diff --git a/src/mocks/viewport.ts b/src/mocks/viewport.ts index 85215fb..d4dfb6e 100644 --- a/src/mocks/viewport.ts +++ b/src/mocks/viewport.ts @@ -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 { @@ -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[0], listener: Parameters[1] ) {