test: fix test on macOS

This commit is contained in:
EnixCoda 2024-07-07 13:42:58 +08:00
parent 73e39066ff
commit 6e566f8ebf
16 changed files with 1337 additions and 828 deletions

View file

@ -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`))
@ -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

View file

@ -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`))

View file

@ -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`))

View file

@ -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`))

View file

@ -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)

View file

@ -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)

View file

@ -1,5 +1,5 @@
import { selectors } from '../../selectors'
import { testURL } from '../../testURL'
import { selectors } from '../selectors'
import { testURL } from '../testURL'
import {
collapseFloatModeSidebar,
expandFloatModeSidebar,
@ -7,7 +7,7 @@ import {
patientClick,
sleep,
waitForRedirect,
} from '../../utils'
} from '../utils'
jest.retryTimes(3)

View file

@ -1,5 +1,5 @@
import { selectors } from '../../selectors'
import { testURL } from '../../testURL'
import { selectors } from '../selectors'
import { testURL } from '../testURL'
import {
expandFloatModeSidebar,
expectToFind,
@ -7,7 +7,7 @@ import {
patientClick,
sleep,
waitForRedirect,
} from '../../utils'
} from '../utils'
jest.retryTimes(3)

View file

@ -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)

View file

@ -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`))

View file

@ -1,11 +0,0 @@
const baseConfig = require('./jest.config')
/**
* @type {import('@jest/types').Config.InitialOptions}
*/
module.exports = {
...baseConfig,
maxWorkers: 1,
testMatch: [...baseConfig.testMatch, '**/__tests__/cases/non-parallel/*.ts?(x)'],
setupFilesAfterEnv: ['<rootDir>/setup.ts'],
}

View file

@ -1,6 +0,0 @@
const baseConfig = require('./jest.config')
module.exports = {
...baseConfig,
testMatch: [...baseConfig.testMatch, '**/__tests__/cases/parallel/*.ts?(x)'],
}

View file

@ -0,0 +1,7 @@
const baseConfig = require('./jest.config')
module.exports = {
...baseConfig,
testMatch: [...baseConfig.testMatch, '**/__tests__/cases/**/*.ts?(x)'],
setupFilesAfterEnv: ['<rootDir>/setup.ts'],
}

View file

@ -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) {

View file

@ -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",
@ -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",
@ -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",

2049
yarn.lock

File diff suppressed because it is too large Load diff