Server-Side jQuery testing with Node.js, Expresso and CoffeeScript. Test faster, test funner.
Last active
September 27, 2015 01:38
-
-
Save balupton/1191942 to your computer and use it in GitHub Desktop.
JQTest: Server-Side jQuery testing with Node.js, Expresso and CoffeeScript. Test faster, test funner.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Server-Side jQuery testing with Node.js | |
# Copyright 2011 Benjamin Lupton | |
# MIT Licensed | |
# https://gist.github.com/1191942 | |
# ------------------------------------- | |
# Requires | |
fs = require('fs') | |
assert = require('assert') | |
jquery = require('jquery') | |
cwd = process.cwd(); | |
# ------------------------------------- | |
# Helpers | |
appendScript = (scriptPath) -> | |
scriptPath = "#{cwd}/#{scriptPath}"; | |
scriptContents = fs.readFileSync(scriptPath).toString() | |
return this.append "<script>#{scriptContents}</script>" | |
createjQuery = -> | |
$ = jquery.create(); | |
$.fn.appendScript = appendScript | |
return $ | |
createjQueryWith = (scripts,html) -> | |
$ = createjQuery(); | |
$body = $('body') | |
scripts = [scripts] unless scripts instanceof Array | |
$body.appendScript script for script in scripts | |
$body.append html if html | |
return $ | |
# ------------------------------------- | |
# Export | |
module.exports = { | |
fs,assert,jquery | |
appendScript | |
createjQuery | |
createjQueryWith | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Implementations: