Browse Source

Fix tests by turning them to ClojureScript

* They're now run with Karma
* The React library is now downloaded and used locally
* The module ttfe.core now has an "init" function that must be
  called from index.html, to avoid that the tests choke when they
  can't "paint" the page
master
parent
commit
ea30b4ea40
8 changed files with 16771 additions and 38 deletions
  1. +2
    -0
      .gitignore
  2. +14
    -0
      buster.js
  3. +1
    -0
      index.html
  4. +63
    -0
      karma.conf.js
  5. +9
    -2
      project.clj
  6. +16644
    -0
      react-0.9.0.js
  7. +4
    -3
      src/ttfe/core.cljs
  8. +34
    -33
      test/ttfe/core_test.cljs

+ 2
- 0
.gitignore View File

@@ -3,3 +3,5 @@
target/
out/
ttfe.js
node_modules/
karma-test.js

+ 14
- 0
buster.js View File

@@ -0,0 +1,14 @@
var config = exports;

config["Browser Tests"] = {
environment: "browser",
sources: [],
tests: ["resources/js/my_cljs_project_browser_test.js",
"resources/js/my_cljs_project_browser_optimized_test.js"]
};

config["Node Tests"] = {
environment: "node",
sources: [],
tests: ["resources/js/my_cljs_project_node_test.js"]
};

+ 1
- 0
index.html View File

@@ -76,5 +76,6 @@
<script src="out/goog/base.js" type="text/javascript"></script>
<script src="ttfe.js" type="text/javascript"></script>
<script type="text/javascript">goog.require("ttfe.core");</script>
<script type="text/javascript">ttfe.core.init();</script>
</body>
</html>

+ 63
- 0
karma.conf.js View File

@@ -0,0 +1,63 @@
// Karma configuration
// Generated on Thu Apr 03 2014 01:40:36 GMT+0200 (CEST)

module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',


// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],


// list of files / patterns to load in the browser
files: [
'react-0.9.0.js',
'karma-test.js'
],


// list of files to exclude
exclude: [],


// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {},


// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],


// web server port
port: 9876,


// enable / disable colors in the output (reporters and logs)
colors: true,


// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,


// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,


// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],


// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true
});
};

+ 9
- 2
project.clj View File

@@ -4,7 +4,8 @@
:dependencies [[org.clojure/clojure "1.5.1"]
[org.clojure/clojurescript "0.0-2156"]
[org.clojure/core.async "0.1.267.0-0d7780-alpha"]
[om "0.5.0"]]
[om "0.5.0"]
[im.chit/purnam "0.4.3"]]

:plugins [[lein-cljsbuild "1.0.2"]]

@@ -17,4 +18,10 @@
:output-to "ttfe.js"
:output-dir "out"
:optimizations :none
:source-map true}}]})
:source-map true}}
{:id "karma-test"
:source-paths ["src" "test"]
:compiler {:pretty-print true
:externs ["lib/react-0.9.0.min.js"]
:output-to "karma-test.js"
:optimizations :whitespace}}]})

+ 16644
- 0
react-0.9.0.js
File diff suppressed because it is too large
View File


+ 4
- 3
src/ttfe/core.cljs View File

@@ -36,6 +36,7 @@
#js {:id "tiles" :className "tile-container"}
cell-divs)))))

(om/root tiles-view
app-state
{:target (. js/document (getElementById "tiles"))})
(defn init []
(om/root tiles-view
app-state
{:target (. js/document (getElementById "tiles"))}))

test/ttfe/core_test.clj → test/ttfe/core_test.cljs View File

@@ -1,100 +1,101 @@
(ns ttfe.core-test
(:require [ttfe.core :refer :all]
[clojure.test :refer :all]))
(:require [ttfe.board :refer [move-right move-left move-up move-down]]
[purnam.test :refer [toSatisfy]])
(:use-macros [purnam.test :only [describe it is is-not]]))

(deftest test-move-right
(testing "Can move a single number"
(is (= (move-right [[nil nil 4 nil]
(describe test-move-right
(it "Can move a single number"
(is (move-right [[nil nil 4 nil]
[nil nil nil nil]
[nil nil nil nil]
[nil nil nil nil]])
[[nil nil nil 4 ]
[nil nil nil nil]
[nil nil nil nil]
[nil nil nil nil]])))
[nil nil nil nil]]))

(testing "Can move two numbers in different rows"
(is (= (move-right [[nil nil 4 nil]
(it "Can move two numbers in different rows"
(is (move-right [[nil nil 4 nil]
[nil nil nil nil]
[nil 2 nil nil]
[nil nil nil nil]])
[[nil nil nil 4 ]
[nil nil nil nil]
[nil nil nil 2 ]
[nil nil nil nil]])))
[nil nil nil nil]]))

(testing "Can combine simple numbers"
(is (= (move-right [[nil nil 2 2 ]
(it "Can combine simple numbers"
(is (move-right [[nil nil 2 2 ]
[nil nil nil nil]
[nil nil nil nil]
[nil nil nil nil]])
[[nil nil nil 4 ]
[nil nil nil nil]
[nil nil nil nil]
[nil nil nil nil]])))
[nil nil nil nil]]))

(testing "Can combine chains of numbers"
(is (= (move-right [[ 4 4 2 2 ]
(it "Can combine chains of numbers"
(is (move-right [[ 4 4 2 2 ]
[nil nil nil nil]
[nil nil nil nil]
[nil nil nil nil]])
[[nil nil 8 4 ]
[nil nil nil nil]
[nil nil nil nil]
[nil nil nil nil]])))
[nil nil nil nil]]))

(testing "Can combine numbers that aren't adjacent"
(is (= (move-right [[nil 2 nil 2 ]
(it "Can combine numbers that aren't adjacent"
(is (move-right [[nil 2 nil 2 ]
[nil nil nil nil]
[nil nil nil nil]
[nil nil nil nil]])
[[nil nil nil 4 ]
[nil nil nil nil]
[nil nil nil nil]
[nil nil nil nil]])))
[nil nil nil nil]]))

(testing "Number combination starts the right way"
(is (= (move-right [[ 2 2 nil 2 ]
(it "Number combination starts the right way"
(is (move-right [[ 2 2 nil 2 ]
[nil nil nil nil]
[nil nil nil nil]
[nil nil nil nil]])
[[nil nil 2 4 ]
[nil nil nil nil]
[nil nil nil nil]
[nil nil nil nil]]))))
[nil nil nil nil]])))


(deftest test-move-left
(testing "Can move two numbers in different rows"
(is (= (move-left [[nil nil 4 nil]
(describe test-move-left
(it "Can move two numbers in different rows"
(is (move-left [[nil nil 4 nil]
[nil nil nil nil]
[nil 2 nil nil]
[nil nil nil nil]])
[[ 4 nil nil nil]
[nil nil nil nil]
[ 2 nil nil nil]
[nil nil nil nil]]))))
[nil nil nil nil]])))


(deftest test-move-up
(testing "Can move two numbers in different rows"
(is (= (move-up [[nil nil nil nil]
(describe test-move-up
(it "Can move two numbers in different rows"
(is (move-up [[nil nil nil nil]
[nil nil 4 nil]
[nil 2 nil nil]
[nil nil nil nil]])
[[nil 2 4 nil]
[nil nil nil nil]
[nil nil nil nil]
[nil nil nil nil]]))))
[nil nil nil nil]])))


(deftest test-move-down
(testing "Can move two numbers in different rows"
(is (= (move-down [[nil nil nil nil]
(describe test-move-down
(it "Can move two numbers in different rows"
(is (move-down [[nil nil nil nil]
[nil nil 4 nil]
[nil 2 nil nil]
[nil nil nil nil]])
[[nil nil nil nil]
[nil nil nil nil]
[nil nil nil nil]
[nil 2 4 nil]]))))
[nil 2 4 nil]])))

Loading…
Cancel
Save