-
-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathtasks.clj
More file actions
158 lines (144 loc) · 6.36 KB
/
tasks.clj
File metadata and controls
158 lines (144 loc) · 6.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
(ns tasks
(:require
[babashka.fs :as fs]
[babashka.process :as p :refer [shell]]
[cheshire.core :as json]
[node-repl-tests]
[clojure.string :as str]))
(def test-config
'{:compiler-options {:load-tests true}
:modules {:squint_tests {:init-fn squint.compiler-test/init
:depends-on #{:compiler :cljs.pprint :node}}}})
(defn shadow-extra-test-config []
(merge-with
merge
test-config))
(defn bump-core-vars []
(let [core-vars (:out (shell {:out :string}
"node --input-type=module -e 'import * as squint from \"squint-cljs/core.js\";console.log(JSON.stringify(Object.keys(squint)))'"))
;; Drop names starting with "__" — convention for
;; exported-but-private helpers (e.g. __toFn) that other runtime
;; modules import but user CLJS shouldn't resolve as a core var.
parsed (into (sorted-set)
(comp (remove #(str/starts-with? % "__"))
(map symbol))
(json/parse-string core-vars))]
(spit "resources/squint/core.edn" (with-out-str
((requiring-resolve 'clojure.pprint/pprint)
parsed)))))
(defn compile-test-runtime
"Pre-compile the cljs.test runtime from its .cljs source so it ships in
the npm package and is available to local tests."
[]
(shell "node" "node_cli.js" "compile" "--extension" "js" "src/squint/test.cljs"))
(defn build-squint-npm-package []
(fs/create-dirs ".work")
(fs/delete-tree "lib")
(fs/delete-tree ".shadow-cljs")
(bump-core-vars)
(spit ".work/config-merge.edn" "{}")
(shell "npx shadow-cljs --config-merge .work/config-merge.edn release squint")
(compile-test-runtime))
(defn publish []
(build-squint-npm-package)
(run! fs/delete (fs/glob "lib" "*.map"))
(shell "npx esbuild src/squint/core.js --minify --format=iife --global-name=squint.core --outfile=lib/squint.core.umd.js")
(shell "npm publish"))
(defn watch-squint []
(fs/create-dirs ".work")
(fs/delete-tree ".shadow-cljs/builds/squint/dev/ana/squint")
(spit ".work/config-merge.edn" (shadow-extra-test-config))
(bump-core-vars)
(shell "npx shadow-cljs --aliases :dev --config-merge .work/config-merge.edn watch squint"))
(defn test-project [_]
(let [dir "test-project"]
(fs/delete-tree (fs/path dir "lib"))
;; dummy invocation
(shell {:dir dir} (fs/which "npx") "squint" "compile")
(let [output (:out (shell {:dir dir :out :string} "node lib/main.mjs"))]
(println output)
(assert (str/includes? output "macros2/debug 10"))
(assert (str/includes? output "macros2/debug 6"))
(assert (str/includes? output "macros/debug 10"))
(assert (str/includes? output "macros/debug 6"))
(assert (str/includes? output "also 10"))
(assert (str/includes? output "my-other-src 1 2"))
(assert (str/includes? output "json!"))
(assert (str/includes? output "{ a: 1 }"))
(assert (str/includes? output "\"emit!\""))
(assert (str/includes? output "qualified test: 142"))
(assert (str/includes? output "refer-only qualified: 242"))
(assert (str/includes? output "real-debug: 42"))
(assert (str/includes? output "transitive-rt: debug: 42")))
(assert (fs/exists? "test-project/lib/foo.json"))
(assert (fs/exists? "test-project/lib/baz.css"))
(assert (not (fs/exists? "test-project/lib/bar.json")))))
(defn test-run [_]
(let [dir "test-project"
out (:out (shell {:dir dir :out :string} (fs/which "npx") "squint" "run" "script.cljs"))]
(assert (str/includes? out "dude"))))
(defn test-cljs-test [_]
(let [src "test-resources/cljs_test_smoke.cljs"
out-file "test-resources/cljs_test_smoke.mjs"]
(shell "node" "node_cli.js" "compile" src)
(let [out (:out (shell {:out :string} "node" out-file))]
(fs/delete out-file)
(assert (str/includes? out "Ran 11 tests containing 21 assertions") out)
(assert (str/includes? out "1 failures, 0 errors") out)
;; :begin-test-ns must fire for each ns visited by run-tests
(assert (str/includes? out "Testing ns.a") out)
(assert (str/includes? out "Testing ns.b") out)
;; (run-tests 'synthetic.ns) macro must compile to a string lookup
(assert (str/includes? out "Testing synthetic.ns") out))))
(defn test-squint []
(fs/create-dirs ".work")
(spit ".work/config-merge.edn" (shadow-extra-test-config))
(bump-core-vars)
(shell "npx shadow-cljs --config-merge .work/config-merge.edn compile squint")
(compile-test-runtime)
(shell "node lib/squint_tests.js")
(node-repl-tests/run-tests {})
(test-project {})
(test-run {})
(test-cljs-test {}))
(defn clojure-mode-test []
(let [dir "libtests"]
(fs/delete-tree dir)
(fs/create-dir dir)
(shell {:dir dir} "git clone https://github.com/nextjournal/clojure-mode")
(let [dir (fs/path dir "clojure-mode")
shell (partial p/shell {:dir dir})
squint-local (fs/path dir "node_modules/squint-cljs")]
(fs/create-dirs dir)
(shell "yarn install")
(fs/delete-tree squint-local)
(fs/create-dirs squint-local)
(run! #(fs/copy % squint-local) (fs/glob "." "*.{js,json}"))
(prn :lib (fs/absolutize "lib") :squint-local (fs/absolutize (fs/path squint-local "lib")))
(fs/copy-tree "lib" (fs/path squint-local "lib"))
(fs/copy-tree "src" (fs/path squint-local "src"))
(shell "node_modules/squint-cljs/node_cli.js" "compile")
(shell "node dist/nextjournal/clojure_mode_tests.mjs")
(println "clojure-mode tests successful!"))))
(defn eucalypt-test []
(let [dir "libtests"]
(fs/delete-tree dir)
(fs/create-dir dir)
(shell {:dir dir} "git clone https://github.com/chr15m/eucalypt")
(let [dir (fs/path dir "eucalypt")
shell (partial p/shell {:dir dir})
squint-local (fs/path dir "node_modules/squint-cljs")]
(fs/create-dirs dir)
(shell "npm install")
(fs/delete-tree squint-local)
(fs/create-dirs squint-local)
(run! #(fs/copy % squint-local) (fs/glob "." "*.{js,json}"))
(fs/copy-tree "lib" (fs/path squint-local "lib"))
(fs/copy-tree "src" (fs/path squint-local "src"))
(shell "npm run test")
(println "eucalypt tests successful!"))))
(defn libtests []
#_(build-squint-npm-package)
;; temporarily disabled because of not= bug
#_(eucalypt-test)
(clojure-mode-test))