Merge pull request #486 from reagent-project/bundle-test

Bundle test
This commit is contained in:
Juho Teperi 2020-04-16 23:23:37 +03:00 committed by GitHub
commit 28aaf6e467
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 3626 additions and 166 deletions

View File

@ -7,28 +7,67 @@ jobs:
steps:
- checkout
- restore_cache:
key: reagent-{{ checksum "project.clj" }}
keys:
- lein-v1-{{ checksum "project.clj" }}
- lein-v1
- restore_cache:
key: reagent-npm-{{ checksum "package.json" }}
keys:
- npm-v1-{{ checksum "package.json" }}
- npm-v1
- run: sudo npm install -g karma-cli
- run: npm install
- run: ./run-tests.sh
- run: ./run-tests.sh lein
- save_cache:
paths:
- ~/.m2
- ~/.lein
- ~/.cljs/.aot_cache
key: reagent-{{ checksum "project.clj" }}
key: lein-v1-{{ checksum "project.clj" }}
- save_cache:
paths:
- node_modules
key: reagent-npm-{{ checksum "package.json" }}
key: npm-v1-{{ checksum "package.json" }}
- store_artifacts:
path: coverage
- run: bash <(curl -s https://codecov.io/bash)
environment:
NPM_CONFIG_LOGLEVEL: warn
test-clj:
working_directory: ~/work
docker:
- image: circleci/clojure:tools-deps-1.9.0.397-node-browsers
steps:
- checkout
- restore_cache:
keys:
- clj-v1-{{ checksum "deps.edn" }}
- clj-v1
- restore_cache:
keys:
- npm-v1-{{ checksum "package.json" }}
- vpm-v1
- run: sudo npm install -g karma-cli
- run: npm install
- run: ./run-tests.sh clj
- save_cache:
paths:
- ~/.m2
- ~/.lein
- ~/.cljs/.aot_cache
key: clj-v1-{{ checksum "deps.edn" }}
- save_cache:
paths:
- node_modules
key: npm-v1-{{ checksum "package.json" }}
- store_artifacts:
path: coverage
- run: bash <(curl -s https://codecov.io/bash)
environment:
NPM_CONFIG_LOGLEVEL: warn
update-site:
working_directory: ~/work
docker:
@ -37,12 +76,17 @@ jobs:
- checkout
- add_ssh_keys
- restore_cache:
key: reagent-{{ checksum "project.clj" }}
keys:
- lein-v1-{{ checksum "project.clj" }}
- lein-v1
- restore_cache:
key: reagent-npm-{{ checksum "package.json" }}
keys:
- npm-v1-{{ checksum "package.json" }}
- npm-v1
- run: npm install
- deploy:
command: ./build-example-site.sh
update-tagged-docs:
working_directory: ~/work
docker:
@ -51,7 +95,9 @@ jobs:
- checkout
- add_ssh_keys
- restore_cache:
key: reagent-{{ checksum "project.clj" }}
keys:
- lein-v1-{{ checksum "project.clj" }}
- lein-v1
- deploy:
command: ./build-docs.sh
workflows:
@ -62,9 +108,14 @@ workflows:
filters:
tags:
only: /v.*/
- test-clj:
filters:
tags:
only: /v.*/
- update-site:
requires:
- test
- test-clj
filters:
branches:
only:
@ -72,6 +123,7 @@ workflows:
- update-tagged-docs:
requires:
- test
- test-clj
filters:
branches:
ignore:

View File

@ -3,6 +3,8 @@
(:require [reagentdemo.core :as core]
[reagenttest.runtests :as tests]))
(enable-console-print!)
(defn init! []
(core/init! (tests/init!)))

View File

@ -6,8 +6,6 @@
(:import goog.History
[goog.history Html5History EventType]))
(enable-console-print!)
;;; Configuration
(declare main-content)

5
deps.edn Normal file
View File

@ -0,0 +1,5 @@
{:paths ["src" "test" "examples/todomvc/src" "examples/simple/src" "examples/geometry/src" "demo"]
:deps {org.clojure/clojurescript {:git/url "https://github.com/clojure/clojurescript.git"
:sha "f95a13b3e3b193749e10e15d95ef98506ce3be29"}
; org.clojure/clojurescript {:local/root "/home/juho/Source/clojurescript"}
doo {:mvn/version "0.1.11"}}}

3558
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -17,7 +17,10 @@
"karma-coverage": "https://github.com/karma-runner/karma-coverage.git#55aeead0934a39efbd9db0b575d416ab44cd8a12",
"karma-junit-reporter": "2.0.1",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "4.0.2",
"md5-file": "4.0.0",
"shadow-cljs": "2.8.93"
"shadow-cljs": "2.8.93",
"webpack": "^4.42.1",
"webpack-cli": "^3.3.11"
}
}

View File

@ -12,8 +12,23 @@ EXIT=0
SUMMARY="$blue##\n## SUMMARY\n##$reset\n\n"
TOOL=$1
for env in test-environments/*; do
name=$(basename "$env")
if [[ -n $TOOL ]]; then
if [[ $name == bundle* ]]; then
if [[ $TOOL != 'clj' ]]; then
continue
fi
else
if [[ $TOOL != 'lein' ]]; then
continue
fi
fi
fi
echo -e "$blue##"
echo -e "## TESTING $name"
echo -e "##$reset"

View File

@ -0,0 +1,10 @@
# Advanced optimized JS bundle
- `tesh.sh`
- Creates `karma.js` bundle using `karma.edn`, including the test suite.
- Runs Karma with `karma.config.js`.
- `build.sh`
- Creates `index.js` bundle which contains the demo site, without test suite.
- Runs Webpack and copies static files to target folder.
- The bundles share the ClojureScript compiler output-dir, so need to
compile everything twice.

View File

@ -0,0 +1,8 @@
{:main reagentdemo.prod
:optimizations :advanced
:output-to "target/bundle-adv/resources/public/js/out/index.js"
:output-dir "target/bundle-adv/resources/public/js/out"
; :pseudo-names true
:elide-asserts true
:target :bundle
:closure-defines {cljs.core/*global* "window"}}

View File

@ -0,0 +1,5 @@
#!/bin/bash
set -ex
clj -m cljs.main -co test-environments/bundle-adv/build.edn -v --compile
npx webpack --config=test-environments/bundle-adv/webpack.config.js
cp -r site/public/index.html site/public/css target/bundle-adv/resources/public/

View File

@ -0,0 +1,20 @@
module.exports = function (config) {
config.set({
browsers: ['ChromeHeadless'],
basePath: '../../target/bundle-adv/resources/public/',
files: ['js/out/karma.js'],
frameworks: ['cljs-test'],
preprocessors: {
'js/out/karma.js': ['webpack', 'sourcemap']
},
colors: true,
logLevel: config.LOG_INFO,
client: {
args: ['reagenttest.runtests.karma_tests'],
},
singleRun: true,
webpack: {
mode: 'production'
}
});
};

View File

@ -0,0 +1,8 @@
{:main reagenttest.runtests
:optimizations :advanced
:output-to "target/bundle-adv/resources/public/js/out/karma.js"
:output-dir "target/bundle-adv/resources/public/js/out"
; :pseudo-names true
:elide-asserts true
:target :bundle
:closure-defines {cljs.core/*global* "window"}}

View File

@ -0,0 +1,4 @@
#!/bin/bash
set -ex
clojure -m cljs.main -co test-environments/bundle-adv/karma.edn -v --compile
npx karma start test-environments/bundle-adv/karma.conf.js

View File

@ -0,0 +1,8 @@
module.exports = {
mode: 'production',
entry: './target/bundle-adv/resources/public/js/out/index.js',
output: {
path: __dirname + "/../../target/bundle-adv/resources/public/js/",
filename: 'main.js'
}
};

View File

@ -0,0 +1,8 @@
{:main reagenttest.runtests
:output-to "target/bundle/resources/public/js/out/index.js"
:output-dir "target/bundle/resources/public/js/out"
:asset-path "js/out"
:target :bundle
; :bundle-cmd {:none ["npx" "webpack" "--mode=development"]
; :default ["npx" "webpack"]}
}

View File

@ -0,0 +1,33 @@
module.exports = function (config) {
config.set({
browsers: ['ChromeHeadless'],
basePath: '../../target/bundle/resources/public/',
files: [
// Karma will try running test adapter before all
// files loaded by Cljs are ready.
'../../../../test-environments/bundle/workaround.js',
'js/out/index.js',
{pattern: 'js/out/**/*.js', included: false},
// Source maps
{pattern: 'js/out/**/*.cljs', included: false},
{pattern: 'js/out/**/*.js.map', included: false}
],
frameworks: ['cljs-test'],
preprocessors: {
'js/out/index.js': ['webpack', 'sourcemap']
},
// Cljs asset-path
proxies: {
'/js/out/': '/base/js/out/'
},
colors: true,
logLevel: config.LOG_INFO,
client: {
args: ['reagenttest.runtests.karma_tests'],
},
singleRun: true,
webpack: {
mode: 'development'
}
});
};

View File

@ -0,0 +1,4 @@
#!/bin/bash
set -ex
clojure -m cljs.main -co test-environments/bundle/build.edn --compile
npx karma start test-environments/bundle/karma.conf.js

View File

@ -0,0 +1,8 @@
module.exports = {
mode: 'development',
entry: './target/bundle/resources/public/js/out/index.js',
output: {
path: __dirname + "/target/bundle/resources/public/js/",
filename: 'main.js'
}
};

View File

@ -0,0 +1,4 @@
window.__karma__.loaded_real = window.__karma__.loaded;
window.__karma__.loaded = function() {
};

View File

@ -10,6 +10,7 @@
[reagent.impl.util-test]
[clojure.test :as test]
[doo.runner :as doo :include-macros true]
[jx.reporter.karma :as karma]
[reagent.core :as r]))
(enable-console-print!)
@ -55,4 +56,12 @@
(run-tests)
[#'test-output-mini]))
;; Macro which sets *main-cli-fn*
(doo/doo-all-tests #"(reagenttest\.test.*|reagent\..*-test)")
(defn ^:export karma-tests [karma]
(karma/run-all-tests karma #"(reagenttest\.test.*|reagent\..*-test)"))
(when (exists? js/window)
(when-let [f (some-> js/window .-__karma__ .-loaded_real)]
(.loaded_real (.-__karma__ js/window))))

View File

@ -1086,9 +1086,9 @@
(is (re-find #"Something went wrong\." (.-innerHTML div)))
(if (dev?)
(is (re-find #"\n in reagenttest.testreagent.comp1 \(created by reagenttest.testreagent.comp2\)\n in reagenttest.testreagent.comp2 \(created by reagent[0-9]+\)\n in reagent[0-9]+ \(created by reagenttest.testreagent.error_boundary\)\n in reagenttest.testreagent.error_boundary"
(.-componentStack @info)))
(.-componentStack ^js @info)))
(is (re-find #"\n in .+\n in .+\n in reagent[0-9]+\n in .+"
(.-componentStack @info))) ))))))))
(.-componentStack ^js @info))) ))))))))
(deftest test-dom-node
(let [node (atom nil)
@ -1236,7 +1236,9 @@
(is (= "<div><div>hello</div><div>world</div><div>foo</div><div>1</div><div>2</div></div>"
(as-string [comp]))))))
(defonce my-context (react/createContext "default"))
;; In bundle version, the names aren't optimized.
;; In node module processed versions, names probably are optimized.
(defonce my-context ^js/MyContext (react/createContext "default"))
(def Provider (.-Provider my-context))
(def Consumer (.-Consumer my-context))