-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor vite-react sample project to add test suite (#569)
* refact(vite-react): adds tests and more bb tasks * fix(vite-react): trim package.json * docs(vite-react): fix example name in readme
- Loading branch information
1 parent
4ce1ec8
commit b4fdb1a
Showing
10 changed files
with
99 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.lsp/.cache | ||
.clj-kondo/.cache | ||
.nrepl-port | ||
node_modules | ||
bundle-visualization.html | ||
public/js | ||
public/test | ||
public/dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
{:tasks | ||
{dev:squint (shell "npx squint watch") | ||
dev:vite (shell "npx vite --config=viteconfig.js public") | ||
-dev {:depends [dev:vite dev:squint]} | ||
dev (run '-dev {:parallel true})}} | ||
-dev {:depends [dev:squint dev:vite]} | ||
dev (run '-dev {:parallel true}) | ||
|
||
test:watch:squint (shell "npx squint watch --paths src test --output-dir public/test") | ||
test:watch:vite (shell "npx vitest --config=viteconfig.js") | ||
-test:watch {:depends [test:watch:squint test:watch:vite]} | ||
test:watch (run '-test:watch {:parallel true}) | ||
|
||
build:squint (shell "npx squint compile") | ||
build:vite (shell "npx vite --config viteconfig.js build public") | ||
-build {:depends [build:squint build:vite]} | ||
build (run '-build {:parallel false})}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
{ | ||
"devDependencies": { | ||
"@vitejs/plugin-react": "^4.1.0", | ||
"chokidar": "^4.0.1", | ||
"vite": "^4.4.11" | ||
"@vitejs/plugin-react": "^4.3.2", | ||
"rollup-plugin-visualizer": "^5.12.0", | ||
"vite": "^5.4.9", | ||
"vitest": "^2.1.3" | ||
}, | ||
"dependencies": { | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"react": "^18.3.1", | ||
"react-dom": "^18.3.1", | ||
"squint-cljs": "latest" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
(ns index | ||
(:require | ||
[MyComponent :as MyComponent] | ||
["react-dom/client" :as rdom])) | ||
(:require [my-component :as MyComponent] | ||
["react-dom/client" :refer [createRoot]])) | ||
|
||
(def root (rdom/createRoot (js/document.getElementById "app"))) | ||
(def root (createRoot (js/document.getElementById "app"))) | ||
(.render root #jsx [MyComponent/MyComponent]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
(ns my-component | ||
(:require ["react" :refer [useState]])) | ||
|
||
(defn adder [& n] | ||
(apply + n)) | ||
|
||
(defn MyComponent [] | ||
(let [[state setState] (useState 0)] | ||
#jsx [:div "You clicked " state " times" | ||
[:button {:onClick #(setState (inc state))} | ||
"Click me"]])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(ns dummy-test | ||
(:require ["vitest" :refer [expect test]])) | ||
|
||
(test "dummy expect works" | ||
(fn [] | ||
(-> (expect 1) | ||
(.toBe 1)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
(ns my-component-test | ||
(:require ["vitest" :refer [expect test]] | ||
[my-component :refer [adder]])) | ||
|
||
(test "my-component adder works" | ||
(fn [] | ||
(-> (expect (adder 1 2 3)) | ||
(.toBe 6)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
// vite.config.js | ||
/// <reference types="vitest" /> | ||
import { defineConfig } from 'vite'; | ||
import react from '@vitejs/plugin-react'; | ||
import { visualizer } from 'rollup-plugin-visualizer'; | ||
|
||
export default defineConfig({ | ||
plugins: [react()] | ||
test: { | ||
include: ["public/**/**test.mjs", "public/**/**test.jsx"], | ||
}, | ||
plugins: [ | ||
react(), | ||
visualizer({ open: false, filename: 'bundle-visualization.html' }) | ||
] | ||
}); |