Skip to content

Commit

Permalink
Use ms for jest timeouts (#9311)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens authored Aug 28, 2024
1 parent c61ac79 commit 5b8a3c7
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 17 deletions.
24 changes: 24 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion tests/admin-ui-tests/live-reloading.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
} from 'playwright'
import { parse, print } from 'graphql'
import fetch from 'node-fetch'
import ms from 'ms'

import {
loadIndex,
makeGqlRequest,
Expand All @@ -24,6 +26,8 @@ async function replaceSchema (schema: string) {
)
}

jest.setTimeout(ms('20 minutes'))

let exit = async () => {}
let ksProcess = undefined as any
let page: Page = undefined as any
Expand Down Expand Up @@ -99,8 +103,8 @@ test('the generated schema includes schema updates', async () => {
}
type Query {
somethings(where: SomethingWhereInput! = {}, orderBy: [SomethingOrderByInput!]! = [], take: Int, skip: Int! = 0, cursor: SomethingWhereUniqueInput): [Something!]
something(where: SomethingWhereUniqueInput!): Something
somethings(where: SomethingWhereInput! = {}, orderBy: [SomethingOrderByInput!]! = [], take: Int, skip: Int! = 0, cursor: SomethingWhereUniqueInput): [Something!]
somethingsCount(where: SomethingWhereInput! = {}): Int
keystone: KeystoneMeta!
someNumber: Int!
Expand Down
5 changes: 3 additions & 2 deletions tests/admin-ui-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
"@keystone-6/core": "workspace:^",
"@manypkg/find-root": "^1.1.0",
"@types/async-retry": "^1.4.3",
"@types/ms": "^0.7.34",
"async-retry": "^1.3.3",
"dotenv": "^16.0.0",
"execa": "^5.1.1",
"express": "^4.19.2",
"graphql": "^16.8.1",
"ms": "^2.1.3",
"node-fetch": "^2.6.7",
"playwright": "^1.17.1",
"treekill": "^1.0.0"
Expand All @@ -25,6 +27,5 @@
"dev": "keystone dev",
"start": "keystone start",
"build": "keystone build"
},
"dependencies": {}
}
}
6 changes: 3 additions & 3 deletions tests/admin-ui-tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import fetch from 'node-fetch'
import { type ExecaChildProcess } from 'execa'
import * as playwright from 'playwright'
import dotenv from 'dotenv'
import ms from 'ms'

jest.setTimeout(ms('20 minutes'))

export async function loadIndex (page: playwright.Page) {
await page.goto('http://localhost:3000')
Expand All @@ -23,9 +26,6 @@ export async function loadIndex (page: playwright.Page) {
}
}

// this'll take a while
jest.setTimeout(10000000)

const projectRoot = path.resolve(__dirname, '..', '..')

export async function makeGqlRequest (query: string, variables?: Record<string, any>) {
Expand Down
3 changes: 2 additions & 1 deletion tests/api-tests/access.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { text } from '@keystone-6/core/fields'
import { list } from '@keystone-6/core'
import { allowAll, denyAll } from '@keystone-6/core/access'
import { dbProvider } from './utils'
import ms from 'ms'

function yesNo (x: boolean) {
if (x === true) return '1'
Expand All @@ -13,7 +14,7 @@ function random (n = 100) {
return 1 + (Math.random() * n | 0)
}

jest.setTimeout(10000000)
jest.setTimeout(ms('20 minutes'))

function makeFieldEntry ({
access
Expand Down
3 changes: 2 additions & 1 deletion tests/api-tests/omit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { list } from '@keystone-6/core'
import { allowAll } from '@keystone-6/core/access'
import { type KeystoneContext } from '@keystone-6/core/types'
import { dbProvider } from './utils'
import ms from 'ms'

jest.setTimeout(10000000)
jest.setTimeout(ms('20 minutes'))

function yn (x: boolean) {
return x ? '1' : '0'
Expand Down
2 changes: 2 additions & 0 deletions tests/api-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
"@prisma/client": "5.17.0",
"@prisma/internals": "^5.0.0",
"@types/express": "^4.17.14",
"@types/ms": "^0.7.34",
"cookie-signature": "^1.1.0",
"fs-extra": "^11.0.0",
"globby": "^11.0.4",
"graphql": "^16.8.1",
"graphql-upload": "^15.0.2",
"mime": "^3.0.0",
"ms": "^2.1.3",
"node-fetch": "^2.6.7",
"prisma": "5.17.0",
"supertest": "^6.1.6",
Expand Down
5 changes: 3 additions & 2 deletions tests/cli-tests/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import {
symlinkKeystoneDeps,
testdir,
} from './utils'
import ms from 'ms'

import { ExitError } from '@keystone-6/core/___internal-do-not-use-will-break-in-patch/artifacts'

jest.setTimeout(ms('20 minutes'))

test("start errors when a build hasn't happened", async () => {
const cwd = await testdir({
...symlinkKeystoneDeps,
Expand All @@ -26,8 +29,6 @@ test("start errors when a build hasn't happened", async () => {
`)
})

jest.setTimeout(1000000)

test('build works with typescript without the user defining a babel config', async () => {
const cwd = await testdir({
...symlinkKeystoneDeps,
Expand Down
3 changes: 2 additions & 1 deletion tests/cli-tests/migrations.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'node:path'
import fs from 'node:fs'
import fsp from 'node:fs/promises'
import ms from 'ms'
import {
getFiles,
introspectDatabase,
Expand Down Expand Up @@ -57,7 +58,7 @@ model Todo {

let mockPromptResponseEntries: [string, string | boolean][] = []

jest.setTimeout(60 * 1000) // these tests are slow
jest.setTimeout(ms('1 minute')) // these tests are slow

jest.mock('prompts', () => {
return function (
Expand Down
4 changes: 3 additions & 1 deletion tests/cli-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
"@keystone-6/core": "workspace:^",
"@keystone-6/fields-document": "workspace:^",
"@prisma/client": "5.17.0",
"@prisma/migrate": "^5.0.0",
"@prisma/internals": "^5.0.0",
"@prisma/migrate": "^5.0.0",
"@types/ms": "^0.7.34",
"chalk": "^4.1.2",
"execa": "^5.1.1",
"fast-glob": "^3.2.12",
"fs-extra": "^11.0.0",
"mime": "^3.0.0",
"ms": "^2.1.3",
"node-fetch": "^2.6.7",
"prisma": "5.17.0"
},
Expand Down
4 changes: 2 additions & 2 deletions tests/cli-tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import fsp from 'node:fs/promises'
import * as fse from 'fs-extra'
import fastGlob from 'fast-glob'
import chalk from 'chalk'
import ms from 'ms'

import { cli } from '@keystone-6/core/scripts/cli'

// these tests spawn processes and it's all pretty slow
jest.setTimeout(1000 * 20)
jest.setTimeout(ms('30 seconds'))

export const cliBinPath = require.resolve('@keystone-6/core/bin/cli.js')

Expand Down
2 changes: 2 additions & 0 deletions tests/examples-smoke-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
"homepage": "https://github.com/keystonejs/keystone",
"devDependencies": {
"@types/async-retry": "^1.4.3",
"@types/ms": "^0.7.34",
"@types/tough-cookie": "^4.0.1",
"async-retry": "^1.3.3",
"execa": "^5.1.1",
"ms": "^2.1.3",
"node-fetch": "^2.6.7",
"playwright": "^1.17.1",
"tree-kill": "^1.2.2"
Expand Down
6 changes: 3 additions & 3 deletions tests/examples-smoke-tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { promisify } from 'util'
import execa, { type ExecaChildProcess } from 'execa'
import _treeKill from 'tree-kill'
import * as playwright from 'playwright'
import ms from 'ms'

jest.setTimeout(ms('20 minutes'))

export async function loadIndex (page: playwright.Page) {
await page.goto('http://localhost:3000')
Expand Down Expand Up @@ -32,9 +35,6 @@ async function deleteAllData (projectDir: string) {

const treeKill = promisify(_treeKill)

// this'll take a while
jest.setTimeout(10000000)

export function initFirstItemTest (getPage: () => playwright.Page) {
test('init first item', async () => {
const page = getPage()
Expand Down

0 comments on commit 5b8a3c7

Please sign in to comment.