Details: 1. All tests now live in `test`. All test dependencies that aren't from npm live in `test-deps`. 2. The QUnit tests are gone, as well as their dependencies. Half of them duplicated existing tests, and some of them depended on the real DOM to properly test. 3. All tests are now using Mocha to run the tests, Chai for assertions, and Sinon and Sinon Chai for testing some callbacks. 4. Tests are run through mocha-phantomjs. If you want to run just the tests, run `grunt mocha_phantomjs` or fire up a server in the root and open `http://localhost:<port>/test/index.html`, e.g. `python3 -m http.server`. 5. The linter I chose is ESLint. It is relatively easy to configure, but with a lot of flexibility. The rules I chose mostly were in tune to the style the project was already using. I'm not including a style guide in this commit, but one will likely come. You can check out the `.eslintrc` in the root and in `test/` for the two configs. The `.eslintignore` includes a TODO for `mithril.js` itself targeted at me, in the root. Other info: - As a drive-by fix, I fixed line endings on a few of the files. - I also took care of a few other files and linted them as I went: - `Gruntfile.js` - `test/input-cursor.html` (was in `tests/`) - `test/svg.html` (was in `tests/`) - `docs/layout/tools/template-converter.html` - `docs/layout/tools/template-converter.js` I didn't test the template converter after linting it, because it needs further scrutiny to ensure it works with the latest version of Mithril. I know the API has changed a little, which is why I want to be sure. - I simplified the `.travis.yml` file because none of the tests are run directly through Node anymore. They are always run in a browser of some kind. Hopefully, this turned out all right...
73 lines
2 KiB
HTML
73 lines
2 KiB
HTML
<!doctype html>
|
|
<meta charset="utf-8">
|
|
<title>Mithril test suite</title>
|
|
<div id="mocha"></div>
|
|
|
|
<!-- Dependencies -->
|
|
<script src="../node_modules/chai/chai.js"></script>
|
|
<script src="../node_modules/sinon/pkg/sinon.js" charset="utf-8"></script>
|
|
<script src="../node_modules/sinon-chai/lib/sinon-chai.js" charset="utf-8"></script>
|
|
<link rel="stylesheet" href="../node_modules/mocha/mocha.css">
|
|
<script src="../node_modules/mocha/mocha.js"></script>
|
|
|
|
<script src="../test-deps/dom.js"></script>
|
|
<script src="../test-deps/mock.js"></script>
|
|
<script src="../mithril.js"></script>
|
|
<script>
|
|
mocha.setup("bdd")
|
|
var expect = chai.expect
|
|
// Temporary workaround for https://github.com/mochajs/mocha/issues/1348
|
|
chai.config.truncateThreshold = 0
|
|
</script>
|
|
|
|
<!-- Tests go here -->
|
|
<script src="./mithril.js"></script>
|
|
<script src="./mithril.mount.js"></script>
|
|
<script src="./mithril.render.js"></script>
|
|
<script src="./mithril.withAttr.js"></script>
|
|
<script src="./mithril.trust.js"></script>
|
|
<script src="./mithril.redraw.js"></script>
|
|
<script src="./mithril.route.js"></script>
|
|
<script src="./mithril.route.parseQueryString.js"></script>
|
|
<script src="./mithril.route.buildQueryString.js"></script>
|
|
<script src="./mithril.prop.js"></script>
|
|
<script src="./mithril.request.js"></script>
|
|
<script src="./mithril.deferred.js"></script>
|
|
<script src="./mithril.sync.js"></script>
|
|
<script src="./mithril.startComputation.js"></script>
|
|
|
|
<!-- Set options and run this thing -->
|
|
<script>
|
|
m.deps(mock)
|
|
mocha.checkLeaks()
|
|
mocha.globals(["m", "mochaResults"])
|
|
|
|
// For Saucelabs reporting
|
|
var runner = mocha.run()
|
|
|
|
var failedTests = []
|
|
|
|
runner.on('end', function() {
|
|
window.mochaResults = runner.stats
|
|
window.mochaResults.reports = failedTests
|
|
})
|
|
|
|
runner.on('fail', function (test, err) {
|
|
function flattenTitles(test) {
|
|
var titles = []
|
|
while (test.parent.title) {
|
|
titles.push(test.parent.title)
|
|
test = test.parent
|
|
}
|
|
return titles.reverse()
|
|
}
|
|
|
|
failedTests.push({
|
|
name: test.title,
|
|
result: false,
|
|
message: err.message,
|
|
stack: err.stack,
|
|
titles: flattenTitles(test)
|
|
})
|
|
})
|
|
</script>
|