|
| 1 | +/* globals describe, it, beforeEach */ |
| 2 | +"use strict"; |
| 3 | +require("should"); |
| 4 | +const MemoryFs = require("memory-fs"); |
| 5 | +const ContextModuleFactory = require("../lib/ContextModuleFactory"); |
| 6 | + |
| 7 | +describe("ContextModuleFactory", function() { |
| 8 | + describe("resolveDependencies", function() { |
| 9 | + let factory, memfs; |
| 10 | + beforeEach(function() { |
| 11 | + factory = new ContextModuleFactory([]); |
| 12 | + memfs = new MemoryFs(); |
| 13 | + }); |
| 14 | + it("should not report an error when ENOENT errors happen", function(done) { |
| 15 | + memfs.readdir = (dir, callback) => { |
| 16 | + setTimeout(() => callback(null, ["/file"])); |
| 17 | + }; |
| 18 | + memfs.stat = (file, callback) => { |
| 19 | + let err = new Error("fake ENOENT error"); |
| 20 | + err.code = "ENOENT"; |
| 21 | + setTimeout(() => callback(err, null)); |
| 22 | + }; |
| 23 | + factory.resolveDependencies(memfs, "/", true, /.*/, (err, res) => { |
| 24 | + (!!err).should.be.false(); |
| 25 | + res.should.be.an.Array(); |
| 26 | + res.length.should.be.exactly(0); |
| 27 | + done(); |
| 28 | + }); |
| 29 | + }); |
| 30 | + it("should report an error when non-ENOENT errors happen", function(done) { |
| 31 | + memfs.readdir = (dir, callback) => { |
| 32 | + setTimeout(() => callback(null, ["/file"])); |
| 33 | + }; |
| 34 | + memfs.stat = (file, callback) => { |
| 35 | + let err = new Error("fake EACCES error"); |
| 36 | + err.code = "EACCES"; |
| 37 | + setTimeout(() => callback(err, null)); |
| 38 | + }; |
| 39 | + factory.resolveDependencies(memfs, "/", true, /.*/, (err, res) => { |
| 40 | + err.should.be.an.Error(); |
| 41 | + (!!res).should.be.false(); |
| 42 | + done(); |
| 43 | + }); |
| 44 | + }); |
| 45 | + }); |
| 46 | +}); |
0 commit comments