File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+ require ( '../common' ) ;
3+
4+ // This tests Module._stat.
5+
6+ const Module = require ( 'module' ) ;
7+ const fs = require ( 'fs' ) ;
8+ const tmpdir = require ( '../common/tmpdir' ) ;
9+ const { ok, strictEqual } = require ( 'assert' ) ;
10+ const { join } = require ( 'path' ) ;
11+
12+ const directory = join ( tmpdir . path , 'directory' ) ;
13+ const doesNotExist = join ( tmpdir . path , 'does-not-exist' ) ;
14+ const file = join ( tmpdir . path , 'file.js' ) ;
15+
16+ tmpdir . refresh ( ) ;
17+ fs . writeFileSync ( file , "module.exports = { a: 'b' }" ) ;
18+ fs . mkdirSync ( directory ) ;
19+
20+ strictEqual ( Module . _stat ( directory ) , 1 ) ; // Returns 1 for directories.
21+ strictEqual ( Module . _stat ( file ) , 0 ) ; // Returns 0 for files.
22+ ok ( Module . _stat ( doesNotExist ) < 0 ) ; // Returns a negative integer for any other kind of strings.
23+
24+ // TODO(RaisinTen): Add tests that make sure that Module._stat() does not crash when called
25+ // with a non-string data type. It crashes currently.
You can’t perform that action at this time.
0 commit comments