From 715f56b4784599bd253743ca6fe1b5316a45142c Mon Sep 17 00:00:00 2001 From: "David Humphrey (:humph) david.humphrey@senecacollege.ca" Date: Wed, 19 Feb 2014 17:47:14 -0500 Subject: [PATCH] Default provider for tests should be indexeddb. Fixes #119 --- tests/lib/test-utils.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/lib/test-utils.js b/tests/lib/test-utils.js index 666a2f2..00efaba 100644 --- a/tests/lib/test-utils.js +++ b/tests/lib/test-utils.js @@ -11,6 +11,24 @@ function(Filer, IndexedDBTestProvider, WebSQLTestProvider, MemoryTestProvider) { return 'filer-testdb-' + uniqueName.seed++; } + function findBestProvider() { + // 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(navigator.userAgent.indexOf('PhantomJS') > -1) { + return MemoryTestProvider; + } + + var providers = Filer.FileSystem.providers; + if(providers.IndexedDB.isSupported()) { + return IndexedDBTestProvider; + } + if(providers.WebSQL.isSupported()) { + return WebSQLTestProvider; + } + return MemoryTestProvider; + } + function setup(callback) { // We support specifying the provider via the query string // (e.g., ?filer-provider=IndexedDB). If not specified, we use @@ -31,7 +49,8 @@ function(Filer, IndexedDBTestProvider, WebSQLTestProvider, MemoryTestProvider) { case 'memory': /* falls through */ default: - _provider = new MemoryTestProvider(name); + var BestProvider = findBestProvider(); + _provider = new BestProvider(name); break; }