-
Notifications
You must be signed in to change notification settings - Fork 30.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! test: add a more isolated Module._stat test
Signed-off-by: Darshan Sen <raisinten@gmail.com>
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
require('../common'); | ||
|
||
// This tests Module._stat. | ||
|
||
const Module = require('module'); | ||
const fs = require('fs'); | ||
const tmpdir = require('../common/tmpdir'); | ||
const { ok, strictEqual } = require('assert'); | ||
const { join } = require('path'); | ||
|
||
const directory = join(tmpdir.path, 'directory'); | ||
const doesNotExist = join(tmpdir.path, 'does-not-exist'); | ||
const file = join(tmpdir.path, 'file.js'); | ||
|
||
tmpdir.refresh(); | ||
fs.writeFileSync(file, "module.exports = { a: 'b' }"); | ||
fs.mkdirSync(directory); | ||
|
||
strictEqual(Module._stat(directory), 1); // Returns 1 for directories. | ||
strictEqual(Module._stat(file), 0); // Returns 0 for files. | ||
ok(Module._stat(doesNotExist) < 0); // Returns a negative integer for any other kind of strings. | ||
|
||
// TODO(RaisinTen): Add tests that make sure that Module._stat() does not crash when called | ||
// with a non-string data type. It crashes currently. |