Skip to content

Commit 96d38c6

Browse files
jmmljharb
authored andcommitted
Add failing test for parent filename in error msg.
1 parent ad16af2 commit 96d38c6

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

test/resolver.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ test('async foo', function (t) {
3434
t.equal(err.message, "Cannot find module 'foo' from '" + path.resolve(dir) + "'");
3535
t.equal(err.code, 'MODULE_NOT_FOUND');
3636
});
37+
38+
// Test that filename is reported as the "from" value when passed.
39+
resolve('foo', { basedir: dir, filename: path.join(dir, 'baz.js') }, function (err) {
40+
t.equal(err.message, "Cannot find module 'foo' from '" + path.join(dir, 'baz.js') + "'");
41+
});
3742
});
3843

3944
test('bar', function (t) {
@@ -193,6 +198,12 @@ test('cup', function (t) {
193198
t.equal(err.message, "Cannot find module './cup' from '" + path.resolve(dir) + "'");
194199
t.equal(err.code, 'MODULE_NOT_FOUND');
195200
});
201+
202+
// Test that filename is reported as the "from" value when passed.
203+
resolve('./cup', { basedir: dir, extensions: [ '.js' ], filename: path.join(dir, 'cupboard.js') },
204+
function (err, res) {
205+
t.equal(err.message, "Cannot find module './cup' from '" + path.join(dir, 'cupboard.js') + "'");
206+
});
196207
});
197208

198209
test('mug', function (t) {

test/resolver_sync.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var path = require('path');
22
var test = require('tape');
33
var resolve = require('../');
4+
var path = require('path');
45

56
test('foo', function (t) {
67
var dir = path.join(__dirname, 'resolver');
@@ -19,6 +20,17 @@ test('foo', function (t) {
1920
resolve.sync('foo', { basedir: dir });
2021
});
2122

23+
// Test that filename is reported as the "from" value when passed.
24+
t.throws(
25+
function () {
26+
resolve.sync('foo', { basedir: dir, filename: path.join(dir, 'bar.js') });
27+
},
28+
{
29+
name: 'Error',
30+
message: "Cannot find module 'foo' from '" + path.join(dir, 'bar.js') + "'"
31+
}
32+
);
33+
2234
t.end();
2335
});
2436

0 commit comments

Comments
 (0)