Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui: Add Jest as test runner to DB Console #82161

Merged
merged 29 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b213dd2
ui: Add jest dependencies and basic config to DB Console
May 16, 2022
905956a
ui: Jest + TSConfig Complete
May 19, 2022
0246339
ui: Refactor tests for Jest setup
May 20, 2022
1fe63bc
Setting Jest test environment to 'jsdom'
May 31, 2022
72e2098
ui: Converting fetchMock response for node-fetch
Jun 1, 2022
c118883
db-console: add @babel/plugin-transform-runtime
sjbarag Jun 1, 2022
2af7640
db-console: add missing identity-obj-proxy dependency
sjbarag Jun 1, 2022
d8a5192
db-console: make src/redux/uiData.spec.ts pass
sjbarag Jun 1, 2022
ca0f84f
db-console: don't transform cluster-ui during jest testing
sjbarag Jun 1, 2022
96421cd
db-console: break circular dependency with analytics and redux store
sjbarag Jun 1, 2022
e97a709
db-console: fix fakeApi for node
sjbarag Jun 1, 2022
4788bba
ui: Removing `src/enzymeInit` from `jobsTable.spec.tsx`
Jun 2, 2022
a253f70
ui: fixing error text mismatch
Jun 2, 2022
add3a0d
ui: clearing session storage for Jest test
Jun 2, 2022
fbba0d8
ui: fix app.spec.tsx tests
sjbarag Jun 2, 2022
638972c
ui: add larger debug buffer to jest
Jun 7, 2022
026bb6c
ui: fixing src/views/jobs/index.spex.ts tests
Jun 8, 2022
c414a99
ui: copyright header for linting
Jun 8, 2022
fc84191
Makefile: replace karma with jest in UI
Jun 10, 2022
5f3fb0b
ui, cmd: WIP Replacing Karma with Jest in Bazel
Jun 21, 2022
3a35b7d
ui: typo in comment
Jun 29, 2022
08cdbfb
db-console: run jest tests via Bazel
sjbarag Jun 30, 2022
e20c056
ui: A few adjustments to Bazel Jest test setup
Jul 7, 2022
8316561
jest: only load one copy of react
sjbarag Jul 7, 2022
da76414
Additional yarn-vendor dependencies
Jul 8, 2022
9d31d1e
ui: .babelrc replaced by babel.config.js
Jul 9, 2022
c19cd3f
cmd: Replace karma with jest in TestDataDriven/ui
Jul 10, 2022
cad63c4
ui: Linting fixes
Jul 10, 2022
24bee22
cmd: updating TestDataDriven/ui
Jul 11, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,7 @@ ui-lint: pkg/ui/yarn.installed $(ESLINT_PLUGIN_CRDB) $(UI_PROTOS_OSS) $(UI_PROTO
.PHONY: ui-test
ui-test: $(UI_PROTOS_OSS) $(UI_PROTOS_CCL) $(CLUSTER_UI_JS)
$(info $(yellow)NOTE: consider using `./dev ui test` instead of `make ui-test`$(term-reset))
$(NODE_RUN) -C pkg/ui/workspaces/db-console $(KARMA) start
$(NODE_RUN) -C pkg/ui/workspaces/db-console yarn test
$(NODE_RUN) -C pkg/ui/workspaces/cluster-ui yarn ci

.PHONY: ui-test-watch
Expand Down
2 changes: 1 addition & 1 deletion build/teamcity/cockroach/ci/tests/ui_test_impl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
set -xeuo pipefail

bazel build //pkg/cmd/bazci --config=ci
$(bazel info bazel-bin --config=ci)/pkg/cmd/bazci/bazci_/bazci test --config=ci //pkg/ui/workspaces/db-console:karma //pkg/ui/workspaces/cluster-ui:jest
$(bazel info bazel-bin --config=ci)/pkg/cmd/bazci/bazci_/bazci test --config=ci //pkg/ui/workspaces/db-console:jest //pkg/ui/workspaces/cluster-ui:jest
6 changes: 3 additions & 3 deletions pkg/cmd/dev/testdata/datadriven/ui
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ bazel test //pkg/ui:lint --test_output all
exec
dev ui test
----
bazel test //pkg/ui/workspaces/db-console:karma //pkg/ui/workspaces/cluster-ui:jest --test_output errors
bazel test //pkg/ui/workspaces/db-console:jest //pkg/ui/workspaces/cluster-ui:jest --test_output errors

exec
dev ui test --verbose
----
bazel test //pkg/ui/workspaces/db-console:karma //pkg/ui/workspaces/cluster-ui:jest --test_output all
bazel test //pkg/ui/workspaces/db-console:jest //pkg/ui/workspaces/cluster-ui:jest --test_output all

exec
dev ui test test --watch
Expand All @@ -114,7 +114,7 @@ cp sandbox/pkg/ui/workspaces/db-console/ccl/src/js/protos.d.ts crdb-checkout/pkg
rm -rf crdb-checkout/pkg/ui/workspaces/cluster-ui/dist
cp -r sandbox/pkg/ui/workspaces/cluster-ui/dist crdb-checkout/pkg/ui/workspaces/cluster-ui/dist
bazel info workspace --color=no
bazel run @yarn//:yarn -- --silent --cwd crdb-checkout/pkg/ui/workspaces/db-console karma:watch
bazel run @yarn//:yarn -- --silent --cwd crdb-checkout/pkg/ui/workspaces/db-console
bazel run @yarn//:yarn -- --silent --cwd crdb-checkout/pkg/ui/workspaces/cluster-ui jest --watch

exec
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/dev/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,6 @@ Replaces 'make ui-test' and 'make ui-test-watch'.`,
"--silent",
"--cwd",
dirs.dbConsole,
"karma:watch",
)

env := append(os.Environ(), "BAZEL_TARGET=fake")
Expand Down Expand Up @@ -490,7 +489,7 @@ Replaces 'make ui-test' and 'make ui-test-watch'.`,
)
args := append([]string{
"test",
"//pkg/ui/workspaces/db-console:karma",
"//pkg/ui/workspaces/db-console:jest",
"//pkg/ui/workspaces/cluster-ui:jest",
}, testOutputArg...)

Expand Down
3 changes: 0 additions & 3 deletions pkg/ui/workspaces/cluster-ui/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
const path = require("path");
const isBazel = !!process.env.BAZEL_TARGET;


const bazelOnlySettings = {
haste: {
// Platforms that include a POSIX-compatible `find` binary default to using it for test file
Expand All @@ -27,8 +26,6 @@ const bazelOnlySettings = {
};

module.exports = {
haste: isBazel ? {
} : undefined,
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
moduleNameMapper: {
"\\.(jpg|ico|jpeg|eot|otf|webp|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "identity-obj-proxy",
Expand Down
2 changes: 1 addition & 1 deletion pkg/ui/workspaces/cluster-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@cockroachlabs/design-tokens": "0.4.5",
"@cockroachlabs/eslint-config": "^0.1.11",
"@cockroachlabs/eslint-plugin-crdb": "link:../eslint-plugin-crdb",
"@cockroachlabs/icons": "0.3.0",
"@cockroachlabs/icons": "0.5.2",
"@cockroachlabs/ui-components": "0.2.20",
"@popperjs/core": "^2.4.0",
"@reduxjs/toolkit": "^1.5.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import React from "react";
import { assert } from "chai";
import { shallow } from "enzyme";
import { earliestRetainedTime } from "./jobsPage.fixture";

import { JobTable, JobTableProps } from "./jobTable";

describe("<JobTable>", () => {
Expand Down
7 changes: 3 additions & 4 deletions pkg/ui/workspaces/cluster-ui/src/jobs/jobsPage/jobTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import { cockroach, google } from "@cockroachlabs/crdb-protobuf-client";
import { Tooltip } from "@cockroachlabs/ui-components";
import { isEqual, map } from "lodash";
import React from "react";
import { Nodes, MagnifyingGlass } from "@cockroachlabs/icons";
import { Anchor } from "src/anchor";
import { JobsResponse } from "src/api/jobsApi";
import emptyTableResultsIcon from "src/assets/emptyState/empty-table-results.svg";
import magnifyingGlassIcon from "src/assets/emptyState/magnifying-glass.svg";
import { EmptyTable } from "src/empty";
import { Pagination, ResultsPerPageLabel } from "src/pagination";
import { ColumnDescriptor, SortSetting, SortedTable } from "src/sortedtable";
Expand Down Expand Up @@ -282,7 +281,7 @@ export class JobTable extends React.Component<JobTableProps, JobTableState> {
return (
<EmptyTable
title="No jobs match your search"
icon={magnifyingGlassIcon}
icon={<MagnifyingGlass />}
footer={
<Anchor href={jobTable} target="_blank">
Learn more about jobs
Expand All @@ -294,7 +293,7 @@ export class JobTable extends React.Component<JobTableProps, JobTableState> {
return (
<EmptyTable
title="No jobs to show"
icon={emptyTableResultsIcon}
icon={<Nodes />}
message="The jobs page provides details about backup/restore jobs, schema changes, user-created table statistics, automatic table statistics jobs and changefeeds."
footer={
<Anchor href={jobTable} target="_blank">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
// licenses/APL.txt.

import React from "react";
import { Spinner } from "@cockroachlabs/icons";
import { Spin, Icon } from "antd";
import "antd/lib/spin/style";
import "antd/lib/icon/style";
import { Spinner } from "@cockroachlabs/ui-components";
import classNames from "classnames/bind";
import styles from "./tableSpinner.module.scss";

Expand All @@ -29,10 +26,7 @@ export const TableSpinner = ({ loadingLabel }: TableSpinnerProps) => {

return (
<div className={tableSpinnerClass}>
<Spin
className={spinClass}
indicator={<Icon component={Spinner} spin />}
/>
<Spinner className={spinClass} />
{loadingLabel && (
<span className={loadingLabelClass}>{loadingLabel}</span>
)}
Expand Down
1 change: 1 addition & 0 deletions pkg/ui/workspaces/cluster-ui/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ module.exports = (env, argv) => {
amd: "react-dom",
root: "ReactDom",
},
"react-router": "react-router",
"react-router-dom": "react-router-dom",
"react-redux": "react-redux",
"redux-saga": "redux-saga",
Expand Down
8 changes: 4 additions & 4 deletions pkg/ui/workspaces/cluster-ui/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1598,10 +1598,10 @@
version "0.0.0"
uid ""

"@cockroachlabs/icons@0.3.0":
version "0.3.0"
resolved "https://registry.yarnpkg.com/@cockroachlabs/icons/-/icons-0.3.0.tgz#160573074396f266e92fcbe5e520c5ba1d8750f9"
integrity sha512-GJxhlXy8Z3/PYFb9C3iM1dvU9wajGoaA/+VCj0an2ipfbkI2fhToq+h0b33vu7JuZ3dS4QMRjfVE4uhlyIUH2Q==
"@cockroachlabs/icons@0.5.2":
version "0.5.2"
resolved "https://registry.yarnpkg.com/@cockroachlabs/icons/-/icons-0.5.2.tgz#ddf87eba8e173f7ee6c787e178f460a0a1872b80"
integrity sha512-+2JJegu+MPb4S2l7LJwPnbkmZuBlPdMBJNr4vqLdcEePcLAgOpEfGMlF1HV1Mb8YbDEFWUT9E0gZ/PRjjMalog==

"@cockroachlabs/icons@^0.4.3":
version "0.4.3"
Expand Down
6 changes: 0 additions & 6 deletions pkg/ui/workspaces/db-console/.babelrc

This file was deleted.

81 changes: 35 additions & 46 deletions pkg/ui/workspaces/db-console/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
load("@npm_db_console//webpack-cli:index.bzl", webpack = "webpack_cli")
load("@npm_db_console//karma:index.bzl", "karma_test")
load("@npm_db_console//stylint:index.bzl", "stylint_test")
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test")
load("@npm_db_console//eslint:index.bzl", "eslint_test")
load("@npm_db_console//typescript:index.bzl", "tsc_test")
load("@npm_db_console//jest:index.bzl", "jest_test")

# TODO (koorosh): keeping the list of deps up to date is a candidate to be
# autogenerated in scope of `dev generate bazel`.
Expand All @@ -16,6 +16,8 @@ DEV_DEPENDENCIES = [
"@npm_db_console//@babel/core",
"@npm_db_console//@babel/preset-env",
"@npm_db_console//@babel/preset-react",
"@npm_db_console//@babel/runtime",
"@npm_db_console//@babel/plugin-transform-runtime",
"@npm_db_console//@cockroachlabs/eslint-config",
"@npm_db_console//@storybook/react",
"@npm_db_console//@testing-library/react",
Expand Down Expand Up @@ -82,13 +84,6 @@ DEV_DEPENDENCIES = [
"@npm_db_console//html-webpack-template",
"@npm_db_console//http-proxy-middleware",
"@npm_db_console//jsdoc",
"@npm_db_console//karma-chai",
"@npm_db_console//karma-chrome-launcher",
"@npm_db_console//karma-mocha",
"@npm_db_console//karma-mocha-reporter",
"@npm_db_console//karma-sinon",
"@npm_db_console//karma-sourcemap-loader",
"@npm_db_console//karma-webpack",
"@npm_db_console//less-loader",
"@npm_db_console//minimist",
"@npm_db_console//mocha",
Expand Down Expand Up @@ -162,7 +157,7 @@ DEPENDENCIES = [
] + DEV_DEPENDENCIES

WEBPACK_DATA_COMMON = [
".babelrc",
"babel.config.js",
".eslintrc.json",
".stylintrc",
"assets",
Expand Down Expand Up @@ -327,48 +322,42 @@ CCL_NOT_PROTO_CLIENT = glob(
exclude = ["protos.*"],
)

KARMA_DEPS = [
":node_modules",
".babelrc",
JEST_DEPS = DEPENDENCIES + [
".eslintrc.json",
".stylintrc",
"assets",
"favicon.ico",
"fonts",
"styl",
"babel.config.js",
"package.json",
"jest.config.js",
"tsconfig.json",
"webpack.config.js",
"karma.conf.js",
"tests-loader.js",
"//pkg/ui/workspaces/cluster-ui:cluster-ui",
"tsconfig.linting.json",
"@npm_db_console//@babel/plugin-proposal-class-properties",
"@npm_db_console//@babel/plugin-proposal-object-rest-spread",
"@npm_db_console//@babel/plugin-transform-modules-commonjs",
"@npm_db_console//@reduxjs/toolkit",
"@npm_db_console//identity-obj-proxy",
"@npm_db_console//ts-jest",
"@npm_db_console//jest-enzyme",
"@npm_db_console//jest-canvas-mock",
"//pkg/ui/workspaces/db-console/src/js:crdb-protobuf-client",
"//pkg/ui/workspaces/db-console/ccl/src/js:crdb-protobuf-client-ccl",
] + SRC_NOT_PROTO_CLIENT + CCL_NOT_PROTO_CLIENT + DEPENDENCIES

karma_test(
name = "karma",
data = KARMA_DEPS,
templated_args = [
"start",
"$(execpath karma.conf.js)",
],
visibility = ["//visibility:public"],
)
"//pkg/ui/workspaces/cluster-ui:cluster-ui",
# A copy of protobufjs from the protobuf client's dependencies is required
# to avoid "cannot find module protobufjs/minimal" errors when Babel
# attempts to transpile the protobuf client during testing.
"@npm_protos//protobufjs",
] + glob([
"src/**",
"ccl/**",
])

karma_test(
name = "karma-watch",
data = KARMA_DEPS,
tags = [
# Reduce test startup times under ibazel by letting the karma process run between file changes
"ibazel_notify_changes",
],
jest_test(
name = "jest",
size = "enormous",
data = JEST_DEPS,
templated_args = [
"start",
"$(execpath karma.conf.js)",
# Reduce test startup times under ibazel by using the default karma watchers
"--auto-watch",
# Don't close the karma server after tests complete
"--no-single-run",
"--node_options=--max-old-space-size=8192",
"-w 25%",
"--ci",
"--config",
"$(rootpath jest.config.js)",
],
visibility = ["//visibility:public"],
)
49 changes: 49 additions & 0 deletions pkg/ui/workspaces/db-console/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2022 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
/* globals module */

const presets = [
[
"@babel/env",
{
modules: "commonjs",
},
],
"@babel/react",
];

const plugins = [
"@babel/proposal-class-properties",
"@babel/proposal-object-rest-spread",
// @babel/plugin-transform-runtime is required to support dynamic loading of cluster-ui package
"@babel/plugin-transform-runtime",
["import", { libraryName: "antd", style: true }],
];

const env = {
test: {
plugins: ["@babel/plugin-transform-modules-commonjs"],
},
};

/*
For dependencies that expect the value of `this` to be equivelant to
the global `window` object (d3 specifically), we need Babel to process
these dependencies as "script" rather than "module". Modules are run in
"strict mode" where the value of a global `this` will be undefined where
as in non-strict mode a global this will be equal to global window.

Source type "unambiguous" will treat any file containing `import` or
`export` as a module and any file without as a script (non-strict mode).
See https://babeljs.io/docs/en/options#sourcetype for more details
*/
const sourceType = "unambiguous";

module.exports = { presets, plugins, env, sourceType };
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { shallow } from "enzyme";
import { createMemoryHistory, History } from "history";
import { match as Match } from "react-router-dom";

import "src/enzymeInit";
import { ClusterVisualization } from "./index";
import { Breadcrumbs } from "./breadcrumbs";

Expand Down
Loading