1'use strict'; 2require('../common'); 3 4// This tests Module._stat. 5 6const Module = require('module'); 7const fs = require('fs'); 8const tmpdir = require('../common/tmpdir'); 9const { ok, strictEqual } = require('assert'); 10const { join } = require('path'); 11 12const directory = join(tmpdir.path, 'directory'); 13const doesNotExist = join(tmpdir.path, 'does-not-exist'); 14const file = join(tmpdir.path, 'file.js'); 15 16tmpdir.refresh(); 17fs.writeFileSync(file, "module.exports = { a: 'b' }"); 18fs.mkdirSync(directory); 19 20strictEqual(Module._stat(directory), 1); // Returns 1 for directories. 21strictEqual(Module._stat(file), 0); // Returns 0 for files. 22ok(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. 26