Skip to content

Commit

Permalink
test: fix test on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
EnixCoda committed Jul 7, 2024
1 parent 73e3906 commit 6e566f8
Show file tree
Hide file tree
Showing 16 changed files with 1,336 additions and 827 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* Confirm basic behaviors of puppeteer assertions
*/

import { testURL } from '../../testURL'
import { expectToFind, expectToNotFind } from '../../utils'
import { testURL } from '../testURL'
import { expectToFind, expectToNotFind, expectToReject } from '../utils'

describe(`in random page`, () => {
beforeAll(() => page.goto(testURL`https://google.com`))
Expand All @@ -23,7 +23,7 @@ describe(`in random page`, () => {
})

it('wait for non-exist element reject should throw', async () => {
await expect(page.waitForSelector('.non-exist-element', { timeout: 1000 })).rejects.toThrow()
await expectToReject(page.waitForSelector('.non-exist-element', { timeout: 1000 }))
})

// Cases below are expected to fail to show how async test works
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { selectors } from '../../selectors'
import { testURL } from '../../testURL'
import { getTextContent, sleep } from '../../utils'
import { selectors } from '../selectors'
import { testURL } from '../testURL'
import { getTextContent, sleep } from '../utils'

describe(`in Gitako project page`, () => {
beforeAll(() => page.goto(testURL`https://github.com/GitakoExtension/test-empty`))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { selectors } from '../../selectors'
import { testURL } from '../../testURL'
import { expectToFind, sleep, waitForRedirect } from '../../utils'
import { selectors } from '../selectors'
import { testURL } from '../testURL'
import { expectToFind, sleep, waitForRedirect } from '../utils'

describe(`in Gitako project page`, () => {
beforeAll(() => page.goto(testURL`https://github.com/EnixCoda/Gitako/tree/develop/src`))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { testURL } from '../../testURL'
import { expectToNotFind } from '../../utils'
import { testURL } from '../testURL'
import { expectToNotFind } from '../utils'

describe(`in GitHub homepage`, () => {
beforeAll(() => page.goto(testURL`https://github.com`))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { selectors } from '../../selectors'
import { testURL } from '../../testURL'
import { expectToFind, expectToNotFind, sleep, waitForRedirect } from '../../utils'
import { selectors } from '../selectors'
import { testURL } from '../testURL'
import { expectToFind, expectToNotFind, sleep, waitForRedirect } from '../utils'

jest.retryTimes(3)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { selectors } from '../../selectors'
import { testURL } from '../../testURL'
import { expectToFind, expectToNotFind, sleep, waitForRedirect } from '../../utils'
import { selectors } from '../selectors'
import { testURL } from '../testURL'
import { expectToFind, expectToNotFind, sleep, waitForRedirect } from '../utils'

jest.retryTimes(3)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { selectors } from '../../selectors'
import { testURL } from '../../testURL'
import { selectors } from '../selectors'
import { testURL } from '../testURL'
import {
collapseFloatModeSidebar,
expandFloatModeSidebar,
getTextContent,
patientClick,
sleep,
waitForRedirect,
} from '../../utils'
} from '../utils'

jest.retryTimes(3)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { selectors } from '../../selectors'
import { testURL } from '../../testURL'
import { selectors } from '../selectors'
import { testURL } from '../testURL'
import {
expandFloatModeSidebar,
expectToFind,
expectToNotFind,
patientClick,
sleep,
waitForRedirect,
} from '../../utils'
} from '../utils'

jest.retryTimes(3)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { selectors } from '../../selectors'
import { testURL } from '../../testURL'
import { expandFloatModeSidebar, expectToFind, expectToNotFind, scroll } from '../../utils'
import { selectors } from '../selectors'
import { testURL } from '../testURL'
import { expandFloatModeSidebar, expectToFind, expectToNotFind, scroll } from '../utils'

jest.retryTimes(3)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { selectors } from '../../selectors'
import { testURL } from '../../testURL'
import { expectToFind } from '../../utils'
import { selectors } from '../selectors'
import { testURL } from '../testURL'
import { expectToFind } from '../utils'

describe(`in Gitako project page`, () => {
beforeAll(() => page.goto(testURL`https://github.com/EnixCoda/Gitako/pull/71`))
Expand Down
11 changes: 0 additions & 11 deletions __tests__/jest.non-parallel.config.js

This file was deleted.

6 changes: 0 additions & 6 deletions __tests__/jest.parallel.config.js

This file was deleted.

7 changes: 7 additions & 0 deletions __tests__/jest.puppeteer.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const baseConfig = require('./jest.config')

module.exports = {
...baseConfig,
testMatch: [...baseConfig.testMatch, '**/__tests__/cases/**/*.ts?(x)'],
setupFilesAfterEnv: ['<rootDir>/setup.ts'],
}
16 changes: 14 additions & 2 deletions __tests__/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
export async function expectToResolve<T>(promise: Promise<T>) {
const pass = jest.fn()
await promise.then(pass)
expect(pass).toHaveBeenCalled()
}

export async function expectToReject<T>(promise: Promise<T>) {
const pass = jest.fn()
await promise.catch(pass)
expect(pass).toHaveBeenCalled()
}

export async function expectToFind(selector: string) {
await expect(page.waitForSelector(selector)).resolves.not.toBeNull()
await expectToResolve(page.waitForSelector(selector))
}

export async function expectToNotFind(selector: string) {
await expect(page.waitForSelector(selector, { timeout: 1000 })).rejects.toThrow()
await expectToReject(page.waitForSelector(selector, { timeout: 1000 }))
}

export function sleep(timeout: number) {
Expand Down
18 changes: 8 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
"postversion": "sh scripts/post-version.sh",
"build": "NODE_OPTIONS=--openssl-legacy-provider VERSION=v$(node scripts/get-version.js) NODE_ENV=production webpack",
"roll": "make release",
"test": "yarn run test:parallel && yarn run test:non-parallel",
"test:unit": "NODE_ENV=test jest --config jest.config.js",
"test:parallel": "NODE_ENV=test jest --config __tests__/jest.parallel.config.js",
"test:non-parallel": "NODE_ENV=test jest --config __tests__/jest.non-parallel.config.js"
"test": "NODE_ENV=test jest --config __tests__/jest.puppeteer.config.js",
"test:unit": "NODE_ENV=test jest --config jest.config.js"
},
"dependencies": {
"@primer/css": "^20.4.3",
Expand Down Expand Up @@ -61,9 +59,9 @@
"@sentry/cli": "^1.64.2",
"@testing-library/react": "^13.3.0",
"@types/firefox-webext-browser": "^70.0.1",
"@types/jest": "^29.2.2",
"@types/jest": "^29.5.12",
"@types/node": "^11.10.4",
"@types/puppeteer": "^5.4.3",
"@types/puppeteer": "^7.0.4",
"@typescript-eslint/eslint-plugin": "^5.33.1",
"@typescript-eslint/parser": "^5.33.1",
"babel-loader": "^8.2.5",
Expand All @@ -79,14 +77,14 @@
"file-loader": "^3.0.1",
"fork-ts-checker-webpack-plugin": "^6.5.0",
"husky": "^8.0.1",
"jest": "^29.2.2",
"jest-environment-jsdom": "^29.2.2",
"jest-puppeteer": "^6.1.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-puppeteer": "^10.0.1",
"json-loader": "^0.5.7",
"lint-staged": "^13.0.3",
"mini-css-extract-plugin": "^0.9.0",
"prettier": "^2.8.3",
"puppeteer": "^10.1.0",
"puppeteer": "^22.12.1",
"raw-loader": "^4.0.0",
"sass": "^1.26.2",
"sass-loader": "^8.0.2",
Expand Down
Loading

0 comments on commit 6e566f8

Please sign in to comment.