Skip to content

Commit

Permalink
Clean up deps, fix jest and linting (#149)
Browse files Browse the repository at this point in the history
* Clean up deps, fix jest and linting
* Remove ./prebuild.sh since we no longer work with .md files directly
* Remove gatsby links
* Fix null vs undefined
  • Loading branch information
vnugent authored Jan 3, 2022
1 parent 41382bd commit ab5c4f5
Show file tree
Hide file tree
Showing 35 changed files with 520 additions and 819 deletions.
1 change: 1 addition & 0 deletions .env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#API_SERVER=https://api.openbeta.io
4 changes: 2 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ jobs:
- name: Lint code
run: yarn lint

- name: Copy a subset of content files
run: ./prebuild.sh
- name: Run unit tests
run: yarn test

- name: Test build
run: yarn build
3 changes: 3 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ variables:

gatsby-build:
stage: build
only: # Only run for these branches
- develop
- main

tags:
- docker
Expand Down
5 changes: 2 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
# @gibboj -- turn back when switch to next js is closer
# yarn lint
# yarn test
yarn lint
yarn test
5 changes: 0 additions & 5 deletions jest-preprocess.js

This file was deleted.

20 changes: 20 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const nextJest = require('next/jest')

const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: './'
})

// Add any custom config to be passed to Jest
const customJestConfig = {
// setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
// if using TypeScript with a baseUrl set to the root directory then you need the below for alias' to work
// moduleDirectories: ['node_modules', '<rootDir>/'],
testEnvironment: 'jest-environment-jsdom',
transform: {
"^.+\\.tsx?$": "ts-jest"
},
}

// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig)
3 changes: 0 additions & 3 deletions loadershim.js

This file was deleted.

25 changes: 5 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"axios": "^0.24.0",
"btoa": "^1.2.1",
"buffer": "^6.0.3",
"cross-env": "^7.0.3",
"dayjs": "^1.10.6",
"formik": "^2.2.9",
"front-matter": "^4.0.2",
Expand Down Expand Up @@ -79,19 +78,16 @@
"prepare": "husky install"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.16.1",
"@testing-library/react": "^12.1.2",
"@types/react": "^17.0.38",
"autoprefixer": "^10.4.1",
"babel-jest": "^27.0.2",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.6",
"eslint-plugin-jest": "^25.3.2",
"eslint-plugin-jest": "^25.3.4",
"husky": "^7.0.4",
"identity-obj-proxy": "^3.0.0",
"jest": "^27.0.4",
"jest": "^27.4.5",
"postcss": "^8.4.5",
"prettier": "^2.3.1",
"react-test-renderer": "^17.0.2",
"tailwindcss": "^3.0.8",
"ts-jest": "^27.1.2",
"ts-standard": "^11.0.0",
"typescript": "^4.5.4"
},
Expand All @@ -102,14 +98,6 @@
"bugs": {
"url": "https://github.com/OpenBeta/open-tacos/issues"
},
"jest": {
"setupFilesAfterEnv": [
"./setupTests.js"
],
"transformIgnorePatterns": [
"[/\\\\]node_modules[/\\\\](?!unified).+\\.(js|jsx)$"
]
},
"browserslist": {
"production": [
">0.2%",
Expand All @@ -132,9 +120,6 @@
"plugins": [
"jest"
],
"globals": [
"jest"
],
"envs": {
"browser": true,
"es2021": true,
Expand Down
33 changes: 0 additions & 33 deletions prebuild.sh

This file was deleted.

5 changes: 0 additions & 5 deletions setupTests.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import React from 'react'
import { Link } from 'gatsby'
import Card from './ui/card'
import Link from 'next/link'
import Card from './ui/Card'
import RouteTypeChips from './ui/RouteTypeChips'
import RouteGradeChip from './ui/RouteGradeChip'
import { sanitizeName } from '../js/utils'

function RandomRouteCard ({ climb }) {
if (!climb) return null
function RandomRouteCard ({ climb }): JSX.Element {
if (climb === null) return null
const { slug, pathTokens } = climb
const { type, route_name: routeName, safety, yds } = climb.frontmatter

return (
<Link to={slug}>
<Link href={slug}>
<Card>
<div className='text-left'>
<h2 className='font-medium font-semigole font-sans text-base truncate'>
Expand Down
16 changes: 5 additions & 11 deletions src/components/SearchBar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useEffect } from 'react'
// import { navigate } from 'gatsby'
import { useRouter } from 'next/router'

import ClimbSearch from './ClimbSearch'
import { IconButton } from './ui/Button'
Expand Down Expand Up @@ -30,11 +30,14 @@ export default function SearchBar ({ className }) {
false
)
}

const router = useRouter()

return (
<div className={className}>
{activated
? (
<ClimbSearch onClimbNameChange={navigateTo} />
<ClimbSearch onClimbNameChange={({ meta_mp_route_id: metaMpRouteId }) => router.push(`/climbs/${metaMpRouteId}`)} />
)
: (
<div
Expand All @@ -50,12 +53,3 @@ export default function SearchBar ({ className }) {
</div>
)
}

const navigateTo = (data) => {
const { meta_mp_route_id: metaMpRouteId } = data
navigate(buildUrl(metaMpRouteId))
}

const buildUrl = (metaMpRouteId) => {
return `/climbs/${metaMpRouteId}`
}
17 changes: 3 additions & 14 deletions src/components/SeoTags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,11 @@ function SeoTags ({ description = '', keywords = [], title, image = '' }: SEOPro
content_edit_branch: 'edit-test'
}
}
// const { site } = useStaticQuery(graphql`
// query DefaultSEOQuery {
// site {
// siteMetadata {
// title
// description
// author
// }
// }
// }
// `)

const metaDescription = description || site.siteMetadata.description
const metaTitle = title || site.siteMetadata.title
const metaDescription = description ?? site.siteMetadata.description
const metaTitle = title ?? site.siteMetadata.title
const metaImage =
image ||
image ??
'https://res.cloudinary.com/openbeta-prod/image/upload/v1639562113/open-tacos/nc9dsf6aoitrnehe1cwo.jpg'

return (
Expand Down
31 changes: 0 additions & 31 deletions src/components/__tests__/RandomRouteCard.js

This file was deleted.

27 changes: 27 additions & 0 deletions src/components/__tests__/RandomRouteCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react'
import '@testing-library/jest-dom/extend-expect'
import { render, screen } from '@testing-library/react'
import RandomRouteCard from '../RandomRouteCard'

test('RandomRouteCard has route_name', () => {
const mocked = {
frontmatter: {
type: { sport: 1 },
route_name: 'Sample Test',
yds: '5.10a'
},
pathTokens: [
'USA',
'Oregon',
'Central Oregon',
'Smith Rock',
'Shipwreck Wall - East Face',
'marooned'
],
slug: '/climbs/1234'
}

render(<RandomRouteCard climb={mocked} />)

expect(screen.getByRole('heading', { hidden: true })).toHaveTextContent(mocked.frontmatter.route_name)
})
6 changes: 4 additions & 2 deletions src/components/editor/Editor.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useState, useEffect } from 'react'
import { useRouter } from 'next/router'
import ReactPlaceholder from 'react-placeholder'
import { usePlateValue } from '@udecode/plate-core'
import { useAuth0 } from '@auth0/auth0-react'
import { navigate } from 'gatsby'

import PlateEditor from './PlateEditor'
import FronmatterForm from './ClimbProfile'
Expand Down Expand Up @@ -53,6 +53,8 @@ export const ERROR = Object.freeze({
})

export const Editor = () => {
const router = useRouter()

const { getAccessTokenSilently, user } = useAuth0()
// to get access to commit message
const commitMsgRef = React.useRef(null)
Expand Down Expand Up @@ -111,7 +113,7 @@ export const Editor = () => {
commitMsgRef.current.values.message,
authToken
)
navigate('/dashboard')
router.push('/dashboard')
} catch (e) {
switch (e.httpStatus) {
case 409:
Expand Down
6 changes: 4 additions & 2 deletions src/components/editor/ErrorMessage.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React from 'react'
import { navigate } from 'gatsby'
import { useRouter } from 'next/router'

import Modal from '../ui/Modal'
import RainIcon from '../../assets/icons/rain.svg'
import { ERROR } from './Editor'

export default function ErrorMessage ({ code, msg, setError }) {
const router = useRouter()
const actionOk = {
text: 'OK',
action: function () {
Expand All @@ -14,7 +16,7 @@ export default function ErrorMessage ({ code, msg, setError }) {
const actionDashboard = {
text: 'Go to Dashboard',
action: function () {
navigate('/dashboard') // direct user to dashboard because there's nothing user can do
router.push('/dashboard') // direct user to dashboard because there's nothing user can do
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/components/editor/PageHeader.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react'
import { navigate } from 'gatsby'
import { useRouter } from 'next/router'

const PageHeader = ({ onSubmit, editType, submitting, children }) => {
const router = useRouter()
return (
<div className='flex justify-between mb-8'>
<div className=''>
Expand All @@ -15,7 +16,7 @@ const PageHeader = ({ onSubmit, editType, submitting, children }) => {
<div>
<button
className='btn btn-text mr-4'
onClick={() => navigate(-1)}
onClick={() => router.back()}
>
Cancel
</button>
Expand Down
6 changes: 2 additions & 4 deletions src/components/ui/AreaCard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import Card from './card'
import Card from './Card'
import BarPercent from './BarPercent'

/**
Expand All @@ -15,14 +15,12 @@ interface AreaStatistics {

interface AreaCardProps {
areaName: string
onPress?: () => {}
stats?: AreaStatistics
}

function AreaCard ({ areaName, onPress, stats }: AreaCardProps): JSX.Element {
function AreaCard ({ areaName, stats }: AreaCardProps): JSX.Element {
return (
<Card
onPress={onPress}
footer={
(stats != null) &&
<BarPercent styles='-mt-2' percents={stats.percents} colors={stats.colors} />
Expand Down
Loading

0 comments on commit ab5c4f5

Please sign in to comment.