Skip to content

Commit

Permalink
[eslint-config] Add recommended jest lint (#7807)
Browse files Browse the repository at this point in the history
  • Loading branch information
hellendag committed May 9, 2022
1 parent 7055f90 commit 10d9fc5
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 30 deletions.
1 change: 1 addition & 0 deletions js_modules/dagit/packages/core/src/app/AppTopNav.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ describe('AppTopNav', () => {
});

// todo dish: Figure out what graphql-tools is doing with this mock. 🤪
// eslint-disable-next-line jest/no-disabled-tests
it.skip('shows the error message when repo location errors are found', async () => {
const mocks = {
RepositoryLocationOrLoadError: () => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'jest';
import {RegExps} from './codemirror-yaml/mode';

it('recognizes a double quoted string with escaped double quotes', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,9 @@ describe('useQueryPersistedState', () => {
);

screen.getByText(`Functions Same: true`).click();
expect(screen.getByText(`Functions Same: true`)).toBeVisible();
screen.getByText(`Functions Same: true`).click();
expect(screen.getByText(`Functions Same: true`)).toBeVisible();
});

it('correctly encodes arrays, using bracket syntax', () => {
Expand Down
3 changes: 1 addition & 2 deletions js_modules/dagit/packages/core/src/runs/RunDetails.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('RunDetails', () => {
global.Date.now = dateNow;
});

it.only('renders QUEUED details', async () => {
it('renders QUEUED details', async () => {
renderAll({status: RunStatus.QUEUED, startTime: null, endTime: null});

await waitFor(() => {
Expand Down Expand Up @@ -148,7 +148,6 @@ describe('RunDetails', () => {
});

await waitFor(() => {
jest.runTimersToTime(5000);
expect(screen.getByRole('row', {name: /started feb 17, 6:24:30 am/i})).toBeVisible();
expect(screen.getByRole('row', {name: /ended canceling/i})).toBeVisible();
expect(screen.getByRole('row', {name: /duration timer 0:01:01/i})).toBeVisible();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('batchRunsForTimeline', () => {
const minChunkWidth = 2;
const minMultipleWidth = 18;

const test = (runs: RunWithTime[]) =>
const getBatch = (runs: RunWithTime[]) =>
batchRunsForTimeline({runs, start, end, width, minChunkWidth, minMultipleWidth});

describe('Overlapping', () => {
Expand All @@ -20,7 +20,7 @@ describe('batchRunsForTimeline', () => {
const runB = {startTime: 30, endTime: 70};
const runs = [runA, runB];

const batched = test(runs);
const batched = getBatch(runs);
expect(batched.length).toBe(1);
const batch = batched[0];
expect(batch.startTime).toBe(10);
Expand All @@ -40,7 +40,7 @@ describe('batchRunsForTimeline', () => {
const runB = {startTime: 30, endTime: 40};
const runs = [runA, runB];

const batched = test(runs);
const batched = getBatch(runs);
expect(batched.length).toBe(1);
const batch = batched[0];
expect(batch.startTime).toBe(10);
Expand All @@ -62,7 +62,7 @@ describe('batchRunsForTimeline', () => {
const runC = {startTime: 40, endTime: 90};
const runs = [runA, runB, runC];

const batched = test(runs);
const batched = getBatch(runs);
expect(batched.length).toBe(1);
const batch = batched[0];
expect(batch.startTime).toBe(10);
Expand All @@ -85,7 +85,7 @@ describe('batchRunsForTimeline', () => {
const runC = {startTime: 40, endTime: 70};
const runs = [runA, runB, runC];

const batched = test(runs);
const batched = getBatch(runs);
expect(batched.length).toBe(1);
const batch = batched[0];
expect(batch.startTime).toBe(10);
Expand All @@ -106,7 +106,7 @@ describe('batchRunsForTimeline', () => {
const runB = {startTime: 40, endTime: 100};
const runs = [runA, runB];

const batched = test(runs);
const batched = getBatch(runs);
expect(batched.length).toBe(1);
const batch = batched[0];
expect(batch.startTime).toBe(10);
Expand All @@ -126,7 +126,7 @@ describe('batchRunsForTimeline', () => {
const runB = {startTime: 50, endTime: 70};
const runs = [runA, runB];

const batched = test(runs);
const batched = getBatch(runs);
expect(batched.length).toBe(1);
const batch = batched[0];
expect(batch.startTime).toBe(10);
Expand All @@ -148,7 +148,7 @@ describe('batchRunsForTimeline', () => {
const runB = {startTime: 40, endTime: 70};
const runs = [runA, runB];

const batched = test(runs);
const batched = getBatch(runs);
expect(batched.length).toBe(2);

// Batch A contains the later run due to sorting.
Expand Down Expand Up @@ -178,7 +178,7 @@ describe('batchRunsForTimeline', () => {
const runC = {startTime: 80, endTime: 90};
const runs = [runA, runB, runC];

const batched = test(runs);
const batched = getBatch(runs);
expect(batched.length).toBe(3);

// Sorting results in later runs being in the first batch.
Expand Down Expand Up @@ -207,7 +207,7 @@ describe('batchRunsForTimeline', () => {
describe('Minimum widths', () => {
it('uses minimum chunk width for tiny runs', () => {
const tinyRun = {startTime: 10, endTime: 11};
const batched = test([tinyRun]);
const batched = getBatch([tinyRun]);

const [batch] = batched;
expect(batch.startTime).toBe(10);
Expand All @@ -220,7 +220,7 @@ describe('batchRunsForTimeline', () => {
it('uses minimum multiple-run width for batched runs', () => {
const tinyRunA = {startTime: 10, endTime: 11};
const tinyRunB = {startTime: 10, endTime: 12};
const batched = test([tinyRunA, tinyRunB]);
const batched = getBatch([tinyRunA, tinyRunB]);

const [batch] = batched;
expect(batch.startTime).toBe(10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from './useQueryPersistedLogFilter';

describe('encodeRunPageFilters', () => {
it('serializes log levels, ', () => {
it('serializes log levels,', () => {
expect(
encodeRunPageFilters({
hideNonMatches: true,
Expand Down
15 changes: 8 additions & 7 deletions js_modules/dagit/packages/core/src/scripts/DownloadMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@ import path from 'path';
import {addTypenameToDocument} from '@apollo/client/utilities';
import {print} from 'graphql/language/printer';

/*
Why is this script structured as a Jest test? Jest goes to great lengths to
setup a NodeJS execution environment that also mimics a browser, so we can read/
write to the filesystem but ALSO load all of the application code (and retrieve
the query objects), etc. We could set all this up (new tsconfig, jsdom, etc.) but
leveraging Jest is easiest.
*/
/**
* Why is this script structured as a Jest test? Jest goes to great lengths to
* setup a NodeJS execution environment that also mimics a browser, so we can read/
* write to the filesystem but ALSO load all of the application code (and retrieve
* the query objects), etc. We could set all this up (new tsconfig, jsdom, etc.) but
* leveraging Jest is easiest.
*/

// collect mocks from various tests in the codebase
import {MOCKS as SVGMocks} from '../testing/SVGMocks';

const dagsterRoot = path.resolve(path.join(__dirname, '..', '..', '..', '..'));

// eslint-disable-next-line jest/expect-expect
it(`builds mocks`, () => {
for (const mock of SVGMocks) {
const query = print(addTypenameToDocument(mock.query))
Expand Down
1 change: 1 addition & 0 deletions js_modules/dagit/packages/eslint-config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
parser: '@typescript-eslint/parser',
extends: [
'plugin:react/recommended',
'plugin:jest/recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended', // Prettier plugin must be last!
],
Expand Down
1 change: 1 addition & 0 deletions js_modules/dagit/packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@typescript-eslint/parser": "5.21.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-jest": "^26.1.5",
"eslint-plugin-jsx-a11y": "6.5.1",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "7.29.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ describe('TokenizingField', () => {
},
];

const expectOptions = (expected: string[]) => {
const getItems = () => {
const items = screen.getAllByRole('listitem');
const actual = items.map((item) => item.textContent);
expect(actual).toEqual(expected);
return items.map((item) => item.textContent);
};

it('shows available autocompletion options when clicked', async () => {
Expand All @@ -31,7 +30,7 @@ describe('TokenizingField', () => {
userEvent.click(input);

await waitFor(() => {
expectOptions(['pipeline:', 'status:']);
expect(getItems()).toEqual(['pipeline:', 'status:']);
});
});

Expand All @@ -43,7 +42,7 @@ describe('TokenizingField', () => {
userEvent.type(input, 'pipeli');

await waitFor(() => {
expectOptions([
expect(getItems()).toEqual([
'pipeline:',
'pipeline:airline_demo_ingest',
'pipeline:airline_demo_warehouse',
Expand All @@ -55,7 +54,7 @@ describe('TokenizingField', () => {
userEvent.type(input, 'pipeline');

await waitFor(() => {
expectOptions([
expect(getItems()).toEqual([
'pipeline:',
'pipeline:airline_demo_ingest',
'pipeline:airline_demo_warehouse',
Expand All @@ -67,7 +66,7 @@ describe('TokenizingField', () => {
userEvent.type(input, 'pipeline:');

await waitFor(() => {
expectOptions([
expect(getItems()).toEqual([
'pipeline:airline_demo_ingest',
'pipeline:airline_demo_warehouse',
'pipeline:composition',
Expand All @@ -83,7 +82,10 @@ describe('TokenizingField', () => {
userEvent.type(input, 'airline');

await waitFor(() => {
expectOptions(['pipeline:airline_demo_ingest', 'pipeline:airline_demo_warehouse']);
expect(getItems()).toEqual([
'pipeline:airline_demo_ingest',
'pipeline:airline_demo_warehouse',
]);
});
});
});
79 changes: 79 additions & 0 deletions js_modules/dagit/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5537,6 +5537,7 @@ __metadata:
eslint: ^8.6.0
eslint-config-prettier: 8.5.0
eslint-plugin-import: 2.26.0
eslint-plugin-jest: ^26.1.5
eslint-plugin-jsx-a11y: 6.5.1
eslint-plugin-prettier: ^4.0.0
eslint-plugin-react: 7.29.4
Expand Down Expand Up @@ -9815,6 +9816,16 @@ __metadata:
languageName: node
linkType: hard

"@typescript-eslint/scope-manager@npm:5.22.0":
version: 5.22.0
resolution: "@typescript-eslint/scope-manager@npm:5.22.0"
dependencies:
"@typescript-eslint/types": 5.22.0
"@typescript-eslint/visitor-keys": 5.22.0
checksum: ebf2ad44f4e5a4dfd55225419804f81f68056086c20f1549adbcca4236634eac3aae461e30d6cab6539ce6f42346ed6e1fbbb2710d2cc058a3283ef91a0fe174
languageName: node
linkType: hard

"@typescript-eslint/scope-manager@npm:5.7.0":
version: 5.7.0
resolution: "@typescript-eslint/scope-manager@npm:5.7.0"
Expand Down Expand Up @@ -9848,6 +9859,13 @@ __metadata:
languageName: node
linkType: hard

"@typescript-eslint/types@npm:5.22.0":
version: 5.22.0
resolution: "@typescript-eslint/types@npm:5.22.0"
checksum: 74f822c5a3b96bba05229eea4ed370c4bd48b17f475c37f08d6ba708adf65c3aa026bb544f1d0308c96e043b30015e396fd53b1e8e4e9fbb6dc9c92d2ccc0a15
languageName: node
linkType: hard

"@typescript-eslint/types@npm:5.7.0":
version: 5.7.0
resolution: "@typescript-eslint/types@npm:5.7.0"
Expand All @@ -9873,6 +9891,24 @@ __metadata:
languageName: node
linkType: hard

"@typescript-eslint/typescript-estree@npm:5.22.0":
version: 5.22.0
resolution: "@typescript-eslint/typescript-estree@npm:5.22.0"
dependencies:
"@typescript-eslint/types": 5.22.0
"@typescript-eslint/visitor-keys": 5.22.0
debug: ^4.3.2
globby: ^11.0.4
is-glob: ^4.0.3
semver: ^7.3.5
tsutils: ^3.21.0
peerDependenciesMeta:
typescript:
optional: true
checksum: 2797a79d7d32a9a547b7f1de77a353d8e8c8519791f865f5e061bfc4918d12cdaddec51afa015f5aac5d068ef525c92bd65afc83b84dc9e52e697303acf0873a
languageName: node
linkType: hard

"@typescript-eslint/typescript-estree@npm:5.7.0":
version: 5.7.0
resolution: "@typescript-eslint/typescript-estree@npm:5.7.0"
Expand Down Expand Up @@ -9907,6 +9943,22 @@ __metadata:
languageName: node
linkType: hard

"@typescript-eslint/utils@npm:^5.10.0":
version: 5.22.0
resolution: "@typescript-eslint/utils@npm:5.22.0"
dependencies:
"@types/json-schema": ^7.0.9
"@typescript-eslint/scope-manager": 5.22.0
"@typescript-eslint/types": 5.22.0
"@typescript-eslint/typescript-estree": 5.22.0
eslint-scope: ^5.1.1
eslint-utils: ^3.0.0
peerDependencies:
eslint: ^6.0.0 || ^7.0.0 || ^8.0.0
checksum: 5019485e76d754a7a60c042545fd884dc666fddf9d4223ff706bbf0c275f19ea25a6b210fb5cf7ed368b019fe538fd854a925e9c6f12007d51b1731a29d95cc1
languageName: node
linkType: hard

"@typescript-eslint/visitor-keys@npm:5.21.0":
version: 5.21.0
resolution: "@typescript-eslint/visitor-keys@npm:5.21.0"
Expand All @@ -9917,6 +9969,16 @@ __metadata:
languageName: node
linkType: hard

"@typescript-eslint/visitor-keys@npm:5.22.0":
version: 5.22.0
resolution: "@typescript-eslint/visitor-keys@npm:5.22.0"
dependencies:
"@typescript-eslint/types": 5.22.0
eslint-visitor-keys: ^3.0.0
checksum: d30dfa98dcce75da49a6a204a0132d42e63228c35681cb9b3643e47a0a24a633e259832d48d101265bd85b8eb5a9f2b4858f9447646c1d3df6a2ac54258dfe8f
languageName: node
linkType: hard

"@typescript-eslint/visitor-keys@npm:5.7.0":
version: 5.7.0
resolution: "@typescript-eslint/visitor-keys@npm:5.7.0"
Expand Down Expand Up @@ -15523,6 +15585,23 @@ __metadata:
languageName: node
linkType: hard

"eslint-plugin-jest@npm:^26.1.5":
version: 26.1.5
resolution: "eslint-plugin-jest@npm:26.1.5"
dependencies:
"@typescript-eslint/utils": ^5.10.0
peerDependencies:
"@typescript-eslint/eslint-plugin": ^5.0.0
eslint: ^6.0.0 || ^7.0.0 || ^8.0.0
peerDependenciesMeta:
"@typescript-eslint/eslint-plugin":
optional: true
jest:
optional: true
checksum: 727487c6d0cc4aa66f8209fc187a2f4eb56ffea6569dacb04bb1e3272221d6238460fb967a12074acac50b0b545d2190c697bad64ebc6c8bdd4e8f3cc66d5a68
languageName: node
linkType: hard

"eslint-plugin-jsx-a11y@npm:6.5.1":
version: 6.5.1
resolution: "eslint-plugin-jsx-a11y@npm:6.5.1"
Expand Down

1 comment on commit 10d9fc5

@vercel
Copy link

@vercel vercel bot commented on 10d9fc5 May 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

dagit-storybook – ./js_modules/dagit/packages/ui

dagit-storybook-git-master-elementl.vercel.app
dagit-storybook-elementl.vercel.app
dagit-storybook.vercel.app

Please sign in to comment.