Skip to content

Commit e865d19

Browse files
committed
Correct types; add tests
1 parent 94e5587 commit e865d19

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

source-map-support.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ export interface Options {
3838
/**
3939
* Callback will be called every time we redirect due to `redirectConflictingLibrary`
4040
* This allows consumers to log helpful warnings if they choose.
41+
* @param parent NodeJS.Module which made the require() or require.resolve() call
4142
*/
42-
onConflictingLibraryRedirect?: (request, parent, isMain, redirectedRequest) => void;
43+
onConflictingLibraryRedirect?: (request: string, parent: any, isMain: boolean, redirectedRequest: string) => void;
4344
}
4445

4546
export interface Position {

test.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
require('./source-map-support').install({
1+
const underTest = require('./source-map-support');
2+
underTest.install({
23
emptyCacheBetweenOperations: true // Needed to be able to test for failure
34
});
45

@@ -680,3 +681,36 @@ it('supports multiple instances', function(done) {
680681
/^ at foo \((?:.*[/\\])?.original2\.js:1:1\)$/
681682
]);
682683
});
684+
685+
describe('redirects require() of "source-map-support" to this module', function() {
686+
it('redirects', function() {
687+
assert.strictEqual(require.resolve('source-map-support'), require.resolve('.'));
688+
assert.strictEqual(require.resolve('source-map-support/register'), require.resolve('./register'));
689+
assert.strictEqual(require('source-map-support'), require('.'));
690+
});
691+
692+
it('emits notifications', function() {
693+
let onConflictingLibraryRedirectCalls = [];
694+
let onConflictingLibraryRedirectCalls2 = [];
695+
underTest.install({
696+
onConflictingLibraryRedirect(request, parent, isMain, redirectedRequest) {
697+
onConflictingLibraryRedirectCalls.push([...arguments]);
698+
}
699+
});
700+
underTest.install({
701+
onConflictingLibraryRedirect(request, parent, isMain, redirectedRequest) {
702+
onConflictingLibraryRedirectCalls2.push([...arguments]);
703+
}
704+
});
705+
require.resolve('source-map-support');
706+
assert.strictEqual(onConflictingLibraryRedirectCalls.length, 1);
707+
assert.strictEqual(onConflictingLibraryRedirectCalls2.length, 1);
708+
for(const args of [onConflictingLibraryRedirectCalls[0], onConflictingLibraryRedirectCalls2[0]]) {
709+
const [request, parent, isMain, redirectedRequest] = args;
710+
assert.strictEqual(request, 'source-map-support');
711+
assert.strictEqual(parent, module);
712+
assert.strictEqual(isMain, false);
713+
assert.strictEqual(redirectedRequest, require.resolve('.'));
714+
}
715+
});
716+
});

0 commit comments

Comments
 (0)