1 |
|
2 | var test = require('tape');
|
3 | var setup = require('../setup');
|
4 | var decache = require('../decache.js');
|
5 | var mymodule = require('../lib/mymodule');
|
6 |
|
7 | console.log(mymodule.count);
|
8 |
|
9 | test('Expect decache to do nothing if the module name does not exist', function(t) {
|
10 |
|
11 | try {
|
12 | decache('./non-existing-module');
|
13 | t.pass('No error thrown');
|
14 | t.end();
|
15 | } catch (e) {
|
16 | t.fail('This should have not throw an error');
|
17 | t.end();
|
18 | }
|
19 | });
|
20 |
|
21 | test('Expect mymodule.count initial state to be false', function(t) {
|
22 | t.equal(mymodule.get(), false, 'count is false! (we have not run this)');
|
23 | t.end();
|
24 | });
|
25 |
|
26 | test('Increment the value of the count so its 1 (one)', function(t) {
|
27 | var runcount = mymodule.set();
|
28 | t.equal(runcount, 1, 'runcount is one! (as expected)');
|
29 | t.end();
|
30 | });
|
31 |
|
32 | test('Increment the value of the count so its 2 (one)', function(t) {
|
33 | mymodule.set();
|
34 | var runcount = mymodule.get();
|
35 | t.equal(runcount, 2, 'runcount is 2!');
|
36 | t.end();
|
37 | });
|
38 |
|
39 | test('There\'s no going back to initial (runcount) state!', function(t) {
|
40 | var runcount = mymodule.get();
|
41 | t.equal(runcount, 2, 'runcount cannot be decremented!!');
|
42 | t.end();
|
43 | });
|
44 |
|
45 | test('Delete Require Cache for mymodule to re-set the runcount!', function(t) {
|
46 | decache('../lib/mymodule');
|
47 | var other = require('../lib/othermodule.js');
|
48 | decache('../lib/othermodule.js');
|
49 | mymodule = require('../lib/mymodule');
|
50 | var runcount = mymodule.get();
|
51 | t.equal(runcount, false, 'runcount is false! (as epxected)');
|
52 | t.end();
|
53 | });
|
54 |
|
55 | test('Require an npm (non local) module', function(t) {
|
56 | var ts = require('tap-spec');
|
57 | decache('tap-spec');
|
58 | var keys = Object.keys(require.cache);
|
59 | t.equal(keys.indexOf('tap-spec'), -1, 'tap-spec no longer in require-cache');
|
60 | t.end();
|
61 | });
|
62 |
|
63 | test('Fake relative parent module', function(t) {
|
64 | var keys = Object.keys(require.cache);
|
65 | var p = keys[0];
|
66 | var obj = require.cache[p];
|
67 | console.log(" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
|
68 | require.cache = {};
|
69 | require.cache[__filename] = obj;
|
70 | console.log(require.cache);
|
71 | var other = require('../lib/othermodule.js');
|
72 | decache('../lib/othermodule.js');
|
73 | keys = Object.keys(require.cache);
|
74 | t.equal(keys.indexOf('othermodule.js'), -1, 'fake parent not in require.cache');
|
75 | t.end();
|
76 | });
|