Skip to content

Instantly share code, notes, and snippets.

@pcj
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcj/d80f516d301aab53ac75 to your computer and use it in GitHub Desktop.
Save pcj/d80f516d301aab53ac75 to your computer and use it in GitHub Desktop.
Testing CometD in mocha/node.js environment
{
additionalDeps:[
'src/main/js/lib/moment/moment.js',
'src/main/js/lib/cometd/cometd-3.0.3.js',
'src/main/js/lib/cometd/jquery.cometd-3.0.3.js',
'src/main/js/src/socket.js',
'src/main/js/src/api.js',
],
additionalCompileOptions: [
'--debug=true',
'--process_closure_primitives=true',
'--warning_level=VERBOSE',
'--jscomp_warning=accessControls',
'--jscomp_warning=checkRegExp',
'--jscomp_warning=checkTypes',
'--jscomp_warning=checkVars',
'--jscomp_warning=deprecated',
'--jscomp_warning=fileoverviewTags',
'--jscomp_warning=invalidCasts',
'--jscomp_warning=missingProperties',
'--jscomp_warning=nonStandardJsDocs',
'--jscomp_warning=strictModuleDepCheck',
'--jscomp_warning=undefinedVars',
'--jscomp_warning=unknownDefines',
'--summary_detail_level=3'
],
additionalJSDocToolkitOptions: [
'-a',// '-v', '-p',
'-E=\.min\.js',
'-E=deps\.js',
'-E=/docs',
'-E=/tests',
'-E=/third_party',
'-r=10',
'-D="noGlobal:true"'
],
jsdocToolkitTemplate: 'codeview',
additionalLinterOptions: [
'--strict',
'-e', '/node/'
]
}
npm_install:
npm install -g node-gyp
# jsdom must be installed at 3.x; the 4.x versions only run in io.js now.
npm install jsdom@3.1.2
npm install ws jquery-deferred nclosure
mocha_test:
mocha --harmony --recursive --timeout 20000 --reporter spec src/main/js/spec
//
// Setup global state to mimic browser environment.
//
var assert = require('assert');
var jsdom = require('jsdom').jsdom;
var ws = require('ws');
var jQuery = require('jquery-deferred');
// Browserlike globals
var document = jsdom('<html></html>');
var window = document.parentWindow;
var location = window.location;
// Provide websocket
window.WebSocket = ws;
// Export these on global
global.document = document;
global.window = window;
global.location = location;
global.jQuery = jQuery;
global.$ = jQuery;
// I am using nclosure for closure library access. This will look for a file
// 'closure.json' that includes additional dependencies including the cometd.js and
// jquery.cometd.js files. These files could also be integrated with
// require('./cometd.js'); statements also.
require('nclosure');
// describe() and it() are mocha-specific and can be removed
//
describe('global environment', function () {
it('browserlike environment should exist', function() {
assert.ok(document);
assert.ok(window);
assert.ok(window.WebSocket);
assert.ok($);
assert.ok($.Deferred);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment