Rework tests for node

This commit is contained in:
David Humphrey (:humph) david.humphrey@senecacollege.ca 2014-05-23 14:54:59 -04:00
parent d9ed65602a
commit 38627f95d6
6 changed files with 109 additions and 166 deletions

View File

@ -1,15 +1,14 @@
define(["Filer"], function(Filer) { (function(global) {
var Filer = require("../..");
var indexedDB = (function(window) { var indexedDB = global.indexedDB ||
return window.indexedDB || global.mozIndexedDB ||
window.mozIndexedDB || global.webkitIndexedDB ||
window.webkitIndexedDB || global.msIndexedDB;
window.msIndexedDB;
}(this));
var needsCleanup = []; var needsCleanup = [];
if(typeof window !== 'undefined') { if(global.addEventListener) {
window.addEventListener('beforeunload', function() { global.addEventListener('beforeunload', function() {
needsCleanup.forEach(function(f) { f(); }); needsCleanup.forEach(function(f) { f(); });
}); });
} }
@ -52,6 +51,6 @@ define(["Filer"], function(Filer) {
this.cleanup = cleanup; this.cleanup = cleanup;
} }
return IndexedDBTestProvider; module.exports = IndexedDBTestProvider;
}); }(this));

View File

@ -1,6 +1,6 @@
define(["Filer"], function(Filer) { var Filer = require('../..');
function MemoryTestProvider(name) { function MemoryTestProvider(name) {
var that = this; var that = this;
function cleanup(callback) { function cleanup(callback) {
@ -17,8 +17,6 @@ define(["Filer"], function(Filer) {
this.init = init; this.init = init;
this.cleanup = cleanup; this.cleanup = cleanup;
} }
return MemoryTestProvider; module.exports = MemoryTestProvider;
});

View File

@ -1,5 +1,9 @@
define(["Filer", "tests/lib/indexeddb", "tests/lib/websql", "tests/lib/memory"], (function(global) {
function(Filer, IndexedDBTestProvider, WebSQLTestProvider, MemoryTestProvider) {
var Filer = require('../..');
var IndexedDBTestProvider = require('./indexeddb.js');
var WebSQLTestProvider = require('./websql.js');
var MemoryTestProvider = require('./memory.js');
var _provider; var _provider;
var _fs; var _fs;
@ -12,17 +16,6 @@ function(Filer, IndexedDBTestProvider, WebSQLTestProvider, MemoryTestProvider) {
} }
function findBestProvider() { function findBestProvider() {
if(typeof module !== 'undefined' && module.exports) {
return MemoryTestProvider;
}
// When running tests, and when no explicit provider is defined,
// prefer providers in this order: IndexedDB, WebSQL, Memory.
// However, if we're running in PhantomJS, use Memory first.
if(typeof navigator !== 'undefined' && navigator.userAgent.indexOf('PhantomJS') > -1) {
return MemoryTestProvider;
}
var providers = Filer.FileSystem.providers; var providers = Filer.FileSystem.providers;
if(providers.IndexedDB.isSupported()) { if(providers.IndexedDB.isSupported()) {
return IndexedDBTestProvider; return IndexedDBTestProvider;
@ -34,13 +27,12 @@ function(Filer, IndexedDBTestProvider, WebSQLTestProvider, MemoryTestProvider) {
} }
function setup(callback) { function setup(callback) {
// We support specifying the provider via the query string // In browser we support specifying the provider via the query string
// (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 = (typeof window !== 'undefined' && var providerType = global.filerArgs && global.filerArgs.provider ?
window.filerArgs && window.filerArgs.provider) ? global.filerArgs.provider : 'Memory';
window.filerArgs.provider : 'Memory';
var name = uniqueName(); var name = uniqueName();
@ -60,9 +52,8 @@ function(Filer, IndexedDBTestProvider, WebSQLTestProvider, MemoryTestProvider) {
} }
// Allow passing FS flags on query string // Allow passing FS flags on query string
var flags = (typeof window !== 'undefined' && var flags = global.filerArgs && global.filerArgs.flags) ?
window && window.filerArgs && window.filerArgs.flags) ? global.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
_provider.init(); _provider.init();
@ -125,7 +116,7 @@ function(Filer, IndexedDBTestProvider, WebSQLTestProvider, MemoryTestProvider) {
return true; return true;
} }
return { module.exports = {
uniqueName: uniqueName, uniqueName: uniqueName,
setup: setup, setup: setup,
fs: fs, fs: fs,
@ -140,4 +131,4 @@ function(Filer, IndexedDBTestProvider, WebSQLTestProvider, MemoryTestProvider) {
typedArrayEqual: typedArrayEqual typedArrayEqual: typedArrayEqual
}; };
}); }(this));

View File

@ -1,7 +1,9 @@
define(["Filer"], function(Filer) { (function(global) {
var Filer = require('../..');
var needsCleanup = []; var needsCleanup = [];
if(typeof window !== 'undefined') { if(global.addEventListener) {
window.addEventListener('beforeunload', function() { window.addEventListener('beforeunload', function() {
needsCleanup.forEach(function(f) { f(); }); needsCleanup.forEach(function(f) { f(); });
}); });
@ -40,6 +42,6 @@ define(["Filer"], function(Filer) {
this.cleanup = cleanup; this.cleanup = cleanup;
} }
return WebSQLTestProvider; module.exports = WebSQLTestProvider;
}); }(this));

View File

@ -1,48 +1,5 @@
// 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 and crash loudly
// so it's clear what happened.
process.on('uncaughtException', function(err) {
describe('requirejs errors: ', function() {
it('requirejs has crashed building the test suite...', function(done) {
console.error(err.stack);
require('assert').ok(false);
});
});
});
var requirejs = require('requirejs');
requirejs.config({
paths: {
"tests": "../tests",
"src": "../src",
"spec": "../tests/spec",
"bugs": "../tests/bugs",
"util": "../tests/lib/test-utils",
// see gruntfile.js for how dist/filer-test.js gets built
"Filer": "../dist/filer_node-test"
},
baseUrl: "./lib",
optimize: "none",
shim: {
// TextEncoder and TextDecoder shims. encoding-indexes must get loaded first,
// and we use a fake one for reduced size, since we only care about utf8.
"encoding": {
deps: ["encoding-indexes-shim"]
}
},
nodeRequire: require
});
// We use Chai's expect assertions in all the tests via a global // We use Chai's expect assertions in all the tests via a global
GLOBAL.expect = require('chai').expect; GLOBAL.expect = require('chai').expect;
// Workaround for Mocha bug, see https://github.com/visionmedia/mocha/issues/362 // Tests to be run are defined in test-manifest.js
describe("Mocha needs one test in order to wait on requirejs tests", function() { require('./test-manifest.js');
it('should wait for other tests', function(){
require('assert').ok(true);
});
});
requirejs(["tests/test-manifest"]);

View File

@ -1,71 +1,67 @@
define([ /**
/**
* Add your test spec files to the list in order to * Add your test spec files to the list in order to
* get them running by default. * get them running by default.
*/ */
// Filer // Filer
"spec/filer.spec", require("./spec/filer.spec");
// Filer.FileSystem.* // Filer.FileSystem.*
"spec/fs.spec", require("./spec/fs.spec");
"spec/fs.stat.spec", require("./spec/fs.stat.spec");
"spec/fs.lstat.spec", require("./spec/fs.lstat.spec");
"spec/fs.exists.spec", require("./spec/fs.exists.spec");
"spec/fs.mknod.spec", require("./spec/fs.mknod.spec");
"spec/fs.mkdir.spec", require("./spec/fs.mkdir.spec");
"spec/fs.readdir.spec", require("./spec/fs.readdir.spec");
"spec/fs.rmdir.spec", require("./spec/fs.rmdir.spec");
"spec/fs.open.spec", require("./spec/fs.open.spec");
"spec/fs.write.spec", require("./spec/fs.write.spec");
"spec/fs.writeFile-readFile.spec", require("./spec/fs.writeFile-readFile.spec");
"spec/fs.appendFile.spec", require("./spec/fs.appendFile.spec");
"spec/fs.read.spec", require("./spec/fs.read.spec");
"spec/fs.close.spec", require("./spec/fs.close.spec");
"spec/fs.link.spec", require("./spec/fs.link.spec");
"spec/fs.unlink.spec", require("./spec/fs.unlink.spec");
"spec/fs.rename.spec", require("./spec/fs.rename.spec");
"spec/fs.lseek.spec", require("./spec/fs.lseek.spec");
"spec/fs.symlink.spec", require("./spec/fs.symlink.spec");
"spec/fs.readlink.spec", require("./spec/fs.readlink.spec");
"spec/fs.truncate.spec", require("./spec/fs.truncate.spec");
"spec/fs.utimes.spec", require("./spec/fs.utimes.spec");
"spec/fs.xattr.spec", require("./spec/fs.xattr.spec");
"spec/fs.stats.spec", require("./spec/fs.stats.spec");
"spec/path-resolution.spec", require("./spec/path-resolution.spec");
"spec/times.spec", require("./spec/times.spec");
"spec/time-flags.spec", require("./spec/time-flags.spec");
"spec/fs.watch.spec", require("./spec/fs.watch.spec");
"spec/errors.spec", require("./spec/errors.spec");
"spec/lib.spec", require("./spec/lib.spec");
// Filer.FileSystem.providers.* // Filer.FileSystem.providers.*
"spec/providers/providers.spec", require("./spec/providers/providers.spec");
"spec/providers/providers.indexeddb.spec", require("./spec/providers/providers.indexeddb.spec");
"spec/providers/providers.websql.spec", require("./spec/providers/providers.websql.spec");
// Filer.FileSystemShell.* // Filer.FileSystemShell.*
"spec/shell/cd.spec", require("./spec/shell/cd.spec");
"spec/shell/touch.spec", require("./spec/shell/touch.spec");
"spec/shell/exec.spec", require("./spec/shell/exec.spec");
"spec/shell/cat.spec", require("./spec/shell/cat.spec");
"spec/shell/ls.spec", require("./spec/shell/ls.spec");
"spec/shell/rm.spec", require("./spec/shell/rm.spec");
"spec/shell/env.spec", require("./spec/shell/env.spec");
"spec/shell/mkdirp.spec", require("./spec/shell/mkdirp.spec");
"spec/shell/wget.spec", require("./spec/shell/wget.spec");
"spec/shell/zip-unzip.spec", require("./spec/shell/zip-unzip.spec");
// Ported node.js tests (filenames match names in https://github.com/joyent/node/tree/master/test) // Ported node.js tests (filenames match names in https://github.com/joyent/node/tree/master/test)
"spec/node-js/simple/test-fs-mkdir", require("./spec/node-js/simple/test-fs-mkdir");
"spec/node-js/simple/test-fs-null-bytes", require("./spec/node-js/simple/test-fs-null-bytes");
"spec/node-js/simple/test-fs-watch", require("./spec/node-js/simple/test-fs-watch");
"spec/node-js/simple/test-fs-watch-recursive", require("./spec/node-js/simple/test-fs-watch-recursive");
// Regressions, Bugs // Regressions; Bugs
"bugs/issue105", require("./bugs/issue105");
"bugs/issue106" , require("./bugs/issue106");
"spec/providers/providers.memory.spec" require("./spec/providers/providers.memory.spec");
]);