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

Added tests for resolve-node-specifier.ts to ensure that relative path resolution works. #19

Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions src/test/resolve-node-specifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,35 @@ test('resolveNodeSpecifier resolves extension-less relative path', (t) => {
'./node_modules/z/binary-file.node',
'should resolve to `.node` extension');
});

test('resolveNodeSpecifier resolves relative paths', (t) => {
t.plan(5);
t.equal(
resolve('./some-file.js'),
'./some-file.js',
'should resolve relative path to non-package file');
t.equal(
resolve('./non-existing-file.js'),
'./non-existing-file.js',
'should resolve a relative path specifier when the file does not exist');
t.equal(
resolve('./node_modules/x/main.js'),
'./node_modules/x/main.js',
'should resolve relative path to existing main file');
t.equal(
resolve('./node_modules/y/main.js'),
'./node_modules/y/main.js',
'should resolve relative path to existing jsnext:main file');
t.equal(
resolve('./node_modules/z/main.js'),
'./node_modules/z/main.js',
'should resolve relative path to existing module file');
});

test('resolveNodeSpecifier resolves modules without import/export', (t) => {
t.plan(1);
t.equal(
resolve('no-imports-or-exports'),
'./node_modules/no-imports-or-exports/main.js',
'should resolve package which contains non-module main.js');
});
1 change: 1 addition & 0 deletions test/fixtures/node_modules/no-imports-or-exports/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions test/fixtures/node_modules/no-imports-or-exports/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/fixtures/some-file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Just some file.')