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