Skip to content

Commit

Permalink
work on test speed
Browse files Browse the repository at this point in the history
  • Loading branch information
narthur committed Aug 24, 2022
1 parent 99d2734 commit 43a59bd
Show file tree
Hide file tree
Showing 34 changed files with 74 additions and 34 deletions.
31 changes: 29 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,35 @@ module.exports = {
sourceType: 'module',
project: './tsconfig.json',
},
plugins: ['react', '@typescript-eslint'],
rules: {},
plugins: ['react', '@typescript-eslint', 'regex'],
rules: {
'regex/required': [
'error',
[
{
regex: 'describe.+from.+vitest',
message: 'Import `describe` explicitly.',
files: {
inspect: '\\.(test|spec)\\.tsx?$',
},
},
{
regex: 'it.+from.+vitest',
message: 'Import `it` explicitly.',
files: {
inspect: '\\.(test|spec)\\.tsx?$',
},
},
{
regex: 'expect.+from.+vitest',
message: 'Import `expect` explicitly.',
files: {
inspect: '\\.(test|spec)\\.tsx?$',
},
},
],
],
},
settings: {
react: {
version: 'detect',
Expand Down
2 changes: 1 addition & 1 deletion __mocks__/react-list.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { forwardRef } from 'react';
import { vi } from 'vitest';
import { vi, beforeEach } from 'vitest';

declare module 'react-list' {
const __listRef: {
Expand Down
5 changes: 0 additions & 5 deletions global-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ module.exports = async () => {
process.env.TZ = 'America/Chicago';
};

// vi.mock('react', async () => ({
// ...(await vi.importActual('react')),
// useLayoutEffect: (await vi.importActual('react')).useEffect,
// }));

vi.mock('@mui/x-date-pickers');

global.scrollTo = vi.fn() as any;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.30.1",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-regex": "^1.10.0",
"eslint-plugin-testing-library": "^5.6.0",
"jsdom": "^20.0.0",
"prettier": "2.4.1",
Expand Down
11 changes: 11 additions & 0 deletions pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion src/App.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { MemoryRouter } from 'react-router-dom';
import { __listRef } from 'react-list';
import { waitFor, screen } from '@testing-library/react';
import { addTask } from './lib/api';
import { vi, Mock } from 'vitest';
import { vi, Mock, describe, it, expect, beforeEach } from 'vitest';
import getQueryClient from './lib/getQueryClient';
import { QueryClient } from 'react-query';
import loadControlledPromise from './lib/test/loadControlledPromise';
Expand Down
1 change: 1 addition & 0 deletions src/components/molecules/FilterButton.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React from 'react';
import userEvent from '@testing-library/user-event';
import { renderWithQueryProvider } from '../../lib/test/helpers';
import { setCookie } from '../../lib/setCookie';
import { expect, it, describe } from 'vitest';

describe('FilterButton', () => {
it('uses local storage', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/molecules/Task.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { waitFor } from '@testing-library/dom';
import browser from '../../lib/Browser';
import { editTask } from '../../lib/api/editTask';
import { screen } from '@testing-library/react';
import { vi, Mock } from 'vitest';
import { vi, Mock, expect, it, describe, beforeEach } from 'vitest';
import { queryTaskCheckbox } from '../../lib/test/queries';

vi.mock('../../lib/api/updateTask');
Expand Down
2 changes: 1 addition & 1 deletion src/components/organisms/ApiSettings.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { screen } from '@testing-library/react';
import React from 'react';
import ApiSettings from './ApiSettings';
import { apiFetch } from '../../lib/api';
import { vi, Mock } from 'vitest';
import { vi, Mock, expect, it, describe } from 'vitest';

vi.mock('../../lib/api/getMe');
vi.mock('../../lib/api/updateMe');
Expand Down
2 changes: 1 addition & 1 deletion src/components/organisms/BeeminderSettings.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
withMutedReactQueryLogger,
} from '../../lib/test/helpers';
import userEvent from '@testing-library/user-event';
import { vi } from 'vitest';
import { vi, expect, it, describe, beforeEach } from 'vitest';
import { updateMe } from '../../lib/api';
import { getMe } from '../../lib/api';

Expand Down
2 changes: 1 addition & 1 deletion src/components/organisms/DueForm.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import React from 'react';
import TaskForm, { TaskFormProps } from './TaskForm';
import userEvent from '@testing-library/user-event';
import { vi } from 'vitest';
import { vi, describe, it, expect } from 'vitest';

vi.mock('@mui/x-date-pickers');

Expand Down
4 changes: 2 additions & 2 deletions src/components/organisms/GeneralSettings.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import GeneralSettings from './GeneralSettings';
import userEvent from '@testing-library/user-event';
import { screen } from '@testing-library/react';
import { vi } from 'vitest';
import { vi, expect, it, describe } from 'vitest';

vi.mock('../../lib/api/getMe');
vi.mock('../../lib/api/updateMe');
Expand All @@ -16,6 +16,6 @@ describe('general settings', () => {

userEvent.click(screen.getByText('Save'));

await screen.findByRole('progressbar');
expect(await screen.findByRole('progressbar')).toBeInTheDocument();
});
});
2 changes: 1 addition & 1 deletion src/components/organisms/Login.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { renderWithQueryProvider } from '../../lib/test/helpers';
import Login from './Login';
import React from 'react';
import userEvent from '@testing-library/user-event';
import { vi } from 'vitest';
import { vi, expect, it, describe, beforeEach } from 'vitest';
import { screen } from '@testing-library/react';

vi.mock('../../lib/LegacyApi');
Expand Down
2 changes: 1 addition & 1 deletion src/components/organisms/NavBar.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useSession } from '../../lib/api/useSession';
import userEvent from '@testing-library/user-event';
import { screen, waitFor } from '@testing-library/react';
import { BrowserRouter } from 'react-router-dom';
import { vi, Mock } from 'vitest';
import { vi, Mock, expect, it, describe } from 'vitest';
import { renderWithQueryProvider } from '../../lib/test/helpers';

vi.mock('../../lib/api/useSession');
Expand Down
6 changes: 4 additions & 2 deletions src/components/organisms/PasswordSettings.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { renderWithQueryProvider } from '../../lib/test/helpers';
import PasswordSettings from './PasswordSettings';
import userEvent from '@testing-library/user-event';
import { screen } from '@testing-library/react';
import { vi } from 'vitest';
import { vi, expect, it, describe } from 'vitest';

vi.mock('../../lib/api/updatePassword');

Expand All @@ -17,7 +17,9 @@ describe('password settings', () => {

userEvent.click(await screen.findByText('Save'));

await screen.findByText("Passwords don't match");
expect(
await screen.findByText("Passwords don't match")
).toBeInTheDocument();
});

it('indicates loading state', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/organisms/PaymentSettings.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import userEvent from '@testing-library/user-event';
import { waitFor, screen } from '@testing-library/react';
import PaymentSettings from './PaymentSettings';
import { useCheckoutSession } from '../../lib/api';
import { vi, Mock } from 'vitest';
import { vi, Mock, expect, it, describe } from 'vitest';

vi.mock('../../lib/api/getMe');
vi.mock('../../lib/api/updateMe');
Expand Down
2 changes: 1 addition & 1 deletion src/components/organisms/TaskForm.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import userEvent from '@testing-library/user-event';
import { TaskFormProps } from './TaskForm';
import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { vi } from 'vitest';
import { vi, expect, it, describe } from 'vitest';

vi.mock('../../lib/Browser');
vi.mock('@mui/x-date-pickers');
Expand Down
2 changes: 1 addition & 1 deletion src/components/organisms/TaskForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const TaskForm = (props: TaskFormProps): JSX.Element => {
} = props;
const [recurrenceEnabled, setRecurrenceEnabled] = useState<boolean>(false);
const [interval, setInterval] = useState<number>(1);
console.log(due);

return (
<Box component={'form'} className={'organism-taskForm'}>
<Stack spacing={2}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/pages/Account.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
renderWithQueryProvider,
} from '../../lib/test/helpers';
import userEvent from '@testing-library/user-event';
import { vi } from 'vitest';
import { vi, expect, it, describe, beforeEach } from 'vitest';
import { useGetApiToken } from '../../lib/api';
import { getCheckoutSession } from '../../lib/api/getCheckoutSession';

Expand Down
2 changes: 1 addition & 1 deletion src/components/pages/RecurringTasks.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import RecurringTasks from './RecurringTasks';
import getRecurringTasks from '../../lib/api/getRecurringTasks';
import updateRecurringTask from '../../lib/api/updateRecurringTask';
import { loadMe, renderWithQueryProvider } from '../../lib/test/helpers';
import { vi, Mock } from 'vitest';
import { vi, Mock, describe, it, expect, beforeEach } from 'vitest';

vi.mock('../../lib/api/getRecurringTasks');
vi.mock('../../lib/api/getMe');
Expand Down
2 changes: 1 addition & 1 deletion src/components/pages/Register.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Register from './Register';
import { waitFor, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { getTimezones } from '../../lib/api';
import { vi } from 'vitest';
import { vi, expect, it, describe, beforeEach } from 'vitest';
import register from '../../lib/api/register';

vi.mock('../../lib/api/getCheckoutSession');
Expand Down
2 changes: 1 addition & 1 deletion src/components/pages/Tasks.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { getUnloadMessage } from '../../lib/getUnloadMessage';
import browser from '../../lib/Browser';
import { __listRef } from '../../../__mocks__/react-list';
import { editTask } from '../../lib/api/editTask';
import { vi, Mock } from 'vitest';
import { vi, Mock, describe, it, expect, beforeEach } from 'vitest';
import loadControlledPromise from '../../lib/test/loadControlledPromise';
import { findTaskCheckbox } from '../../lib/test/queries';

Expand Down
1 change: 1 addition & 0 deletions src/lib/LegacyApi.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { login } from './LegacyApi';
import { waitFor } from '@testing-library/react';
import { expect, it, describe } from 'vitest';

describe('LegacyApi', () => {
it('stores session token on successful login', async () => {
Expand Down
1 change: 1 addition & 0 deletions src/lib/api/apiFetch.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { apiFetch } from './apiFetch';
import { expect, it, describe } from 'vitest';

describe('apiFetch', () => {
it('uses localStorage token', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/api/updateMe.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { updateMe } from './updateMe';
import { apiFetch } from './apiFetch';
import _ from 'lodash';
import { vi } from 'vitest';
import { vi, expect, it, describe, beforeEach } from 'vitest';

vi.mock('./apiFetch');

Expand Down
1 change: 1 addition & 0 deletions src/lib/api/useSession.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { logout, useSession } from './useSession';
import { act, renderHook } from '@testing-library/react';
import { expect, it, describe } from 'vitest';

describe('useSession', () => {
it('should return the session', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/getUnloadMessage.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getUnloadMessage } from './getUnloadMessage';
import React from 'react';
import { useUpdateTask } from './api/useUpdateTask';
import { renderWithQueryProvider, resolveWithDelay } from './test/helpers';
import { vi } from 'vitest';
import { vi, expect, it, describe } from 'vitest';
import { updateTask } from './api';

vi.mock('./api/updateTask');
Expand Down
1 change: 1 addition & 0 deletions src/lib/sortTasks.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { makeTask } from './test/helpers';
import { sortTasks } from './sortTasks';
import { expect, it, describe } from 'vitest';

describe('sortTasks', () => {
it('has secondary sort by stakes', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/test/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { waitFor } from '@testing-library/dom';
import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { vi, Mock, SpyInstance } from 'vitest';
import { vi, Mock, SpyInstance, expect } from 'vitest';
import { getMe, updateMe } from '../api';
import { createTheme, ThemeProvider } from '@mui/material/styles';

Expand Down
1 change: 1 addition & 0 deletions src/lib/useDifferenceToNow.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import useDifferenceToNow from './useDifferenceToNow';
import { loadNowTime, makeTask } from './test/helpers';
import { expect, it, describe } from 'vitest';

describe('useDifferenceToNow', () => {
it('handles future due', () => {
Expand Down
1 change: 1 addition & 0 deletions src/lib/useIsDue.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import useIsDue from './useIsDue';
import { loadNowTime, makeTask } from './test/helpers';
import { expect, it, describe } from 'vitest';

describe('useIsDue', () => {
it('returns is due', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/vitest.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it } from 'vitest';
import { describe, it, expect } from 'vitest';

describe('vitest', () => {
it('test 1', () => {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"types": ["vitest/globals", "@testing-library/jest-dom"],
"types": ["@testing-library/jest-dom"],
"allowUnreachableCode": true
},
"include": ["src", "vite.config.ts", "global-setup.ts", "__mocks__"],
Expand Down
3 changes: 0 additions & 3 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
/// <reference types="vitest" />
/// <reference types="vitest/globals" />
import { defineConfig } from 'vitest/config';
import react from '@vitejs/plugin-react';
import { visualizer } from 'rollup-plugin-visualizer';

export default defineConfig({
plugins: [react(), visualizer()],
test: {
globals: true,
environment: 'jsdom',
setupFiles: ['./global-setup.ts'],
mockReset: true,
include: ['./src/**/*.spec.{ts,tsx}'],
reporters: 'dot',
},
});

1 comment on commit 43a59bd

@github-actions
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.