xref: /third_party/node/test/parallel/test-module-stat.js (revision 1cb0ef41)
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/parallel/
11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_cirequire('../common');
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ci// This tests Module._stat.
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst Module = require('module');
71cb0ef41Sopenharmony_ciconst fs = require('fs');
81cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir');
91cb0ef41Sopenharmony_ciconst { ok, strictEqual } = require('assert');
101cb0ef41Sopenharmony_ciconst { join } = require('path');
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ciconst directory = join(tmpdir.path, 'directory');
131cb0ef41Sopenharmony_ciconst doesNotExist = join(tmpdir.path, 'does-not-exist');
141cb0ef41Sopenharmony_ciconst file = join(tmpdir.path, 'file.js');
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_citmpdir.refresh();
171cb0ef41Sopenharmony_cifs.writeFileSync(file, "module.exports = { a: 'b' }");
181cb0ef41Sopenharmony_cifs.mkdirSync(directory);
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_cistrictEqual(Module._stat(directory), 1); // Returns 1 for directories.
211cb0ef41Sopenharmony_cistrictEqual(Module._stat(file), 0); // Returns 0 for files.
221cb0ef41Sopenharmony_ciok(Module._stat(doesNotExist) < 0); // Returns a negative integer for any other kind of strings.
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci// TODO(RaisinTen): Add tests that make sure that Module._stat() does not crash when called
251cb0ef41Sopenharmony_ci// with a non-string data type. It crashes currently.
26

Indexes created Thu Nov 07 10:32:03 CST 2024