Skip to content

Commit 002c88c

Browse files
committed
Add tests and extract cache reload to separate example
1 parent 50eccb8 commit 002c88c

File tree

9 files changed

+2569
-150
lines changed

9 files changed

+2569
-150
lines changed

cache.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
const lib1 = require('./main.js');
4+
const libPath = require.resolve('./main.js');
5+
delete require.cache[libPath];
6+
const lib2 = require('./main.js');
7+
8+
if (lib1 === lib2) {
9+
console.log('Cache not reloaded');
10+
} else {
11+
console.log('Cache reloaded');
12+
}

lib/submodule1.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const method11 = () => {};
4-
const method12 = () => {};
3+
const method11 = () => 11;
4+
const method12 = () => 12;
55

66
module.exports = { method11, method12 };

lib/submodule2.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

3-
const method21 = () => {};
4-
const method22 = () => {};
5-
const method23 = () => {};
3+
const method21 = () => 21;
4+
const method22 = () => 22;
5+
const method23 = () => 23;
66

77
module.exports = { method21, method22, method23 };

lib/submodule3.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const method31 = () => {};
4-
const method32 = () => {};
3+
const method31 = () => 31;
4+
const method32 = () => 32;
55

66
module.exports = { method31, method32 };

main.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,3 @@ const lib = {};
88

99
console.log('We combined submodules:');
1010
console.log(Object.keys(lib).join(', '));
11-
12-
const metasync1 = require('metasync');
13-
const metasyncPath = require.resolve('metasync');
14-
delete require.cache[metasyncPath];
15-
const metasync2 = require('metasync');
16-
if (metasync1 === metasync2) {
17-
console.log('Cache not reloaded');
18-
} else {
19-
console.log('Cache reloaded');
20-
}
21-
22-
console.log('We use metasync:');
23-
console.log(Object.keys(metasync1).join(', '));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy