-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
49 lines (41 loc) · 1.6 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env node
var should = require('should');
var fakeMainModule = require("../index.js");
var mainModuleBackup = require.main;
describe('fake require.main', function(){
it('should expect require as 1. parameter', function(){
(function testFirstParm() {
fakeMainModule.fake("asdfasdfasd");
}).should.throw(new Error("need current require as first parameter!"));
});
it('should expect a valid module filename as 2. parameter', function(){
(function testFirstParm() {
fakeMainModule.fake(require, "asdfasdfasd");
}).should.throw("module not found.");
});
it('should not assigned to this module __filename', function(){
require.main.should.not.deepEqual(module);
});
it('should not be assigned to this module for electron env', function(){
fakeMainModule.fakeFor(require, __filename, "electron");
require.main.should.not.deepEqual(module);
});
it('should not assigned to this module __filename', function(){
require.main = mainModuleBackup;
require.main.should.not.deepEqual(module);
});
it('should be assigned to this module', function(){
fakeMainModule.fake(require, __filename);
require.main.should.deepEqual(module);
process.mainModule.should.deepEqual(module);
});
it('should not assigned to this module __filename', function(){
require.main = mainModuleBackup;
require.main.should.not.deepEqual(module);
});
it('should be assigned to this module for node env', function(){
fakeMainModule.fakeFor(require, __filename, "node");
require.main.should.deepEqual(module);
process.mainModule.should.deepEqual(module);
});
});