Skip to content

Commit

Permalink
Merge pull request #19 from Polymer/resolve-module-specifier-for-file…
Browse files Browse the repository at this point in the history
…-without-imports-and-exports

Added tests for `resolve-node-specifier.ts` to ensure that relative path resolution works.
  • Loading branch information
usergenic authored Jun 18, 2019
2 parents 8114f0b + 8e2a635 commit 20c3d04
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
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.')

0 comments on commit 20c3d04

Please sign in to comment.