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

View File

@ -1,24 +1,22 @@
define(["Filer"], function(Filer) {
var Filer = require('../..');
function MemoryTestProvider(name) {
var that = this;
function MemoryTestProvider(name) {
var that = this;
function cleanup(callback) {
that.provider = null;
callback();
}
function init() {
if(that.provider) {
return;
}
that.provider = new Filer.FileSystem.providers.Memory(name);
}
this.init = init;
this.cleanup = cleanup;
function cleanup(callback) {
that.provider = null;
callback();
}
return MemoryTestProvider;
function init() {
if(that.provider) {
return;
}
that.provider = new Filer.FileSystem.providers.Memory(name);
}
});
this.init = init;
this.cleanup = cleanup;
}
module.exports = MemoryTestProvider;

View File

@ -1,5 +1,9 @@
define(["Filer", "tests/lib/indexeddb", "tests/lib/websql", "tests/lib/memory"],
function(Filer, IndexedDBTestProvider, WebSQLTestProvider, MemoryTestProvider) {
(function(global) {
var Filer = require('../..');
var IndexedDBTestProvider = require('./indexeddb.js');
var WebSQLTestProvider = require('./websql.js');
var MemoryTestProvider = require('./memory.js');
var _provider;
var _fs;
@ -12,17 +16,6 @@ function(Filer, IndexedDBTestProvider, WebSQLTestProvider, MemoryTestProvider) {
}
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;
if(providers.IndexedDB.isSupported()) {
return IndexedDBTestProvider;
@ -34,13 +27,12 @@ function(Filer, IndexedDBTestProvider, WebSQLTestProvider, MemoryTestProvider) {
}
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
// the Memory provider by default. See test/require-config.js
// for definition of window.filerArgs.
var providerType = (typeof window !== 'undefined' &&
window.filerArgs && window.filerArgs.provider) ?
window.filerArgs.provider : 'Memory';
var providerType = global.filerArgs && global.filerArgs.provider ?
global.filerArgs.provider : 'Memory';
var name = uniqueName();
@ -60,9 +52,8 @@ function(Filer, IndexedDBTestProvider, WebSQLTestProvider, MemoryTestProvider) {
}
// Allow passing FS flags on query string
var flags = (typeof window !== 'undefined' &&
window && window.filerArgs && window.filerArgs.flags) ?
window.filerArgs.flags : 'FORMAT';
var flags = global.filerArgs && global.filerArgs.flags) ?
global.filerArgs.flags : 'FORMAT';
// Create a file system and wait for it to get setup
_provider.init();
@ -125,7 +116,7 @@ function(Filer, IndexedDBTestProvider, WebSQLTestProvider, MemoryTestProvider) {
return true;
}
return {
module.exports = {
uniqueName: uniqueName,
setup: setup,
fs: fs,
@ -140,4 +131,4 @@ function(Filer, IndexedDBTestProvider, WebSQLTestProvider, MemoryTestProvider) {
typedArrayEqual: typedArrayEqual
};
});
}(this));

View File

@ -1,7 +1,9 @@
define(["Filer"], function(Filer) {
(function(global) {
var Filer = require('../..');
var needsCleanup = [];
if(typeof window !== 'undefined') {
if(global.addEventListener) {
window.addEventListener('beforeunload', function() {
needsCleanup.forEach(function(f) { f(); });
});
@ -40,6 +42,6 @@ define(["Filer"], function(Filer) {
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
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() {
it('should wait for other tests', function(){
require('assert').ok(true);
});
});
requirejs(["tests/test-manifest"]);
// Tests to be run are defined in test-manifest.js
require('./test-manifest.js');

View File

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