Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 20c3d04

Browse files
authored
Merge pull request #19 from Polymer/resolve-module-specifier-for-file-without-imports-and-exports
Added tests for `resolve-node-specifier.ts` to ensure that relative path resolution works.
2 parents 8114f0b + 8e2a635 commit 20c3d04

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/test/resolve-node-specifier.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,35 @@ test('resolveNodeSpecifier resolves extension-less relative path', (t) => {
7171
'./node_modules/z/binary-file.node',
7272
'should resolve to `.node` extension');
7373
});
74+
75+
test('resolveNodeSpecifier resolves relative paths', (t) => {
76+
t.plan(5);
77+
t.equal(
78+
resolve('./some-file.js'),
79+
'./some-file.js',
80+
'should resolve relative path to non-package file');
81+
t.equal(
82+
resolve('./non-existing-file.js'),
83+
'./non-existing-file.js',
84+
'should resolve a relative path specifier when the file does not exist');
85+
t.equal(
86+
resolve('./node_modules/x/main.js'),
87+
'./node_modules/x/main.js',
88+
'should resolve relative path to existing main file');
89+
t.equal(
90+
resolve('./node_modules/y/main.js'),
91+
'./node_modules/y/main.js',
92+
'should resolve relative path to existing jsnext:main file');
93+
t.equal(
94+
resolve('./node_modules/z/main.js'),
95+
'./node_modules/z/main.js',
96+
'should resolve relative path to existing module file');
97+
});
98+
99+
test('resolveNodeSpecifier resolves modules without import/export', (t) => {
100+
t.plan(1);
101+
t.equal(
102+
resolve('no-imports-or-exports'),
103+
'./node_modules/no-imports-or-exports/main.js',
104+
'should resolve package which contains non-module main.js');
105+
});

test/fixtures/node_modules/no-imports-or-exports/main.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/node_modules/no-imports-or-exports/package.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/some-file.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('Just some file.')

0 commit comments

Comments
 (0)