Skip to content

Commit

Permalink
Merge pull request #94 from YurandCL/master
Browse files Browse the repository at this point in the history
Update prepare script to compile only the necessary files
  • Loading branch information
midudev authored Aug 7, 2023
2 parents 51368bd + c97ad6d commit 15fe1c0
Show file tree
Hide file tree
Showing 14 changed files with 19 additions and 29 deletions.
2 changes: 1 addition & 1 deletion projects/07-midu-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"scripts": {
"dev": "vite",
"build": "vite build",
"prepare": "npm run test && swc ./src/*.jsx -d lib && rm lib/App.js lib/main.js lib/Router.test.js && cp src/*.js lib",
"prepare": "npm run test && swc src/components src/utils src/index.jsx -d lib",
"preview": "vite preview",
"test": "echo",
"test:watch": "vitest",
Expand Down
5 changes: 2 additions & 3 deletions projects/07-midu-router/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { lazy, Suspense } from 'react'

import './App.css'
import Page404 from './pages/404.jsx'
import SearchPage from './pages/Search.jsx'

import { Router } from './Router.jsx'
import { Route } from './Route.jsx'
import { Router } from './components/Router.jsx'
import { Route } from './components/Route.jsx'

const LazyHomePage = lazy(() => import('./pages/Home.jsx'))
const LazyAboutPage = lazy(() => import('./pages/About.jsx'))
Expand Down
14 changes: 7 additions & 7 deletions projects/07-midu-router/src/Router.test.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { describe, it, expect, beforeEach, vi } from 'vitest'
import { render, screen, cleanup, fireEvent } from '@testing-library/react'
import { Router } from './Router.jsx'
import { Route } from './Route.jsx'
import { Link } from './Link.jsx'
import { getCurrentPath } from './utils.js'
import { Router } from './components/Router.jsx'
import { Route } from './components/Route.jsx'
import { Link } from './components/Link.jsx'
import { getCurrentPath } from './utils/getCurrentPath.js'

vi.mock('./utils.js', () => ({
vi.mock('./utils/getCurrentPath.js', () => ({
getCurrentPath: vi.fn()
}))

Expand Down Expand Up @@ -63,8 +63,8 @@ describe('Router', () => {
)

// Click on the link
const button = screen.getByText(/Go to About/)
fireEvent.click(button)
const anchor = screen.getByText(/Go to About/)
fireEvent.click(anchor)

const aboutTitle = await screen.findByText('About')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BUTTONS, EVENTS } from './consts.js'
import { BUTTONS, EVENTS } from '../utils/consts.js'

export function navigate (href) {
window.history.pushState({}, '', href)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EVENTS } from './consts.js'
import { EVENTS } from '../utils/consts.js'
import { useState, useEffect, Children } from 'react'
import { match } from 'path-to-regexp'
import { getCurrentPath } from './utils.js'
import { getCurrentPath } from '../utils/getCurrentPath.js'

export function Router ({ children, routes = [], defaultComponent: DefaultComponent = () => <h1>404</h1> }) {
const [currentPath, setCurrentPath] = useState(getCurrentPath())
Expand Down
8 changes: 0 additions & 8 deletions projects/07-midu-router/src/consts.js

This file was deleted.

6 changes: 3 additions & 3 deletions projects/07-midu-router/src/index.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { Router } from './Router'
export { Link } from './Link'
export { Route } from './Route'
export { Router } from './components/Router'
export { Link } from './components/Link'
export { Route } from './components/Route'
2 changes: 1 addition & 1 deletion projects/07-midu-router/src/pages/404.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Link } from '../Link.jsx'
import { Link } from '../components/Link'

export default function Page404 () {
return (
Expand Down
2 changes: 1 addition & 1 deletion projects/07-midu-router/src/pages/About.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Link } from '../Link.jsx'
import { Link } from '../components/Link'

const i18n = {
es: {
Expand Down
2 changes: 1 addition & 1 deletion projects/07-midu-router/src/pages/Home.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Link } from '../Link.jsx'
import { Link } from '../components/Link'

export default function HomePage () {
return (
Expand Down
1 change: 0 additions & 1 deletion projects/07-midu-router/src/utils.js

This file was deleted.

File renamed without changes.
File renamed without changes.

0 comments on commit 15fe1c0

Please sign in to comment.