summaryrefslogtreecommitdiff
path: root/test/es-module
diff options
context:
space:
mode:
authorGuy Bedford <guybedford@gmail.com>2019-10-13 19:27:39 -0400
committerGuy Bedford <guybedford@gmail.com>2019-11-08 17:26:26 -0500
commit2367474db46136aecb87b27d82bfa597a95aeedd (patch)
tree58fd8eb4ad143677a791b00f994965d9573e562b /test/es-module
parentc73ef32d355aa58672c15e89534c375dd2246f3c (diff)
downloadandroid-node-v8-2367474db46136aecb87b27d82bfa597a95aeedd.tar.gz
android-node-v8-2367474db46136aecb87b27d82bfa597a95aeedd.tar.bz2
android-node-v8-2367474db46136aecb87b27d82bfa597a95aeedd.zip
module: conditional exports with flagged conditions
PR-URL: https://github.com/nodejs/node/pull/29978 Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com>
Diffstat (limited to 'test/es-module')
-rw-r--r--test/es-module/test-esm-exports.mjs31
1 files changed, 27 insertions, 4 deletions
diff --git a/test/es-module/test-esm-exports.mjs b/test/es-module/test-esm-exports.mjs
index d8c3399418..2683b5df68 100644
--- a/test/es-module/test-esm-exports.mjs
+++ b/test/es-module/test-esm-exports.mjs
@@ -1,4 +1,4 @@
-// Flags: --experimental-modules --experimental-resolve-self
+// Flags: --experimental-modules --experimental-resolve-self --experimental-conditional-exports
import { mustCall } from '../common/index.mjs';
import { ok, deepStrictEqual, strictEqual } from 'assert';
@@ -23,7 +23,16 @@ import fromInside from '../fixtures/node_modules/pkgexports/lib/hole.js';
['pkgexports/fallbackfile', { default: 'asdf' }],
// Dot main
['pkgexports', { default: 'asdf' }],
+ // Conditional split for require
+ ['pkgexports/condition', isRequire ? { default: 'encoded path' } :
+ { default: 'asdf' }],
+ // String exports sugar
+ ['pkgexports-sugar', { default: 'main' }],
+ // Conditional object exports sugar
+ ['pkgexports-sugar2', isRequire ? { default: 'not-exported' } :
+ { default: 'main' }]
]);
+
for (const [validSpecifier, expected] of validSpecifiers) {
if (validSpecifier === null) continue;
@@ -39,6 +48,9 @@ import fromInside from '../fixtures/node_modules/pkgexports/lib/hole.js';
// The file exists but isn't exported. The exports is a number which counts
// as a non-null value without any properties, just like `{}`.
['pkgexports-number/hidden.js', './hidden.js'],
+ // Sugar cases still encapsulate
+ ['pkgexports-sugar/not-exported.js', './not-exported.js'],
+ ['pkgexports-sugar2/not-exported.js', './not-exported.js']
]);
const invalidExports = new Map([
@@ -79,7 +91,7 @@ import fromInside from '../fixtures/node_modules/pkgexports/lib/hole.js';
assertStartsWith(err.message, (isRequire ? 'Package exports' :
'Cannot resolve'));
assertIncludes(err.message, isRequire ?
- `do not define a valid '${subpath}' subpath` :
+ `do not define a valid '${subpath}' target` :
`matched for '${subpath}'`);
}));
}
@@ -93,11 +105,22 @@ import fromInside from '../fixtures/node_modules/pkgexports/lib/hole.js';
'Cannot find module');
}));
- // THe use of %2F escapes in paths fails loading
+ // The use of %2F escapes in paths fails loading
loadFixture('pkgexports/sub/..%2F..%2Fbar.js').catch(mustCall((err) => {
strictEqual(err.code, isRequire ? 'ERR_INVALID_FILE_URL_PATH' :
'ERR_MODULE_NOT_FOUND');
}));
+
+ // Sugar conditional exports main mixed failure case
+ loadFixture('pkgexports-sugar-fail').catch(mustCall((err) => {
+ strictEqual(err.code, 'ERR_INVALID_PACKAGE_CONFIG');
+ assertStartsWith(err.message, (isRequire ? 'Invalid package' :
+ 'Cannot resolve'));
+ assertIncludes(err.message, '"exports" cannot contain some keys starting ' +
+ 'with \'.\' and some not. The exports object must either be an object of ' +
+ 'package subpath keys or an object of main entry condition name keys ' +
+ 'only.');
+ }));
});
const { requireFromInside, importFromInside } = fromInside;
@@ -124,6 +147,6 @@ function assertStartsWith(actual, expected) {
}
function assertIncludes(actual, expected) {
- ok(actual.toString().indexOf(expected),
+ ok(actual.toString().indexOf(expected) !== -1,
`${JSON.stringify(actual)} includes ${JSON.stringify(expected)}`);
}