开发者

Running browser javascript unit tests in node

开发者 https://www.devze.com 2023-04-13 09:49 出处:网络
I\'ve got a project that I\'d like to move the testing from rhino to nodejs for (rhino simply takes too long to start and load in envjs). This is the current blocker before being able to move forward:

I've got a project that I'd like to move the testing from rhino to nodejs for (rhino simply takes too long to start and load in envjs). This is the current blocker before being able to move forward:

ExampleSingleton = new function () {
    var something = someFunction () {/*Does something*/}
    $(window).bind('resize', something);
}();

This complains about window not being defined - I don't know how to get the 'window' that I made in the shell (#!/usr/bin/env node) script开发者_JS百科 that I wrote (see below, and pardon the chaos, as I've gotten to that "try anything and everything" point).

var dom = require("jsdom").jsdom()
var window = global.window = dom.createWindow();
global.jQuery = require("jQuery");
global.$ = global.jQuery;
....
require("path/to/file"); //This is where it breaks, before the tests even start

I've tried reading in and eval'ing as well, but that didn't much help and of course the error was masked because it was an anonymous function.

Am I trying to do the impossible here? Or is there a very simple browser friendly thing I can do to get this working?


Have you thought about using PhantomJS instead of node?

PhantomJS is a headless WebKit with JavaScript API. It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG.

PhantomJS is an optimal solution for fast headless testing, site scraping, pages capture, SVG renderer, network monitoring and many other use cases.

Because it is a real browser, you won't need jsdom or envjs. JavaScript continuous testing with QUnit, PhantomJS and Powershell might help you get started.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号