Skip to content

Commit

Permalink
Added a test case for ContextModuleFactory.resolveDependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-paris committed Oct 12, 2017
1 parent 5e3039d commit d98eea7
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/ContextModuleFactory.test.js
@@ -0,0 +1,46 @@
/* globals describe, it, beforeEach */
"use strict";
require("should");
const MemoryFs = require("memory-fs");
const ContextModuleFactory = require("../lib/ContextModuleFactory");

describe("ContextModuleFactory", function() {
describe("resolveDependencies", function() {
let factory, memfs;
beforeEach(function() {
factory = new ContextModuleFactory([]);
memfs = new MemoryFs();
});
it("should not report an error when ENOENT errors happen", function(done) {
memfs.readdir = (dir, callback) => {
setTimeout(() => callback(null, ["/file"]));
};
memfs.stat = (file, callback) => {
let err = new Error("fake ENOENT error");
err.code = "ENOENT";
setTimeout(() => callback(err, null));
};
factory.resolveDependencies(memfs, "/", true, /.*/, (err, res) => {
(!!err).should.be.false();
res.should.be.an.Array();
res.length.should.be.exactly(0);
done();
});
});
it("should report an error when non-ENOENT errors happen", function(done) {
memfs.readdir = (dir, callback) => {
setTimeout(() => callback(null, ["/file"]));
};
memfs.stat = (file, callback) => {
let err = new Error("fake EACCES error");
err.code = "EACCES";
setTimeout(() => callback(err, null));
};
factory.resolveDependencies(memfs, "/", true, /.*/, (err, res) => {
err.should.be.an.Error();
(!!res).should.be.false();
done();
});
});
});
});

0 comments on commit d98eea7

Please sign in to comment.