Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a test case for ContextModuleFactory.resolveDependencies
- Loading branch information
1 parent
5e3039d
commit d98eea7
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); | ||
}); | ||
}); | ||
}); |