Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add second set of tests #25

Merged
merged 8 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
* begin dusting off this old package
* move tests into subdirectory, prepare for multiple test packages
* use shields io npm badge
* add tests for export patterns from nodejs documentation
* add exports.import definition
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"version": "0.8.6",
"license": "ISC",
"main": "resolvewithplus.js",
"exports": {
"import": "./resolvewithplus.js"
},
iambumblehead marked this conversation as resolved.
Show resolved Hide resolved
"readmeFilename": "README.md",
"description": "resolvewith with extra power",
"type": "module",
Expand Down
14 changes: 9 additions & 5 deletions resolvewithplus.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ export default (o => {

if (isBuiltinRe.test(requirepath)) {
fullpath = requirepath;
} else if (isDirPathRe.test(requirepath)) {
fullpath = o.getasfileordir(requirepath, withpath, opts);
fullpath = fullpath && realpath(fullpath);
} else {
fullpath = o.getasnode_module(requirepath, withpath);
fullpath = isDirPathRe.test(requirepath)
? o.getasfileordir(requirepath, withpath, opts)
: o.getasnode_module(requirepath, withpath);

fullpath = fullpath && realpath(fullpath);
}

Expand Down Expand Up @@ -104,7 +104,11 @@ export default (o => {
if (typeof esmexportsobj['.'] === 'string') {
indexval = esmexportsobj['.'];
}

// "exports": {
// ".": {
// "import": "./lib/index.js"
// }
// }
if (typeof esmexportsobj['.'].import === 'string') {
indexval = esmexportsobj['.'].import;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'feature-index';
1 change: 1 addition & 0 deletions tests/tests-basic/nodejsexample_02_exports/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'lib-index';
18 changes: 18 additions & 0 deletions tests/tests-basic/nodejsexample_02_exports/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "nodejsexample_02_exports",
"type": "module",
"repository": {
"type": "git",
"url": "https://github.com/iambumblehead/resolvewithplus.git"
},
"exports": {
".": "./lib/index.js",
"./lib": "./lib/index.js",
"./lib/*": "./lib/*.js",
"./lib/*.js": "./lib/*.js",
"./feature": "./feature/index.js",
"./feature/*": "./feature/*.js",
"./feature/*.js": "./feature/*.js",
"./package.json": "./package.json"
}
}
1 change: 1 addition & 0 deletions tests/tests-basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
},
"dependencies": {
"nodejsexample_01_exports": "file:nodejsexample_01_exports",
"nodejsexample_02_exports": "file:nodejsexample_02_exports",
"resolvewithplus": "file:.."
},
"scripts": {
Expand Down
55 changes: 55 additions & 0 deletions tests/tests-basic/tests-export-patterns.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,58 @@ test('should mock all exports from nodejsexample_01_exports', () => {
resolvewithplus('nodejsexample_01_exports/package.json'),
noderesolvedpackagejson)
});

// from: https://nodejs.org/api/packages.html#package-entry-points
// {
// "name": "my-package",
// "exports": {
// ".": "./lib/index.js",
// "./lib": "./lib/index.js",
// "./lib/*": "./lib/*.js",
// "./lib/*.js": "./lib/*.js",
// "./feature": "./feature/index.js",
// "./feature/*": "./feature/*.js",
// "./feature/*.js": "./feature/*.js",
// "./package.json": "./package.json"
// }
// }
test('should mock all exports from nodejsexample_02_exports', () => {
const noderesolvedlibindex = path
.resolve('./nodejsexample_02_exports/lib/index.js');
const noderesolvedfeatureindex = path
.resolve('./nodejsexample_02_exports/feature/index.js');
const noderesolvedpackagejson = path
.resolve('./nodejsexample_02_exports/package.json');

assert.strictEqual(
resolvewithplus('nodejsexample_02_exports'),
noderesolvedlibindex);

assert.strictEqual(
resolvewithplus('nodejsexample_02_exports/lib'),
noderesolvedlibindex);

assert.strictEqual(
resolvewithplus('nodejsexample_02_exports/lib/index'),
noderesolvedlibindex);

assert.strictEqual(
resolvewithplus('nodejsexample_02_exports/lib/index.js'),
noderesolvedlibindex);

assert.strictEqual(
resolvewithplus('nodejsexample_02_exports/feature'),
noderesolvedfeatureindex);

assert.strictEqual(
resolvewithplus('nodejsexample_02_exports/feature/index'),
noderesolvedfeatureindex);

assert.strictEqual(
resolvewithplus('nodejsexample_02_exports/feature/index.js'),
noderesolvedfeatureindex);

assert.strictEqual(
resolvewithplus('nodejsexample_02_exports/package.json'),
noderesolvedpackagejson)
});