File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // We've experienced a regression where the module loader stats a bunch of
2+ // directories on require() even if it's been called before. The require()
3+ // should caching the request.
4+ var common = require ( '../common' ) ;
5+ var fs = require ( 'fs' ) ;
6+ var assert = require ( 'assert' ) ;
7+
8+ var counter = 0 ;
9+
10+ // Switch out the two stat implementations so that they increase a counter
11+ // each time they are called.
12+
13+ var _statSync = fs . statSync ;
14+ var _stat = fs . stat ;
15+
16+ fs . statSync = function ( ) {
17+ counter ++ ;
18+ return _statSync . apply ( this , arguments ) ;
19+ } ;
20+
21+ fs . stat = function ( ) {
22+ counter ++ ;
23+ return _stat . apply ( this , arguments ) ;
24+ } ;
25+
26+ // Load the module a.js once. It should become cached.
27+
28+ var m = common . fixturesDir + '/a.js' ;
29+ require ( m ) ;
30+
31+ console . log ( "counterBefore = %d" , counter ) ;
32+ var counterBefore = counter ;
33+
34+ // Now load the module a bunch of times.
35+ // stat should not be called.
36+ for ( var i = 0 ; i < 100 ; i ++ ) {
37+ require ( m ) ;
38+ }
39+
40+ console . log ( "counterAfter = %d" , counter ) ;
41+ var counterAfter = counter ;
42+
43+ assert . equal ( counterBefore , counterAfter ) ;
44+
You can’t perform that action at this time.
0 commit comments