Skip to content

Commit

Permalink
DSEGOG-341 Fix yarn preview:build:dev and address some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
joelvdavies committed Sep 3, 2024
1 parent 3a08d5a commit ce4b1c6
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 20 deletions.
1 change: 0 additions & 1 deletion src/images/imageWindow.component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { renderComponentWithProviders } from '../testUtils';
import ImageWindow from './imageWindow.component';

vi.mock('../windows/windowPortal.component', async () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const ReactMock = await vi.importActual('react');
return {
default: ReactMock.forwardRef(({ children }, ref) => (
Expand Down
1 change: 0 additions & 1 deletion src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ async function prepare() {
import.meta.env.VITE_APP_INCLUDE_MSW === 'true' ||
settingsResult?.apiUrl === ''
) {
// Need to use require instead of import as import breaks when loaded in SG
const { worker } = await import('./mocks/browser');
return worker.start({
onUnhandledRequest(request, print) {
Expand Down
2 changes: 0 additions & 2 deletions src/plotting/plot.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import {
} from '../app.types';
// only import types as we don't actually run any chart.js code in React
import type { ChartDataset, ChartOptions } from 'chart.js';
// we import this even though we don't use it so we can get typescript info added to ChartOptions
// eslint-disable-next-line @typescript-eslint/no-unused-vars

export interface PlotProps {
datasets: PlotDataset[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ describe('Plot Settings component', () => {

const createView = async () => {
// need to import like this in order for the doMock's to work
const PlotSettingsController =
// eslint-disable-next-line @typescript-eslint/no-var-requires
(await vi.importActual('./plotSettingsController.component')).default;
const PlotSettingsController = (
await vi.importActual('./plotSettingsController.component')
).default;
return render(<PlotSettingsController {...props} />);
};

Expand Down
1 change: 0 additions & 1 deletion src/plotting/plotWindow.component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { WindowPortal } from '../windows/windowPortal.component';
import PlotWindow from './plotWindow.component';

vi.mock('../windows/windowPortal.component', async () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const ReactMock = await vi.importActual('react');
return {
default: ReactMock.forwardRef(({ children }, ref) => (
Expand Down
8 changes: 1 addition & 7 deletions src/testUtils.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import React from 'react';
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';
// need to mock <canvas> for plotting
import { Action, ThunkAction } from '@reduxjs/toolkit';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import type { RenderOptions } from '@testing-library/react';
import { render } from '@testing-library/react';
import { matchRequestUrl } from 'msw';
import React from 'react';
import { Provider } from 'react-redux';
import { staticChannels } from './api/channels';
import {
Expand Down
2 changes: 0 additions & 2 deletions src/traces/tracePlot.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import React from 'react';
import { Waveform } from '../app.types';
// only import types as we don't actually run any chart.js code in React
import type { ChartData, ChartOptions } from 'chart.js';
// we import this even though we don't use it so we can get typescript info added to ChartOptions
// eslint-disable-next-line @typescript-eslint/no-unused-vars

export interface TracePlotProps {
trace: Waveform;
Expand Down
1 change: 0 additions & 1 deletion src/traces/traceWindow.component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { renderComponentWithProviders } from '../testUtils';
import TraceWindow from './traceWindow.component';

vi.mock('../windows/windowPortal.component', async () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const ReactMock = await vi.importActual('react');
return {
default: ReactMock.forwardRef(({ children }, ref) => (
Expand Down
8 changes: 6 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,16 @@ export default defineConfig(({ mode }) => {
// Config for deployment in SciGateway
config.build = {
lib: {
// https://github.com/vitejs/vite/issues/7130
// We use `umd` here as `es` causes some import statements to leak into the main.js, breaking the build
// removing this entirely uses a default of both, which for build results in `umd` taking precedence but when
// using --watch, `es` appears to replace it intermittently. Hopefully this can be fixed in the future and we
// can use `es` instead.
formats: ['umd'],
entry: 'src/main.tsx',
name: 'operationsgateway',
},
rollupOptions: {
external: ['react', 'react-dom'].concat(rollupExternals),
external: rollupExternals,
input: 'src/main.tsx',
output: {
entryFileNames: '[name].js',
Expand Down

0 comments on commit ce4b1c6

Please sign in to comment.