Finish test suite changes for node.js

This commit is contained in:
David Humphrey 2014-05-17 15:17:09 -04:00
parent 3aa670dd90
commit 24e0b155be
4 changed files with 30 additions and 21 deletions

View File

@ -1,14 +1,18 @@
define(["Filer"], function(Filer) { define(["Filer"], function(Filer) {
var indexedDB = window.indexedDB || var indexedDB = (function(window) {
window.mozIndexedDB || return window.indexedDB ||
window.webkitIndexedDB || window.mozIndexedDB ||
window.msIndexedDB; window.webkitIndexedDB ||
window.msIndexedDB;
}(this));
var needsCleanup = []; var needsCleanup = [];
window.addEventListener('beforeunload', function() { if(typeof window !== 'undefined') {
needsCleanup.forEach(function(f) { f(); }); window.addEventListener('beforeunload', function() {
}); needsCleanup.forEach(function(f) { f(); });
});
}
function IndexedDBTestProvider(name) { function IndexedDBTestProvider(name) {
var _done = false; var _done = false;

View File

@ -38,7 +38,8 @@ function(Filer, IndexedDBTestProvider, WebSQLTestProvider, MemoryTestProvider) {
// (e.g., ?filer-provider=IndexedDB). If not specified, we use // (e.g., ?filer-provider=IndexedDB). If not specified, we use
// the Memory provider by default. See test/require-config.js // the Memory provider by default. See test/require-config.js
// for definition of window.filerArgs. // for definition of window.filerArgs.
var providerType = window.filerArgs && window.filerArgs.provider ? var providerType = (typeof window !== 'undefined' &&
window.filerArgs && window.filerArgs.provider) ?
window.filerArgs.provider : 'Memory'; window.filerArgs.provider : 'Memory';
var name = uniqueName(); var name = uniqueName();
@ -59,7 +60,8 @@ function(Filer, IndexedDBTestProvider, WebSQLTestProvider, MemoryTestProvider) {
} }
// Allow passing FS flags on query string // Allow passing FS flags on query string
var flags = window.filerArgs && window.filerArgs.flags ? var flags = (typeof window !== 'undefined' &&
window && window.filerArgs && window.filerArgs.flags) ?
window.filerArgs.flags : 'FORMAT'; window.filerArgs.flags : 'FORMAT';
// Create a file system and wait for it to get setup // Create a file system and wait for it to get setup

View File

@ -1,9 +1,11 @@
define(["Filer"], function(Filer) { define(["Filer"], function(Filer) {
var needsCleanup = []; var needsCleanup = [];
window.addEventListener('beforeunload', function() { if(typeof window !== 'undefined') {
needsCleanup.forEach(function(f) { f(); }); window.addEventListener('beforeunload', function() {
}); needsCleanup.forEach(function(f) { f(); });
});
}
function WebSQLTestProvider(name) { function WebSQLTestProvider(name) {
var _done = false; var _done = false;

View File

@ -1,5 +1,12 @@
var requirejs = require('requirejs'); // If there's something broken in filer or a test,
// requirejs can blow up, and mocha sees it as tests
// not getting added (i.e., it just exists with only
// 1 test run). Display an error so it's clear what happened.
process.on('uncaughtException', function(err) {
console.error('Error in require.js trying to build test suite, filer:\n', err.stack);
});
var requirejs = require('requirejs');
requirejs.config({ requirejs.config({
paths: { paths: {
"tests": "../tests", "tests": "../tests",
@ -22,16 +29,10 @@ requirejs.config({
nodeRequire: require nodeRequire: require
}); });
GLOBAL.document = {}; // We use Chai's expect assertions in all the tests via a global
GLOBAL.navigator = { userAgent: ""};
GLOBAL.window = {
addEventListener: function(){},
navigator: navigator,
document: document,
setTimeout: setTimeout
};
GLOBAL.expect = require('chai').expect; GLOBAL.expect = require('chai').expect;
// Workaround for Mocha bug, see https://github.com/visionmedia/mocha/issues/362
describe("Mocha needs one test in order to wait on requirejs tests", function() { describe("Mocha needs one test in order to wait on requirejs tests", function() {
it('should wait for other tests', function(){ it('should wait for other tests', function(){
require('assert').ok(true); require('assert').ok(true);