explicitly import @jest/globals and mocha (#57786)

Previously bindings like `expect`, `describe`, `afterAll`, etc., were imported implicitly by Jest or Mocha. We should import them explicitly to reduce magic. (Also this makes it easier to migrate to another test runner in the future if we want.)
This commit is contained in:
Quinn Slack 2023-10-23 14:40:17 -07:00 committed by GitHub
parent 59c82bcfb1
commit f160c5c041
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
414 changed files with 1051 additions and 977 deletions

View File

@ -5,6 +5,7 @@ load("//dev:eslint.bzl", "eslint_config_and_lint_root", "eslint_test_with_types"
# TODO(bazel): storybook build
# gazelle:exclude **/*.story.{ts,tsx}
# gazelle:exclude **/testGlobals.d.ts
# gazelle:js_resolve **/*.module.scss :module_style_typings
@ -250,6 +251,7 @@ ts_project(
"src/search-ui/results/sidebar/SearchFilterSection.test.tsx",
"src/search-ui/results/sidebar/helpers.test.ts",
"src/search-ui/results/use-items-to-show.test.ts",
"src/testGlobals.d.ts", #keep
],
tsconfig = ":tsconfig",
deps = [
@ -260,6 +262,8 @@ ts_project(
":node_modules/@sourcegraph/wildcard",
"//:node_modules/@codemirror/autocomplete",
"//:node_modules/@codemirror/state",
"//:node_modules/@jest/globals",
"//:node_modules/@testing-library/jest-dom", #keep
"//:node_modules/@testing-library/react",
"//:node_modules/@testing-library/user-event",
"//:node_modules/@types/history",

View File

@ -1,3 +1,4 @@
import { describe, expect, test } from '@jest/globals'
import { render } from '@testing-library/react'
import { Timestamp, TimestampFormat } from './Timestamp'

View File

@ -1,3 +1,4 @@
import { describe, expect, test } from '@jest/globals'
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import sinon from 'sinon'

View File

@ -1,3 +1,4 @@
import { describe, expect, test } from '@jest/globals'
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import sinon from 'sinon'

View File

@ -1,5 +1,6 @@
import React from 'react'
import { afterEach, describe, expect, it } from '@jest/globals'
import { cleanup, fireEvent } from '@testing-library/react'
import { renderWithBrandedContext } from '@sourcegraph/wildcard/src/testing'

View File

@ -1,3 +1,5 @@
import { describe, expect, test } from '@jest/globals'
import type { Location } from '@sourcegraph/extension-api-types'
import { type GroupedLocations, groupLocations } from './locations'

View File

@ -1,3 +1,4 @@
import { afterAll, describe, expect, it } from '@jest/globals'
import { cleanup, getByText, render } from '@testing-library/react'
import { of } from 'rxjs'
import { map } from 'rxjs/operators'

View File

@ -1,3 +1,4 @@
import { afterAll, describe, expect, it } from '@jest/globals'
import { cleanup, getAllByTestId, getByTestId } from '@testing-library/react'
import { createBrowserHistory } from 'history'
import FileIcon from 'mdi-react/FileIcon'

View File

@ -1,3 +1,4 @@
import { afterAll, describe, it } from '@jest/globals'
import { cleanup } from '@testing-library/react'
import * as H from 'history'
import { of } from 'rxjs'

View File

@ -1,3 +1,4 @@
import { afterAll, describe, expect, it } from '@jest/globals'
import { cleanup, fireEvent, getByTestId, getByText } from '@testing-library/react'
import * as H from 'history'
import FileIcon from 'mdi-react/FileIcon'

View File

@ -1,3 +1,5 @@
import { describe, expect, test } from '@jest/globals'
import { renderWithBrandedContext } from '@sourcegraph/wildcard/src/testing'
import { RepoFileLink } from './RepoFileLink'

View File

@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals'
import { render } from '@testing-library/react'
import { SyntaxHighlightedSearchQuery } from './SyntaxHighlightedSearchQuery'

View File

@ -1,3 +1,4 @@
import { describe, expect, test } from '@jest/globals'
import { render } from '@testing-library/react'
import { noop } from 'lodash'

View File

@ -1,3 +1,4 @@
import { afterAll, beforeAll, describe, expect, it } from '@jest/globals'
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { act } from 'react-dom/test-utils'

View File

@ -1,3 +1,4 @@
import { afterAll, beforeAll, describe, expect, it } from '@jest/globals'
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { act } from 'react-dom/test-utils'

View File

@ -1,4 +1,5 @@
import type { Completion } from '@codemirror/autocomplete'
import { describe, expect, test } from '@jest/globals'
import { SymbolKind } from '@sourcegraph/shared/src/graphql-operations'
import { POPULAR_LANGUAGES } from '@sourcegraph/shared/src/search/query/languageFilter'

View File

@ -1,4 +1,5 @@
import { EditorState } from '@codemirror/state'
import { describe, expect, it } from '@jest/globals'
import { SearchPatternType } from '@sourcegraph/shared/src/graphql-operations'

View File

@ -1,3 +1,5 @@
import { describe, expect, it } from '@jest/globals'
import { shortenPath } from './utils'
describe('shortenPath', () => {

View File

@ -1,3 +1,4 @@
import { describe, expect, test } from '@jest/globals'
import { screen } from '@testing-library/react'
import { SearchPatternType } from '@sourcegraph/shared/src/graphql-operations'

View File

@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals'
import { render } from '@testing-library/react'
import type { Progress } from '@sourcegraph/shared/src/search/stream'

View File

@ -1,3 +1,4 @@
import { beforeAll, describe, expect, it } from '@jest/globals'
import { screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import sinon from 'sinon'

View File

@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals'
import { screen, within } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import sinon from 'sinon'

View File

@ -1,3 +1,5 @@
import { describe, expect, test } from '@jest/globals'
import { validateQueryForExhaustiveSearch } from './exhaustive-search-validation'
describe('exhaustive search validation', () => {

View File

@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals'
import { screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import sinon from 'sinon'

View File

@ -1,3 +1,5 @@
import { describe, expect, it } from '@jest/globals'
import type { QuickLink } from '@sourcegraph/shared/src/schema/settings.schema'
import { renderWithBrandedContext } from '@sourcegraph/wildcard/src/testing'

View File

@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals'
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { stub } from 'sinon'

View File

@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals'
import { renderHook } from '@testing-library/react'
import { FilterType } from '@sourcegraph/shared/src/search/query/filters'

View File

@ -1,3 +1,4 @@
import { afterEach, describe, expect, it } from '@jest/globals'
import { act, renderHook } from '@testing-library/react'
import { times } from 'lodash'
@ -11,7 +12,7 @@ function renderUseItemsToShowHook(query = 'Hello there!') {
function scrollToViewMoreResults(scrollNumber: number, handleBottomHit: () => void) {
// Do not await `act` call with sync logic. It's not a promise.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
act(() => {
times(scrollNumber, handleBottomHit)
})

1
client/branded/src/testGlobals.d.ts vendored Normal file
View File

@ -0,0 +1 @@
/// <reference types="@testing-library/jest-dom/types/jest-globals" />

View File

@ -11,6 +11,7 @@ load("//dev:eslint.bzl", "eslint_config_and_lint_root", "eslint_test_with_types"
# TODO(bazel): storybook build
# gazelle:exclude **/*.story.{ts,tsx}
# gazelle:exclude **/testGlobals.d.ts
# gazelle:js_resolve **/*.module.scss :module_style_typings
@ -247,12 +248,12 @@ ts_project(
":node_modules/@sourcegraph/http-client",
":node_modules/@sourcegraph/shared",
":node_modules/@sourcegraph/wildcard",
"//:node_modules/@jest/globals",
"//:node_modules/@mdi/js",
"//:node_modules/@reach/combobox",
"//:node_modules/@sentry/browser",
"//:node_modules/@types/classnames",
"//:node_modules/@types/history",
"//:node_modules/@types/jest", #keep
"//:node_modules/@types/lodash",
"//:node_modules/@types/mz",
"//:node_modules/@types/node",
@ -303,6 +304,7 @@ ts_project(
"src/shared/code-hosts/shared/codeViews.test.ts",
"src/shared/code-hosts/shared/views.test.ts",
"src/shared/code-hosts/sourcegraph/inject.test.tsx",
"src/testGlobals.d.ts", #keep
],
tsconfig = ":tsconfig",
deps = [
@ -313,6 +315,8 @@ ts_project(
":node_modules/@sourcegraph/shared",
":node_modules/@sourcegraph/wildcard", #keep
":node_modules/sourcegraph",
"//:node_modules/@jest/globals",
"//:node_modules/@testing-library/jest-dom", #keep
"//:node_modules/@testing-library/react",
"//:node_modules/@types/lodash",
"//:node_modules/@types/mz",
@ -330,9 +334,22 @@ ts_project(
],
)
js_library(
name = "jest_config",
testonly = True,
srcs = [
"jest.config.js",
],
data = [
"src/shared/jestSetupAfterEnv.js",
],
deps = ["//:jest_config"],
)
jest_test(
name = "test",
timeout = "moderate",
config = ":jest_config",
data = [
":browser_tests",
],

View File

@ -4,4 +4,11 @@
const config = require('../../jest.config.base')
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = { ...config, displayName: 'browser', rootDir: __dirname }
module.exports = {
...config,
displayName: 'browser',
rootDir: __dirname,
roots: ['<rootDir>/src'],
modulePathIgnorePatterns: ['<rootDir>/.*runfiles.*', '.*/end-to-end/.*'], // TODO(sqs)
setupFilesAfterEnv: [...(config.setupFilesAfterEnv || []), '<rootDir>/src/shared/jestSetupAfterEnv.js'],
}

View File

@ -20,9 +20,11 @@ ts_project(
srcs = ["shared.ts"],
tsconfig = ":tsconfig",
deps = [
"//:node_modules/@types/mocha",
"//:node_modules/@types/node",
"//:node_modules/@types/puppeteer",
"//:node_modules/expect",
"//:node_modules/mocha",
"//:node_modules/puppeteer",
"//client/browser:node_modules/@sourcegraph/shared",
],
@ -42,10 +44,12 @@ ts_project(
deps = [
":end-to-end",
"//:node_modules/@types/lodash",
"//:node_modules/@types/mocha",
"//:node_modules/@types/node",
"//:node_modules/@types/puppeteer",
"//:node_modules/expect",
"//:node_modules/lodash",
"//:node_modules/mocha",
"//:node_modules/puppeteer",
"//:node_modules/rxjs",
"//client/browser",

View File

@ -1,4 +1,5 @@
import expect from 'expect'
import { describe } from 'mocha'
import { ExternalServiceKind } from '@sourcegraph/shared/src/graphql-operations'
import { getConfig } from '@sourcegraph/shared/src/testing/config'

View File

@ -1,6 +1,7 @@
import assert from 'assert'
import { startCase } from 'lodash'
import { describe, it } from 'mocha'
import type { Target, Page } from 'puppeteer'
import { fromEvent } from 'rxjs'
import { first, filter, timeout, mergeMap } from 'rxjs/operators'

View File

@ -1,3 +1,5 @@
import { describe } from 'mocha'
import { ExternalServiceKind } from '@sourcegraph/shared/src/graphql-operations'
import { getConfig } from '@sourcegraph/shared/src/testing/config'
import { createDriverForTest, type Driver } from '@sourcegraph/shared/src/testing/driver'

View File

@ -1,5 +1,6 @@
import expect from 'expect'
import { isEqual } from 'lodash'
import { describe, it } from 'mocha'
import { ExternalServiceKind } from '@sourcegraph/shared/src/graphql-operations'
import { getConfig } from '@sourcegraph/shared/src/testing/config'

View File

@ -1,6 +1,7 @@
import assert from 'assert'
import expect from 'expect'
import { describe, it } from 'mocha'
import type puppeteer from 'puppeteer'
import type { Driver } from '@sourcegraph/shared/src/testing/driver'

View File

@ -2,7 +2,7 @@
"extends": "../../tsconfig.json",
"references": [{ "path": "../.." }, { "path": "../../../shared/src/testing" }],
"compilerOptions": {
"types": ["mocha", "node"],
"types": ["node"],
"module": "commonjs",
"rootDir": ".",
"outDir": "../../out/src/end-to-end",

View File

@ -1,5 +1,7 @@
import assert from 'assert'
import { afterEach, beforeEach, describe, it } from 'mocha'
import type { ExtensionContext } from '@sourcegraph/shared/src/codeintel/legacy-extensions/api'
import type { Settings } from '@sourcegraph/shared/src/settings/settings'
import { createDriverForTest, type Driver } from '@sourcegraph/shared/src/testing/driver'

View File

@ -1,5 +1,7 @@
import assert from 'assert'
import { afterEach, beforeEach, describe, it } from 'mocha'
import type { Settings } from '@sourcegraph/shared/src/settings/settings'
import { createDriverForTest, type Driver } from '@sourcegraph/shared/src/testing/driver'
import { setupExtensionMocking, simpleHoverProvider } from '@sourcegraph/shared/src/testing/integration/mockExtension'

View File

@ -2,7 +2,7 @@
"extends": "../../tsconfig.json",
"references": [{ "path": "../.." }, { "path": "../../../shared/src/testing" }],
"compilerOptions": {
"types": ["mocha", "node"],
"types": ["node"],
"module": "commonjs",
"rootDir": ".",
"outDir": "../../out/src/integration",

View File

@ -1,3 +1,5 @@
import { describe, expect, test } from '@jest/globals'
import type { LineOrPositionOrRange } from '@sourcegraph/common'
import { parseHash } from './codeHost'

View File

@ -1,3 +1,5 @@
import { describe, expect, test } from '@jest/globals'
import type { LineOrPositionOrRange } from '@sourcegraph/common'
import { testCodeHostMountGetters, testToolbarMountGetter } from '../shared/codeHostTestUtils'

View File

@ -1,3 +1,4 @@
import { describe } from '@jest/globals'
import { startCase } from 'lodash'
import { testDOMFunctions } from '../shared/codeHostTestUtils'

View File

@ -1,3 +1,4 @@
import { afterEach, describe, expect, it } from '@jest/globals'
import { readFile } from 'mz/fs'
import { getFixtureBody } from '../shared/codeHostTestUtils'

View File

@ -1,5 +1,6 @@
import { existsSync, readdirSync } from 'fs'
import { afterAll, beforeAll, beforeEach, describe, expect, it, test } from '@jest/globals'
import fetch from 'jest-fetch-mock'
import { startCase } from 'lodash'
import { readFile } from 'mz/fs'
@ -225,7 +226,7 @@ describe('isPrivateRepository', () => {
beforeEach(() => {
fetch.enableMocks()
fetch.mockClear()
fetch.resetMocks()
})
afterAll(() => {

View File

@ -1,3 +1,4 @@
import { beforeEach, describe, expect, it } from '@jest/globals'
import { startCase } from 'lodash'
import type { Omit } from 'utility-types'

View File

@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals'
import { readFile } from 'mz/fs'
import { getFilePath, getFilePathFromURL } from './util'

View File

@ -1,3 +1,4 @@
import { describe, expect, test } from '@jest/globals'
import { startCase } from 'lodash'
import { getFixtureBody } from '../shared/codeHostTestUtils'

View File

@ -1,3 +1,4 @@
import { afterAll, beforeAll, beforeEach, describe, expect, it, test } from '@jest/globals'
import fetch from 'jest-fetch-mock'
import { readFile } from 'mz/fs'
@ -161,7 +162,7 @@ describe('isPrivateRepository', () => {
})
beforeEach(() => {
fetch.mockClear()
fetch.resetMocks()
})
afterAll(() => {

View File

@ -1,3 +1,4 @@
import { describe } from '@jest/globals'
import { startCase } from 'lodash'
import { testDOMFunctions } from '../shared/codeHostTestUtils'

View File

@ -1,3 +1,5 @@
import { describe, expect, test } from '@jest/globals'
import { getPageKindFromPathName, GitLabPageKind } from './scrape'
describe('getPageKindFromPathName()', () => {

View File

@ -1,3 +1,5 @@
import { describe } from '@jest/globals'
import { testToolbarMountGetter } from '../shared/codeHostTestUtils'
import { commitCodeView, diffCodeView } from './codeHost'

View File

@ -1,3 +1,4 @@
import { describe } from '@jest/globals'
import { startCase } from 'lodash'
import { type DOMFunctionsTest, testDOMFunctions } from '../shared/codeHostTestUtils'

View File

@ -1,3 +1,4 @@
import { beforeEach, describe, expect, test } from '@jest/globals'
import { readFile } from 'mz/fs'
import { type Observable, throwError, of } from 'rxjs'

View File

@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals'
import { render } from '@testing-library/react'
import { noop } from 'lodash'

View File

@ -1,6 +1,7 @@
import { nextTick } from 'process'
import { promisify } from 'util'
import { afterEach, beforeAll, beforeEach, jest, describe, expect, it, test } from '@jest/globals'
import type { RenderResult } from '@testing-library/react'
import type { Remote } from 'comlink'
import { uniqueId, noop, pick } from 'lodash'

View File

@ -1,5 +1,6 @@
import assert from 'assert'
import { beforeEach, describe, expect, it } from '@jest/globals'
import { readFile } from 'mz/fs'
import Simmer, { type Options as SimmerOptions } from 'simmerjs'
import type { SetIntersection } from 'utility-types'
@ -75,7 +76,7 @@ export async function getFixtureBody({
* @param mayReturnNull Whether the mount getter might be called with containers where the mount does not belong.
* It will be tested to return `null` in that case.
*/
export function testMountGetter(
function testMountGetter(
htmlFixturePath: string,
getMount: MountGetter,
isFullDocument: boolean,

View File

@ -1,3 +1,4 @@
import { beforeEach, describe, expect, it } from '@jest/globals'
import { of } from 'rxjs'
import { toArray } from 'rxjs/operators'
import * as sinon from 'sinon'

View File

@ -1,3 +1,4 @@
import { afterAll, beforeEach, describe, expect, test } from '@jest/globals'
import { noop } from 'lodash'
import { from, type Observable, of, Subject, Subscription, NEVER } from 'rxjs'
import { bufferCount, map, switchMap, toArray } from 'rxjs/operators'

View File

@ -1,3 +1,5 @@
import { describe, expect, it } from '@jest/globals'
import { checkIsSourcegraph } from './inject'
describe('checkIsSourcegraph()', () => {

View File

@ -0,0 +1,4 @@
// jest-fetch-mock assumes the `jest` global is available, but we use explicit imports from
// `@jest/globals`. This is a workaround to make jest-fetch-mock work. See
// https://github.com/jefflau/jest-fetch-mock/issues/104.
global.jest = require('@jest/globals').jest

1
client/browser/src/testGlobals.d.ts vendored Normal file
View File

@ -0,0 +1 @@
/// <reference types="@testing-library/jest-dom/types/jest-globals" />

View File

@ -46,6 +46,7 @@ ts_project(
deps = [
":client-api_lib",
":node_modules/@sourcegraph/extension-api-types",
"//:node_modules/@jest/globals",
"//:node_modules/@sourcegraph/extension-api-classes",
],
)

View File

@ -1,3 +1,5 @@
import { describe, expect, test } from '@jest/globals'
import { MarkupKind } from '@sourcegraph/extension-api-classes'
import type { Range } from '@sourcegraph/extension-api-types'

View File

@ -56,6 +56,7 @@ ts_project(
"src/testutils/fixtures.ts",
"src/testutils/generate.ts",
"src/testutils/github/generate.ts",
"src/testutils/globals.d.ts",
"src/testutils/mouse.ts",
"src/testutils/revision.ts",
"src/testutils/sourcegraph/generate.ts",
@ -71,6 +72,8 @@ ts_project(
":codeintellify_lib",
":node_modules/@sourcegraph/common",
":node_modules/@sourcegraph/extension-api-types",
"//:node_modules/@jest/globals",
"//:node_modules/@testing-library/jest-dom", #keep
"//:node_modules/@types/lodash",
"//:node_modules/@types/node",
"//:node_modules/lodash",

View File

@ -1,3 +1,4 @@
import { afterAll, afterEach, beforeAll, describe, it, expect } from '@jest/globals'
import { isEqual } from 'lodash'
import { EMPTY, NEVER, of, Subject, Subscription } from 'rxjs'
import { delay, distinctUntilChanged, filter, first, map, takeWhile } from 'rxjs/operators'

View File

@ -1,5 +1,6 @@
import assert from 'assert'
import { describe, it } from '@jest/globals'
import { TestScheduler } from 'rxjs/testing'
import { emitLoading, LOADING, type MaybeLoadingResult } from './loading'

View File

@ -1,5 +1,7 @@
import * as assert from 'assert'
import { describe, it } from '@jest/globals'
import { calculateOverlayPosition, type HasGetBoundingClientRect } from './overlayPosition'
const rectangle = (left: number, top: number, width: number, height: number): HasGetBoundingClientRect => ({

View File

@ -1,3 +1,4 @@
import { afterAll, describe, expect, it } from '@jest/globals'
import { of } from 'rxjs'
import { findPositionsFromEvents } from './positions'

View File

@ -1,3 +1,5 @@
import { afterAll, describe, expect, it } from '@jest/globals'
import { DOM } from './dom'
describe('can create dom elements from generated code tables', () => {

View File

@ -0,0 +1 @@
/// <reference types="@testing-library/jest-dom/types/jest-globals" />

View File

@ -1,5 +1,7 @@
import * as assert from 'assert'
import { afterAll, beforeAll, describe, expect, it } from '@jest/globals'
import type { Position, Range } from '@sourcegraph/extension-api-types'
import { type CodeViewProps, DOM } from './testutils/dom'

View File

@ -1,4 +1,5 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_config")
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@npm//:defs.bzl", "npm_link_all_packages")
load("//dev:defs.bzl", "jest_test", "npm_package", "ts_project")
load("//dev:eslint.bzl", "eslint_config_and_lint_root")
@ -94,6 +95,7 @@ ts_project(
tsconfig = ":tsconfig",
deps = [
":common_lib",
"//:node_modules/@jest/globals",
"//:node_modules/@types/mockdate",
"//:node_modules/@types/node",
"//:node_modules/jest-fetch-mock",
@ -110,8 +112,21 @@ npm_package(
],
)
js_library(
name = "jest_config",
testonly = True,
srcs = [
"jest.config.js",
],
data = [
"src/jestSetupAfterEnv.js",
],
deps = ["//:jest_config"],
)
jest_test(
name = "test",
config = ":jest_config",
data = [
":common_tests",
],

View File

@ -6,8 +6,9 @@ const exportedConfig = {
...config,
displayName: 'common',
rootDir: __dirname,
roots: ['<rootDir>'],
roots: ['<rootDir>/src'],
verbose: true,
setupFilesAfterEnv: [...(config.setupFilesAfterEnv || []), '<rootDir>/src/jestSetupAfterEnv.js'],
}
module.exports = exportedConfig

View File

@ -1,3 +1,5 @@
import { describe, expect, test } from '@jest/globals'
import { asError } from './errors'
import { isErrorLike } from './utils'

View File

@ -0,0 +1,4 @@
// jest-fetch-mock assumes the `jest` global is available, but we use explicit imports from
// `@jest/globals`. This is a workaround to make jest-fetch-mock work. See
// https://github.com/jefflau/jest-fetch-mock/issues/104.
global.jest = require('@jest/globals').jest

View File

@ -1,3 +1,4 @@
import { afterAll, beforeAll, beforeEach, describe, expect, it } from '@jest/globals'
import fetch from 'jest-fetch-mock'
import MockDate from 'mockdate'
@ -19,7 +20,7 @@ describe('fetchCache', () => {
})
beforeEach(() => {
fetch.mockClear()
fetch.resetMocks()
clearFetchCache()
fetch.mockResponse(JSON.stringify(EXPECTED_DATA))
})
@ -65,7 +66,7 @@ describe('fetchCache', () => {
it('makes multiple requests in case of cache expiration', async () => {
const responseOne = await fetchCache({ cacheMaxAge: 1, url: TEST_URL })
await new Promise(resolve => setTimeout(resolve, 3)) // 3 millis passed
MockDate.set(Date.now() + 3)
const responseTwo = await fetchCache({ cacheMaxAge: 1, url: TEST_URL })
expectResponses([responseOne, responseTwo])

View File

@ -1,3 +1,5 @@
import { describe, expect, test } from '@jest/globals'
import { hashCode } from './hashCode'
describe('hashCode', () => {

View File

@ -1,3 +1,5 @@
import { beforeEach, describe, expect, test } from '@jest/globals'
import * as dom from './highlightNode'
describe('util/dom', () => {

View File

@ -1,3 +1,5 @@
import { describe, expect, test } from '@jest/globals'
import { isErrorLike } from '../errors'
import { modify, parseJSONCOrError } from './jsonc'

View File

@ -1,3 +1,5 @@
import { describe, expect, it, test } from '@jest/globals'
import { renderMarkdown, registerHighlightContributions, escapeMarkdown } from '.'
registerHighlightContributions()

View File

@ -1,5 +1,6 @@
import assert from 'assert'
import { describe, it } from '@jest/globals'
import { of } from 'rxjs'
import { asObservable } from './asObservable'

View File

@ -1,3 +1,4 @@
import { describe, expect, test } from '@jest/globals'
import { of } from 'rxjs'
import { TestScheduler } from 'rxjs/testing'

View File

@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals'
import { from, defer } from 'rxjs'
import { TestScheduler } from 'rxjs/testing'

View File

@ -1,3 +1,5 @@
import { describe, expect, it } from '@jest/globals'
import { dedupeWhitespace } from './strings'
describe('utils/string', () => {

View File

@ -1,3 +1,5 @@
import { describe, expect, it, test } from '@jest/globals'
import { lprToSelectionsZeroIndexed, encodeURIPathComponent, appendLineRangeQueryParameter } from './url'
/**

View File

@ -58,6 +58,7 @@ ts_project(
deps = [
":http-client_lib",
"//:node_modules/@apollo/client",
"//:node_modules/@jest/globals",
"//:node_modules/@types/sinon",
"//:node_modules/delay",
"//:node_modules/rxjs",

View File

@ -1,4 +1,5 @@
import { Observable as ZenObservable, type ObservableQuery } from '@apollo/client'
import { describe, expect, it } from '@jest/globals'
import delay from 'delay'
import { isObservable } from 'rxjs'
import sinon from 'sinon'

View File

@ -1,3 +1,5 @@
import { describe, expect, test } from '@jest/globals'
import { GRAPHQL_URI } from './constants'
import { buildGraphQLUrl, gql } from './graphql'
@ -53,7 +55,7 @@ describe('buildGraphQLUrl', () => {
],
]
test.each(testCases)('correctly constructs %s', (title, request, baseUrl, expectedResult) => {
test.each(testCases)('correctly constructs %s', (_title, request, baseUrl, expectedResult) => {
expect(buildGraphQLUrl({ request, baseUrl })).toEqual(expectedResult)
})
})

View File

@ -83,7 +83,10 @@ ts_project(
testonly = True,
srcs = ["src/sdk/__tests__/getTracingUrl.test.ts"],
tsconfig = ":tsconfig",
deps = [":observability-client_lib"],
deps = [
":observability-client_lib",
"//:node_modules/@jest/globals",
],
)
jest_test(

View File

@ -1,3 +1,5 @@
import { describe, expect, it } from '@jest/globals'
import { getTracingURL, TRACING_URL_SUFFIX } from '../getTracingUrl'
const BASE_URL = 'https://sourcegraph.test:3443'

View File

@ -52,6 +52,7 @@ ts_project(
tsconfig = ":tsconfig",
deps = [
":observability-server",
"//:node_modules/@jest/globals",
"//:node_modules/@types/node",
],
)

View File

@ -1,5 +1,7 @@
import path from 'path'
import { describe, expect, it, jest } from '@jest/globals'
import { getBundleSizeStats } from './getBundleSizeStats'
const MOCK_ASSETS_PATH = path.join(__dirname, './__mocks__/assets')

View File

@ -9,6 +9,7 @@ load("//dev:eslint.bzl", "eslint_config_and_lint_root", "eslint_test_with_types"
# TODO(bazel): storybook build
# gazelle:exclude **/*.story.{ts,tsx}
# gazelle:exclude **/testGlobals.d.ts
# gazelle:js_resolve **/*.module.scss :module_style_typings
# gazelle:js_resolve ../graphql-operations //client/shared:graphql_operations
@ -463,6 +464,7 @@ ts_project(
"src/search/query/validate.test.ts",
"src/settings/settings.test.ts",
"src/settings/temporary/useTemporarySetting.test.tsx",
"src/testGlobals.d.ts", #keep
"src/tracking/utm.test.ts",
"src/util/dom.test.ts",
"src/util/url.test.ts",
@ -482,8 +484,10 @@ ts_project(
":node_modules/sourcegraph",
":shared_lib",
"//:node_modules/@apollo/client",
"//:node_modules/@jest/globals",
"//:node_modules/@sourcegraph/extension-api-classes",
"//:node_modules/@sourcegraph/extension-api-stubs",
"//:node_modules/@testing-library/jest-dom", #keep
"//:node_modules/@testing-library/react",
"//:node_modules/@testing-library/user-event",
"//:node_modules/@types/history",

View File

@ -79,11 +79,13 @@ ts_project(
tsconfig = "//client/shared:tsconfig",
visibility = ["//visibility:private"],
deps = [
"//:node_modules/@jest/globals",
"//:node_modules/@sentry/browser",
"//:node_modules/@testing-library/react",
"//:node_modules/@types/jest",
"//:node_modules/@types/lodash",
"//:node_modules/@types/node",
"//:node_modules/@types/react",
"//:node_modules/lodash",
"//:node_modules/react",
"//:node_modules/react-visibility-sensor",
"//:node_modules/resize-observer-polyfill",

View File

@ -1,3 +1,5 @@
import { jest } from '@jest/globals'
/* eslint-disable ban/ban */
/**

View File

@ -1,3 +1,4 @@
import { jest } from '@jest/globals'
import ResizeObserver from 'resize-observer-polyfill'
if ('ResizeObserver' in window === false) {
@ -6,6 +7,6 @@ if ('ResizeObserver' in window === false) {
jest.mock('use-resize-observer', () => ({
__esModule: true,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
default: jest.requireActual('use-resize-observer/polyfilled'),
}))

View File

@ -1,8 +1,10 @@
import { jest } from '@jest/globals'
// The value returned by the `_.uniqueId()` function depends on the number of previous calls
// because it maintains an internal variable that increments on each call.
// Mock `_.uniqueId()` to avoid updating snapshots once the sequence or number of tests using this helper changes.
jest.mock('lodash', () =>
Object.assign(jest.requireActual('lodash'), {
Object.assign(jest.requireActual<typeof import('lodash')>('lodash'), {
// Keep all actual implementations except uniqueId
uniqueId: (prefix = '') => `${prefix}test-id`,
})

View File

@ -1,3 +1,4 @@
import { afterEach } from '@jest/globals'
import { cleanup } from '@testing-library/react'
/**

Some files were not shown because too many files have changed in this diff Show More