mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 17:11:49 +00:00
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:
parent
59c82bcfb1
commit
f160c5c041
@ -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",
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { describe, expect, test } from '@jest/globals'
|
||||
import { render } from '@testing-library/react'
|
||||
|
||||
import { Timestamp, TimestampFormat } from './Timestamp'
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { describe, expect, test } from '@jest/globals'
|
||||
|
||||
import { renderWithBrandedContext } from '@sourcegraph/wildcard/src/testing'
|
||||
|
||||
import { RepoFileLink } from './RepoFileLink'
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { describe, expect, it } from '@jest/globals'
|
||||
import { render } from '@testing-library/react'
|
||||
|
||||
import { SyntaxHighlightedSearchQuery } from './SyntaxHighlightedSearchQuery'
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { describe, expect, test } from '@jest/globals'
|
||||
import { render } from '@testing-library/react'
|
||||
import { noop } from 'lodash'
|
||||
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { EditorState } from '@codemirror/state'
|
||||
import { describe, expect, it } from '@jest/globals'
|
||||
|
||||
import { SearchPatternType } from '@sourcegraph/shared/src/graphql-operations'
|
||||
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { describe, expect, it } from '@jest/globals'
|
||||
|
||||
import { shortenPath } from './utils'
|
||||
|
||||
describe('shortenPath', () => {
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { describe, expect, test } from '@jest/globals'
|
||||
|
||||
import { validateQueryForExhaustiveSearch } from './exhaustive-search-validation'
|
||||
|
||||
describe('exhaustive search validation', () => {
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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'
|
||||
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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
1
client/branded/src/testGlobals.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
/// <reference types="@testing-library/jest-dom/types/jest-globals" />
|
||||
@ -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",
|
||||
],
|
||||
|
||||
@ -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'],
|
||||
}
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { describe, expect, test } from '@jest/globals'
|
||||
|
||||
import type { LineOrPositionOrRange } from '@sourcegraph/common'
|
||||
|
||||
import { parseHash } from './codeHost'
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { describe, expect, test } from '@jest/globals'
|
||||
|
||||
import type { LineOrPositionOrRange } from '@sourcegraph/common'
|
||||
|
||||
import { testCodeHostMountGetters, testToolbarMountGetter } from '../shared/codeHostTestUtils'
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { describe } from '@jest/globals'
|
||||
import { startCase } from 'lodash'
|
||||
|
||||
import { testDOMFunctions } from '../shared/codeHostTestUtils'
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { afterEach, describe, expect, it } from '@jest/globals'
|
||||
import { readFile } from 'mz/fs'
|
||||
|
||||
import { getFixtureBody } from '../shared/codeHostTestUtils'
|
||||
|
||||
@ -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(() => {
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { beforeEach, describe, expect, it } from '@jest/globals'
|
||||
import { startCase } from 'lodash'
|
||||
import type { Omit } from 'utility-types'
|
||||
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { describe, expect, it } from '@jest/globals'
|
||||
import { readFile } from 'mz/fs'
|
||||
|
||||
import { getFilePath, getFilePathFromURL } from './util'
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { describe, expect, test } from '@jest/globals'
|
||||
import { startCase } from 'lodash'
|
||||
|
||||
import { getFixtureBody } from '../shared/codeHostTestUtils'
|
||||
|
||||
@ -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(() => {
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { describe } from '@jest/globals'
|
||||
import { startCase } from 'lodash'
|
||||
|
||||
import { testDOMFunctions } from '../shared/codeHostTestUtils'
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { describe, expect, test } from '@jest/globals'
|
||||
|
||||
import { getPageKindFromPathName, GitLabPageKind } from './scrape'
|
||||
|
||||
describe('getPageKindFromPathName()', () => {
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { describe } from '@jest/globals'
|
||||
|
||||
import { testToolbarMountGetter } from '../shared/codeHostTestUtils'
|
||||
|
||||
import { commitCodeView, diffCodeView } from './codeHost'
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { describe } from '@jest/globals'
|
||||
import { startCase } from 'lodash'
|
||||
|
||||
import { type DOMFunctionsTest, testDOMFunctions } from '../shared/codeHostTestUtils'
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { beforeEach, describe, expect, test } from '@jest/globals'
|
||||
import { readFile } from 'mz/fs'
|
||||
import { type Observable, throwError, of } from 'rxjs'
|
||||
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { describe, expect, it } from '@jest/globals'
|
||||
import { render } from '@testing-library/react'
|
||||
import { noop } from 'lodash'
|
||||
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { describe, expect, it } from '@jest/globals'
|
||||
|
||||
import { checkIsSourcegraph } from './inject'
|
||||
|
||||
describe('checkIsSourcegraph()', () => {
|
||||
|
||||
4
client/browser/src/shared/jestSetupAfterEnv.js
Normal file
4
client/browser/src/shared/jestSetupAfterEnv.js
Normal 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
1
client/browser/src/testGlobals.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
/// <reference types="@testing-library/jest-dom/types/jest-globals" />
|
||||
@ -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",
|
||||
],
|
||||
)
|
||||
|
||||
@ -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'
|
||||
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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 => ({
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { afterAll, describe, expect, it } from '@jest/globals'
|
||||
import { of } from 'rxjs'
|
||||
|
||||
import { findPositionsFromEvents } from './positions'
|
||||
|
||||
@ -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', () => {
|
||||
|
||||
1
client/codeintellify/src/testutils/globals.d.ts
vendored
Normal file
1
client/codeintellify/src/testutils/globals.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
/// <reference types="@testing-library/jest-dom/types/jest-globals" />
|
||||
@ -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'
|
||||
|
||||
@ -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",
|
||||
],
|
||||
|
||||
@ -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
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { describe, expect, test } from '@jest/globals'
|
||||
|
||||
import { asError } from './errors'
|
||||
import { isErrorLike } from './utils'
|
||||
|
||||
|
||||
4
client/common/src/jestSetupAfterEnv.js
Normal file
4
client/common/src/jestSetupAfterEnv.js
Normal 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,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])
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { describe, expect, test } from '@jest/globals'
|
||||
|
||||
import { hashCode } from './hashCode'
|
||||
|
||||
describe('hashCode', () => {
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { beforeEach, describe, expect, test } from '@jest/globals'
|
||||
|
||||
import * as dom from './highlightNode'
|
||||
|
||||
describe('util/dom', () => {
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { describe, expect, test } from '@jest/globals'
|
||||
|
||||
import { isErrorLike } from '../errors'
|
||||
|
||||
import { modify, parseJSONCOrError } from './jsonc'
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { describe, expect, it, test } from '@jest/globals'
|
||||
|
||||
import { renderMarkdown, registerHighlightContributions, escapeMarkdown } from '.'
|
||||
|
||||
registerHighlightContributions()
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import assert from 'assert'
|
||||
|
||||
import { describe, it } from '@jest/globals'
|
||||
import { of } from 'rxjs'
|
||||
|
||||
import { asObservable } from './asObservable'
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { describe, expect, test } from '@jest/globals'
|
||||
import { of } from 'rxjs'
|
||||
import { TestScheduler } from 'rxjs/testing'
|
||||
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { describe, expect, it } from '@jest/globals'
|
||||
import { from, defer } from 'rxjs'
|
||||
import { TestScheduler } from 'rxjs/testing'
|
||||
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { describe, expect, it } from '@jest/globals'
|
||||
|
||||
import { dedupeWhitespace } from './strings'
|
||||
|
||||
describe('utils/string', () => {
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { describe, expect, it, test } from '@jest/globals'
|
||||
|
||||
import { lprToSelectionsZeroIndexed, encodeURIPathComponent, appendLineRangeQueryParameter } from './url'
|
||||
|
||||
/**
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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)
|
||||
})
|
||||
})
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -52,6 +52,7 @@ ts_project(
|
||||
tsconfig = ":tsconfig",
|
||||
deps = [
|
||||
":observability-server",
|
||||
"//:node_modules/@jest/globals",
|
||||
"//:node_modules/@types/node",
|
||||
],
|
||||
)
|
||||
|
||||
@ -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')
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { jest } from '@jest/globals'
|
||||
|
||||
/* eslint-disable ban/ban */
|
||||
|
||||
/**
|
||||
|
||||
@ -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'),
|
||||
}))
|
||||
|
||||
@ -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`,
|
||||
})
|
||||
|
||||
@ -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
Loading…
Reference in New Issue
Block a user