Skip to content

Instantly share code, notes, and snippets.

@balupton
Last active September 27, 2015 01:38
Show Gist options
  • Save balupton/1191942 to your computer and use it in GitHub Desktop.
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.

JQTest

Server-Side jQuery testing with Node.js, Expresso and CoffeeScript. Test faster, test funner.

# 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
}
@balupton
Copy link
Author

balupton commented Sep 3, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment