summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGeoffrey Booth <webmaster@geoffreybooth.com>2018-10-01 22:12:47 -0700
committerRich Trott <rtrott@gmail.com>2018-11-01 19:28:15 -0700
commit22f7d0a4bdf4e33cfb85be1f341b1f8cadf1b668 (patch)
tree4cb4497fd3fdaa1f268bb6baf7bc66d4e97b3584 /test
parenta03165a5fd5ab0325eec506e346f6ec5db46780d (diff)
downloadandroid-node-v8-22f7d0a4bdf4e33cfb85be1f341b1f8cadf1b668.tar.gz
android-node-v8-22f7d0a4bdf4e33cfb85be1f341b1f8cadf1b668.tar.bz2
android-node-v8-22f7d0a4bdf4e33cfb85be1f341b1f8cadf1b668.zip
module: support multi-dot file extension
Support multi-dot file extensions like '.coffee.md' in Module.load. PR-URL: https://github.com/nodejs/node/pull/23416 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/known_issues/test-module-deleted-extensions.js18
-rw-r--r--test/parallel/test-module-multi-extensions.js94
2 files changed, 94 insertions, 18 deletions
diff --git a/test/known_issues/test-module-deleted-extensions.js b/test/known_issues/test-module-deleted-extensions.js
deleted file mode 100644
index 3a51e8725e..0000000000
--- a/test/known_issues/test-module-deleted-extensions.js
+++ /dev/null
@@ -1,18 +0,0 @@
-'use strict';
-// Refs: https://github.com/nodejs/node/issues/4778
-const common = require('../common');
-const assert = require('assert');
-const fs = require('fs');
-const path = require('path');
-const tmpdir = require('../common/tmpdir');
-const file = path.join(tmpdir.path, 'test-extensions.foo.bar');
-
-tmpdir.refresh();
-fs.writeFileSync(file, '', 'utf8');
-require.extensions['.foo.bar'] = (module, path) => {};
-delete require.extensions['.foo.bar'];
-require.extensions['.bar'] = common.mustCall((module, path) => {
- assert.strictEqual(module.id, file);
- assert.strictEqual(path, file);
-});
-require(path.join(tmpdir.path, 'test-extensions'));
diff --git a/test/parallel/test-module-multi-extensions.js b/test/parallel/test-module-multi-extensions.js
new file mode 100644
index 0000000000..be17bc5d02
--- /dev/null
+++ b/test/parallel/test-module-multi-extensions.js
@@ -0,0 +1,94 @@
+'use strict';
+
+// Refs: https://github.com/nodejs/node/issues/4778
+
+const common = require('../common');
+const assert = require('assert');
+const fs = require('fs');
+const path = require('path');
+const Module = require('module');
+const tmpdir = require('../common/tmpdir');
+const file = path.join(tmpdir.path, 'test-extensions.foo.bar');
+const dotfile = path.join(tmpdir.path, '.bar');
+const dotfileWithExtension = path.join(tmpdir.path, '.foo.bar');
+
+tmpdir.refresh();
+fs.writeFileSync(file, 'console.log(__filename);', 'utf8');
+fs.writeFileSync(dotfile, 'console.log(__filename);', 'utf8');
+fs.writeFileSync(dotfileWithExtension, 'console.log(__filename);', 'utf8');
+
+{
+ require.extensions['.bar'] = common.mustNotCall();
+ require.extensions['.foo.bar'] = common.mustCall();
+ const modulePath = path.join(tmpdir.path, 'test-extensions');
+ require(modulePath);
+ require(file);
+ delete require.cache[file];
+ delete require.extensions['.bar'];
+ delete require.extensions['.foo.bar'];
+ Module._pathCache = Object.create(null);
+}
+
+{
+ require.extensions['.foo.bar'] = common.mustCall();
+ const modulePath = path.join(tmpdir.path, 'test-extensions');
+ require(modulePath);
+ assert.throws(
+ () => require(`${modulePath}.foo`),
+ new Error(`Cannot find module '${modulePath}.foo'`)
+ );
+ require(`${modulePath}.foo.bar`);
+ delete require.cache[file];
+ delete require.extensions['.foo.bar'];
+ Module._pathCache = Object.create(null);
+}
+
+{
+ const modulePath = path.join(tmpdir.path, 'test-extensions');
+ assert.throws(
+ () => require(modulePath),
+ new Error(`Cannot find module '${modulePath}'`)
+ );
+ delete require.cache[file];
+ Module._pathCache = Object.create(null);
+}
+
+{
+ require.extensions['.bar'] = common.mustNotCall();
+ require.extensions['.foo.bar'] = common.mustCall();
+ const modulePath = path.join(tmpdir.path, 'test-extensions.foo');
+ require(modulePath);
+ delete require.cache[file];
+ delete require.extensions['.bar'];
+ delete require.extensions['.foo.bar'];
+ Module._pathCache = Object.create(null);
+}
+
+{
+ require.extensions['.foo.bar'] = common.mustNotCall();
+ const modulePath = path.join(tmpdir.path, 'test-extensions.foo');
+ assert.throws(
+ () => require(modulePath),
+ new Error(`Cannot find module '${modulePath}'`)
+ );
+ delete require.extensions['.foo.bar'];
+ Module._pathCache = Object.create(null);
+}
+
+{
+ require.extensions['.bar'] = common.mustNotCall();
+ require(dotfile);
+ delete require.cache[dotfile];
+ delete require.extensions['.bar'];
+ Module._pathCache = Object.create(null);
+}
+
+{
+ require.extensions['.bar'] = common.mustCall();
+ require.extensions['.foo.bar'] = common.mustNotCall();
+ require(dotfileWithExtension);
+ delete require.cache[dotfileWithExtension];
+ delete require.extensions['.bar'];
+ delete require.extensions['.foo.bar'];
+ Module._pathCache = Object.create(null);
+}