mithril-vndb/Gruntfile.js
impinball 12b8f044f1 Convert tests to Mocha/Chai/Sinon and lint them.
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...
2015-10-31 11:07:22 -04:00

386 lines
8 KiB
JavaScript
Executable file

/* eslint-env node */
module.exports = function (grunt) { // eslint-disable-line
var version = "0.2.1"
var inputFolder = "./docs"
var tempFolder = "./temp"
var archiveFolder = "./archive"
var outputFolder = "../mithril"
var guide = [
"auto-redrawing",
"benchmarks",
"community",
"optimizing-performance",
"comparison",
"components",
"getting-started",
"installation",
"integration",
"practices",
"refactoring",
"routing",
"tools",
"web-services"
]
var api = [
"change-log",
"roadmap",
"how-to-read-signatures",
"mithril",
"mithril.computation",
"mithril.deferred",
"mithril.mount",
"mithril.component",
"mithril.prop",
"mithril.redraw",
"mithril.render",
"mithril.deps",
"mithril.request",
"mithril.route",
"mithril.sync",
"mithril.trust",
"mithril.withAttr",
"mithril.xhr"
]
var md2htmlTasks = {}
function makeTasks(layout, pages) {
pages.forEach(function (name) {
var src = inputFolder + "/" + name + ".md"
var title = ""
if (grunt.file.exists(src)) {
title = grunt.file.read(src).split(/\n/)[0].substring(3) +
" - "
}
md2htmlTasks[name] = {
options: {
layout: inputFolder + "/layout/" + layout + ".html",
templateData: {topic: title}
},
files: [{
src: [src],
dest: tempFolder + "/" + name + ".html"
}]
}
})
}
makeTasks("guide", guide)
makeTasks("api", api)
var currentVersionArchiveFolder = archiveFolder + "/v" + version
grunt.initConfig({
// Keep this in sync with the .eslintignore
eslint: {
options: {
extensions: [".js"],
fix: true
},
all: [
"**/*.js",
"!node_modules/**",
"!**/*.min.js",
"!archive/**",
"!deploy/**",
"!mithril.closure-compiler-externs.js",
"!docs/layout/lib/**",
// TODO(impinball): Finish this.
"!mithril.js"
]
},
mocha_phantomjs: { // eslint-disable-line camelcase
test: {
src: ["test/index.html"],
options: {
reporter: "dot"
}
}
},
md2html: md2htmlTasks,
uglify: {
options: {
banner: [
"/*",
"Mithril v" + version,
"http://github.com/lhorie/mithril.js",
"(c) Leo Horie",
"License: MIT",
"*/"
].join("\n"),
sourceMap: true
},
mithril: {src: "mithril.js", dest: "mithril.min.js"}
},
zip: {
distribution: {
cwd: currentVersionArchiveFolder + "/",
src: [
currentVersionArchiveFolder + "/mithril.min.js",
currentVersionArchiveFolder + "/mithril.min.js.map",
currentVersionArchiveFolder + "/mithril.js"
],
dest: currentVersionArchiveFolder + "/mithril.min.zip"
}
},
replace: {
options: {
force: true,
patterns: [
{match: /\.md/g, replacement: ".html"},
{match: /\$version/g, replacement: version}
]
},
links: {
expand: true,
flatten: true,
src: [tempFolder + "/**/*.html"],
dest: currentVersionArchiveFolder + "/"
},
index: {
src: inputFolder + "/layout/index.html",
dest: currentVersionArchiveFolder + "/index.html"
},
commonjs: {
expand: true,
flatten: true,
src: [inputFolder + "/layout/*.json"],
dest: currentVersionArchiveFolder
},
cdnjs: {
src: "deploy/cdnjs-package.json",
dest: "../cdnjs/ajax/libs/mithril/package.json"
}
},
copy: {
style: {
src: inputFolder + "/layout/style.css",
dest: currentVersionArchiveFolder + "/style.css"
},
pages: {
src: inputFolder + "/layout/pages.json",
dest: currentVersionArchiveFolder + "/pages.json"
},
lib: {
expand: true,
cwd: inputFolder + "/layout/lib/",
src: "./**",
dest: currentVersionArchiveFolder + "/lib/"
},
tools: {
expand: true,
cwd: inputFolder + "/layout/tools/",
src: "./**",
dest: currentVersionArchiveFolder + "/tools/"
},
comparisons: {
expand: true,
cwd: inputFolder + "/layout/comparisons/",
src: "./**",
dest: currentVersionArchiveFolder + "/comparisons/"
},
unminified: {
src: "mithril.js",
dest: currentVersionArchiveFolder + "/mithril.js"
},
minified: {
src: "mithril.min.js",
dest: currentVersionArchiveFolder + "/mithril.min.js"
},
readme: {
src: "README.md",
dest: currentVersionArchiveFolder + "/README.md"
},
map: {
src: "mithril.min.js.map",
dest: currentVersionArchiveFolder + "/mithril.min.js.map"
},
typescript: {
src: "mithril.d.ts",
dest: currentVersionArchiveFolder + "/mithril.d.ts"
},
publish: {
expand: true,
cwd: currentVersionArchiveFolder,
src: "./**",
dest: outputFolder
},
archive: {
expand: true,
cwd: currentVersionArchiveFolder,
src: "./**",
dest: outputFolder + "/archive/v" + version
}
},
"saucelabs-browsers": {
firefox: {
filter: function (browsers) {
return browsers.filter(function (browser) {
if (browser.browserName !== "firefox") return false
var version = browser.version
return version === "dev" || version === "beta" ||
+version >= 38 // The latest ESR version
})
}
},
chrome: {
filter: function (browsers) {
return browsers.filter(function (browser) {
if (browser.browserName !== "chrome") return false
var version = browser.version
return version === "dev" || version === "beta" ||
+version >= 41
})
}
},
ie: {
filter: function (browsers) {
return browsers.filter(function (browser) {
return browser.browserName === "internet explorer" &&
!/2003/.test(browser.platform)
})
}
},
edge: {
filter: function (browsers) {
return browsers.filter(function (browser) {
return browser.browserName === "microsoftedge"
})
}
},
safari: {
filter: function (browsers) {
return browsers.filter(function (browser) {
return browser.browserName === "safari"
})
}
},
opera: {
filter: function (browsers) {
return browsers.filter(function (browser) {
return browser.browserName === "opera"
})
}
}
},
saucelabs: {
all: {
options: {
username: process.env.SAUCE_USERNAME,
key: process.env.SAUCE_ACCESS_KEY,
testname: "Mithril Tests " + new Date().toJSON(),
browsers: "<%= saucelabs.browsers %>",
urls: ["http://localhost:8000/test/index.html"],
sauceConfig: {
"record-video": false,
"record-screenshots": false
},
build: process.env.TRAVIS_JOB_ID,
onTestComplete: function (result, callback) {
var user = process.env.SAUCE_USERNAME
var pass = process.env.SAUCE_ACCESS_KEY
var url = [
"https://saucelabs.com/rest/v1", user, "jobs",
result.job_id
].join("/")
require("request").put({
url: url,
auth: {user: user, pass: pass},
json: {passed: result.passed}
}, function (error, response) {
if (error) {
return callback(error)
} else if (response.statusCode !== 200) {
return callback(new Error(
"Unexpected response status: " +
response.statusCode + "\n "))
} else {
return callback(null, result.passed)
}
})
},
tunnelTimeout: 5
}
}
},
connect: {
server: {
options: {
port: 8888,
base: "."
}
}
},
clean: {
options: {force: true},
generated: [tempFolder]
}
})
grunt.loadNpmTasks("grunt-saucelabs-browsers")
grunt.loadNpmTasks("grunt-contrib-clean")
grunt.loadNpmTasks("grunt-contrib-copy")
grunt.loadNpmTasks("grunt-contrib-uglify")
grunt.loadNpmTasks("grunt-md2html")
grunt.loadNpmTasks("grunt-replace")
grunt.loadNpmTasks("grunt-zip")
grunt.loadNpmTasks("grunt-contrib-connect")
grunt.loadNpmTasks("grunt-saucelabs")
grunt.loadNpmTasks("grunt-eslint")
grunt.loadNpmTasks("grunt-mocha-phantomjs")
grunt.registerTask("build", [
"test",
"uglify",
"zip",
"md2html",
"replace",
"copy",
"clean"
])
grunt.registerTask("test", ["eslint:all", "mocha_phantomjs"])
grunt.registerTask("default", ["build"])
grunt.registerTask("sauce", [
"saucelabs-browsers:all",
"connect",
"saucelabs"
])
}