Fix #340 - Set provider type for unit tests in the browser
This commit is contained in:
parent
78f9ce824d
commit
e9c4cb6d7a
|
@ -1,9 +1,8 @@
|
||||||
(function(global) {
|
|
||||||
|
|
||||||
var Filer = require('../..');
|
var Filer = require('../..');
|
||||||
var IndexedDBTestProvider = require('./indexeddb.js');
|
var IndexedDBTestProvider = require('./indexeddb.js');
|
||||||
var WebSQLTestProvider = require('./websql.js');
|
var WebSQLTestProvider = require('./websql.js');
|
||||||
var MemoryTestProvider = require('./memory.js');
|
var MemoryTestProvider = require('./memory.js');
|
||||||
|
var Url = require('url');
|
||||||
|
|
||||||
var _provider;
|
var _provider;
|
||||||
var _fs;
|
var _fs;
|
||||||
|
@ -26,13 +25,35 @@
|
||||||
return MemoryTestProvider;
|
return MemoryTestProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getUrlParams() {
|
||||||
|
// Check if we are running in node
|
||||||
|
if(!global.location) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var url = Url.parse(global.location.href, true);
|
||||||
|
|
||||||
|
return url.query;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getProviderType() {
|
||||||
|
var defaultProvider = 'Memory';
|
||||||
|
var queryString = getUrlParams();
|
||||||
|
|
||||||
|
// If the environment is node or the query string is empty,
|
||||||
|
// the memory provider will be used.
|
||||||
|
if(!queryString) {
|
||||||
|
return defaultProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
return queryString['filer-provider'] || defaultProvider;
|
||||||
|
}
|
||||||
|
|
||||||
function setup(callback) {
|
function setup(callback) {
|
||||||
// In browser 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.
|
||||||
// for definition of window.filerArgs.
|
var providerType = getProviderType();
|
||||||
var providerType = global.filerArgs && global.filerArgs.provider ?
|
|
||||||
global.filerArgs.provider : 'Memory';
|
|
||||||
|
|
||||||
var name = uniqueName();
|
var name = uniqueName();
|
||||||
|
|
||||||
|
@ -131,5 +152,3 @@
|
||||||
cleanup: cleanup,
|
cleanup: cleanup,
|
||||||
typedArrayEqual: typedArrayEqual
|
typedArrayEqual: typedArrayEqual
|
||||||
};
|
};
|
||||||
|
|
||||||
}(this));
|
|
||||||
|
|
Loading…
Reference in New Issue