2019-02-05 18:46:58 +00:00
|
|
|
'use strict';
|
|
|
|
const Filer = require('../../src');
|
|
|
|
const util = require('../lib/test-utils');
|
|
|
|
const expect = require('chai').expect;
|
2014-01-14 15:56:36 +00:00
|
|
|
|
2018-07-15 17:25:35 +00:00
|
|
|
describe('Filer', function() {
|
|
|
|
it('is defined', function() {
|
2014-05-23 20:53:50 +00:00
|
|
|
expect(typeof Filer).not.to.equal(undefined);
|
2014-01-14 15:56:36 +00:00
|
|
|
});
|
|
|
|
|
2018-07-15 17:25:35 +00:00
|
|
|
it('has FileSystem constructor', function() {
|
2014-05-23 20:53:50 +00:00
|
|
|
expect(typeof Filer.FileSystem).to.equal('function');
|
|
|
|
});
|
2014-10-17 16:28:03 +00:00
|
|
|
|
2019-01-03 02:21:25 +00:00
|
|
|
it('has Buffer constructor', function() {
|
|
|
|
expect(typeof Filer.Buffer).to.equal('function');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has Path and path objects', function() {
|
|
|
|
expect(typeof Filer.Path).to.equal('object');
|
|
|
|
expect(typeof Filer.path).to.equal('object');
|
|
|
|
expect(Filer.Path).to.equal(Filer.path);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has Errors object', function() {
|
|
|
|
expect(typeof Filer.Errors).to.equal('object');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has an fs object that returns a Filer.FileSystem', function() {
|
|
|
|
// Depends on IndexedDB being available, since we can't
|
2019-01-03 04:36:20 +00:00
|
|
|
// configure our own test provider. Shim for coverage.
|
|
|
|
util.shimIndexedDB(function() {
|
|
|
|
expect(typeof Filer.fs).to.equal('object');
|
|
|
|
|
|
|
|
const fs1 = Filer.fs;
|
|
|
|
const fs2 = Filer.fs;
|
|
|
|
|
|
|
|
expect(fs1).to.be.an.instanceof(Filer.FileSystem);
|
|
|
|
expect(fs2).to.be.an.instanceof(Filer.FileSystem);
|
|
|
|
expect(fs1).to.equal(fs2);
|
|
|
|
});
|
2019-01-03 02:21:25 +00:00
|
|
|
});
|
|
|
|
|
2018-07-15 17:25:35 +00:00
|
|
|
it('has Shell constructor', function() {
|
2014-10-17 16:28:03 +00:00
|
|
|
expect(typeof Filer.Shell).to.equal('function');
|
|
|
|
});
|
2014-04-18 23:26:41 +00:00
|
|
|
|
|
|
|
it('must honor the \'FORMAT\' flag', function(done) {
|
2019-02-05 18:46:58 +00:00
|
|
|
const name = 'local-test';
|
2018-12-20 23:52:26 +00:00
|
|
|
// Because we need to use a bunch of Filer filesystems
|
|
|
|
// in this test, we can't use the usual test infrastructure
|
|
|
|
// to create/manage the fs instance. Pick the best one
|
|
|
|
// based on the testing environment (browser vs. node)
|
2019-02-05 18:46:58 +00:00
|
|
|
const providers = Filer.FileSystem.providers;
|
|
|
|
let Provider;
|
2018-12-20 23:52:26 +00:00
|
|
|
if(providers.IndexedDB.isSupported()) {
|
|
|
|
Provider = providers.IndexedDB;
|
|
|
|
} else {
|
|
|
|
Provider = providers.Memory;
|
|
|
|
}
|
|
|
|
|
2019-02-05 18:46:58 +00:00
|
|
|
let fs = new Filer.FileSystem({name, provider: new Provider(name)});
|
|
|
|
let fs2 = new Filer.FileSystem({name, provider: new Provider(name)});
|
2014-04-18 23:26:41 +00:00
|
|
|
|
|
|
|
fs.mkdir('/test', function(err){
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
fs2.readdir('/', function(err, list) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
expect(list).to.exist;
|
|
|
|
expect(list).to.have.length(1);
|
|
|
|
|
2018-12-20 23:52:26 +00:00
|
|
|
fs2 = new Filer.FileSystem({name, provider: new Provider(name), flags:['FORMAT']});
|
2014-04-18 23:26:41 +00:00
|
|
|
fs2.readdir('/', function(err, list2) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(list2).to.exist;
|
|
|
|
expect(list2).to.have.length(0);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|