Skip to content

Commit

Permalink
chore: migrate to vite and vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
langdal committed Nov 18, 2022
1 parent 540a750 commit 4944d27
Show file tree
Hide file tree
Showing 32 changed files with 2,263 additions and 3,479 deletions.
2 changes: 1 addition & 1 deletion .env.development
Original file line number Diff line number Diff line change
@@ -1 +1 @@
NEXT_PUBLIC_API_SERVER=http://localhost:9090/v1.0
VITE_PUBLIC_API_SERVER=http://localhost:9090/v1.0
2 changes: 1 addition & 1 deletion .env.production
Original file line number Diff line number Diff line change
@@ -1 +1 @@
NEXT_PUBLIC_API_SERVER=http://localhost:9090/v1.0
VITE_PUBLIC_API_SERVER=http://localhost:9090/v1.0
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"plugins": ["react", "prettier"],
"extends": ["next/core-web-vitals", "prettier"]
"extends": ["prettier"]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ db
/specification.yml
.vscode
tsconfig.tsbuildinfo
dist
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.github
node_modules
out
dist
public
tmp
openapi
Expand Down
14 changes: 14 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Process Optimizer Frontend</title>
<script type="module" src="/src/jquery-shim.ts"></script>
<script type="module" src="/src/main.tsx"></script>
</head>
<body>
<div id="root"></div>
</body>
</html>
14 changes: 0 additions & 14 deletions jest.config.js

This file was deleted.

5 changes: 0 additions & 5 deletions next-env.d.ts

This file was deleted.

23 changes: 0 additions & 23 deletions next.config.js

This file was deleted.

19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"build-static": "next build && next export",
"start": "next start",
"dev": "vite",
"build": "tsc && vite build",
"build-static": "tsc && vite build --outDir out",
"start": "vite preview",
"lint": "eslint .",
"formatAll": "prettier --write .",
"test": "jest",
"prettier": "prettier --check .",
"test": "vitest",
"prepare": "husky install",
"openapi": "openapi-generator-cli generate -i https://raw.githubusercontent.com/BoostV/process-optimizer-api/v2.1.0/optimizerapi/openapi/specification.yml -g typescript-fetch -o ./openapi --additional-properties=nullSafeAdditionalProps && prettier --write ./openapi"
},
Expand All @@ -30,7 +31,6 @@
"eslint-config-prettier": "8.5.0",
"eslint-plugin-prettier": "4.1.0",
"immer": "^9.0.15",
"next": "^12.1.6",
"prettier": "2.7.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand All @@ -43,7 +43,6 @@
},
"devDependencies": {
"@openapitools/openapi-generator-cli": "2.5.1",
"@swc/jest": "^0.2.21",
"@testing-library/dom": "^8.13.0",
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.3.0",
Expand All @@ -57,13 +56,15 @@
"git-revision-webpack-plugin": "^5.0.0",
"husky": "^8.0.1",
"identity-obj-proxy": "^3.0.0",
"jest": "^28.1.1",
"jest-dom": "^4.0.0",
"jest-environment-jsdom": "^28.1.1",
"lint-staged": "^13.0.3",
"node-mocks-http": "^1.10.1",
"react-devtools": "^4.24.7",
"rimraf": "^3.0.2",
"typescript": "^4.7.4"
"typescript": "^4.7.4",
"vite": "^3.2.4",
"@vitejs/plugin-react": "^2.2.0",
"vitest": "^0.25.2"
}
}
39 changes: 0 additions & 39 deletions pages/_app.tsx

This file was deleted.

84 changes: 0 additions & 84 deletions pages/_document.tsx

This file was deleted.

8 changes: 0 additions & 8 deletions pages/index.tsx

This file was deleted.

22 changes: 22 additions & 0 deletions src/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as React from 'react'
import CssBaseline from '@mui/material/CssBaseline'
import { GlobalStateProvider } from '@/context/global'
import ExperimentContainer from './experiment-container'
import createEmotionCache from './createEmotionCache'
import { CacheProvider } from '@emotion/react'
import Home from '@/components/home/home'

const emotionCache = createEmotionCache()

export default function MyApp() {
return (
<CacheProvider value={emotionCache}>
<GlobalStateProvider>
{/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}
<CssBaseline />
<Home />
<ExperimentContainer experimentId="4b1e207a-85e5-4800-b4f3-cfeb21338798" />
</GlobalStateProvider>
</CacheProvider>
)
}
19 changes: 7 additions & 12 deletions src/components/home/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ import { MouseEvent, useCallback, useReducer, useState } from 'react'
import { useDropzone } from 'react-dropzone'
import Layout from '@/components/layout/layout'
import useStyles from './home.style'
import { NextRouter, useRouter } from 'next/router'
import SystemUpdateAltIcon from '@mui/icons-material/SystemUpdateAlt'
import ChevronRightIcon from '@mui/icons-material/ChevronRight'
import DeleteIcon from '@mui/icons-material/Delete'
import { buildPath, paths } from '../../../paths'
import { ExperimentType } from '@/types/common'
import { useGlobal } from '@/context/global'
import { v4 as uuid } from 'uuid'
Expand All @@ -33,7 +31,6 @@ type UploadMessage = {

export default function Home() {
const { classes } = useStyles()
const router: NextRouter = useRouter()
const { state, dispatch } = useGlobal()
const [isSnackbarOpen, setSnackbarOpen] = useState(false)
const [deletionState, dispatchDeletion] = useReducer(reducer, {
Expand All @@ -45,13 +42,10 @@ export default function Home() {
})
const [tempExperiment, setTempExperiment] = useState<ExperimentType>()

const saveExperimentLocally = useCallback(
(experiment: ExperimentType) => {
localStorage.setItem(experiment.id, JSON.stringify({ experiment }))
router.push(buildPath(paths.experiment, experiment.id))
},
[router]
)
const saveExperimentLocally = useCallback((experiment: ExperimentType) => {
localStorage.setItem(experiment.id, JSON.stringify({ experiment }))
// router.push(buildPath(paths.experiment, experiment.id))
}, [])

const onDrop = useCallback(
(acceptedFiles: Blob[]) => {
Expand Down Expand Up @@ -106,12 +100,13 @@ export default function Home() {

const createNewExperiment = () => {
deleteExperiments()
router.push(buildPath(paths.experiment, uuid()))
// router.push(buildPath(paths.experiment, uuid()))
}

const openSavedExperiment = (key: string) => {
deleteExperiments()
router.push(buildPath(paths.experiment, key))
console.log('TODO route to ' + key)
// router.push(buildPath(paths.experiment, key))
}

const getExperimentName = (key: string) => {
Expand Down
7 changes: 2 additions & 5 deletions src/components/layout/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import {
AppBar,
Box,
Button,
Switch,
Toolbar,
Typography,
FormControlLabel,
Button,
} from '@mui/material'
import Link from 'next/link'
import useStyles from './layout.style'
import { useGlobal } from '@/context/global'
import { VersionInfo } from '@/components/version-info'
Expand Down Expand Up @@ -106,9 +105,7 @@ export default function Layout({ children }: Props) {
Brownie Bee
</Typography>
<div className={classes.links}>
<Link href="/" passHref>
<Button className={classes.link}>Home</Button>
</Link>
<Button className={classes.link}>Home</Button>
</div>
<div
onClick={() => {
Expand Down
7 changes: 2 additions & 5 deletions src/components/plots/bokeh-plot/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import dynamic from 'next/dynamic'
import React from 'react'

// This is a workaround for Next.js to work with BokehJS
export const BokehPlot = dynamic(() => import('./bokeh-plot'), {
ssr: false,
})
export const BokehPlot = React.lazy(() => import('./bokeh-plot'))
2 changes: 1 addition & 1 deletion src/context/experiment/experiment-context.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const ExperimentWrapper: FC<{ children: React.ReactNode }> = ({ children }) => (

describe('useExperiment', () => {
it('fails if called outside provider', async () => {
console.error = jest.fn()
console.error = vi.fn()
expect(() => renderHook(() => useExperiment())).toThrow(
'useExperiment must be used within an ExperimentProvider'
)
Expand Down
Loading

0 comments on commit 4944d27

Please sign in to comment.