Skip to content

refactor: redirect subsequent imports of "source-map-support" to this… #23

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

Merged
merged 12 commits into from
Oct 6, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'origin/master' into ej/sourceMapSupport…
…Redirect
  • Loading branch information
cspotcode committed Oct 4, 2021
commit 8ab8b7a727a583d78d7194da6520b5b21179ba79
79 changes: 74 additions & 5 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const underTest = require('./source-map-support');
underTest.install({
emptyCacheBetweenOperations: true // Needed to be able to test for failure
});
// Note: some tests rely on side-effects from prior tests.
// You may not get meaningful results running a subset of tests.

const priorErrorPrepareStackTrace = Error.prepareStackTrace;
const priorProcessEmit = process.emit;
Expand Down Expand Up @@ -737,4 +735,75 @@ describe('redirects require() of "source-map-support" to this module', function(
assert.strictEqual(redirectedRequest, require.resolve('.'));
}
});
});
});

describe('uninstall', function() {
this.beforeEach(function() {
underTest.uninstall();
process.emit = priorProcessEmit;
Error.prepareStackTrace = priorErrorPrepareStackTrace;
});

it('uninstall removes hooks and source-mapping behavior', function() {
assert.strictEqual(Error.prepareStackTrace, priorErrorPrepareStackTrace);
assert.strictEqual(process.emit, priorProcessEmit);
normalThrowWithoutSourceMapSupportInstalled();
});

it('install re-adds hooks', function() {
installSms();
normalThrow();
});

it('uninstall removes prepareStackTrace even in presence of third-party hooks if none were installed before us', function() {
installSms();
const wrappedPrepareStackTrace = Error.prepareStackTrace;
let pstInvocations = 0;
function thirdPartyPrepareStackTraceHook() {
pstInvocations++;
return wrappedPrepareStackTrace.apply(this, arguments);
}
Error.prepareStackTrace = thirdPartyPrepareStackTraceHook;
underTest.uninstall();
assert.strictEqual(Error.prepareStackTrace, undefined);
assert(pstInvocations === 0);
});

it('uninstall preserves third-party prepareStackTrace hooks if one was installed before us', function() {
let beforeInvocations = 0;
function thirdPartyPrepareStackTraceHookInstalledBefore() {
beforeInvocations++;
return 'foo';
}
Error.prepareStackTrace = thirdPartyPrepareStackTraceHookInstalledBefore;
installSms();
const wrappedPrepareStackTrace = Error.prepareStackTrace;
let afterInvocations = 0;
function thirdPartyPrepareStackTraceHookInstalledAfter() {
afterInvocations++;
return wrappedPrepareStackTrace.apply(this, arguments);
}
Error.prepareStackTrace = thirdPartyPrepareStackTraceHookInstalledAfter;
underTest.uninstall();
assert.strictEqual(Error.prepareStackTrace, thirdPartyPrepareStackTraceHookInstalledAfter);
assert.strictEqual(new Error().stack, 'foo');
assert.strictEqual(beforeInvocations, 1);
assert.strictEqual(afterInvocations, 1);
});

it('uninstall preserves third-party process.emit hooks installed after us', function() {
installSms();
const wrappedProcessEmit = process.emit;
let peInvocations = 0;
function thirdPartyProcessEmit() {
peInvocations++;
return wrappedProcessEmit.apply(this, arguments);
}
process.emit = thirdPartyProcessEmit;
underTest.uninstall();
assert.strictEqual(process.emit, thirdPartyProcessEmit);
normalThrowWithoutSourceMapSupportInstalled();
process.emit('foo');
assert(peInvocations >= 1);
});
});
You are viewing a condensed version of this merge commit. You can view the full changes here.