mirror of
https://github.com/discourse/discourse.git
synced 2025-04-26 04:14:31 +08:00
DEV: Add source-map-support in tests for qunit stack-traces (#23653)
The source-map-support package uses JS sourcemaps to improve the human-readability of Error#stack stacktraces.
This commit is contained in:
parent
2a10ea0e3f
commit
42070d49da
@ -71,6 +71,9 @@ module.exports = function (defaults) {
|
|||||||
util: require.resolve("util/"),
|
util: require.resolve("util/"),
|
||||||
// Also for sinon
|
// Also for sinon
|
||||||
timers: false,
|
timers: false,
|
||||||
|
// For source-map-support
|
||||||
|
path: require.resolve("path-browserify"),
|
||||||
|
fs: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
@ -226,6 +229,13 @@ module.exports = function (defaults) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
resolve: {
|
||||||
|
fallback: {
|
||||||
|
// For source-map-support
|
||||||
|
path: require.resolve("path-browserify"),
|
||||||
|
fs: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -95,6 +95,7 @@
|
|||||||
"loader.js": "^4.7.0",
|
"loader.js": "^4.7.0",
|
||||||
"message-bus-client": "^4.3.8",
|
"message-bus-client": "^4.3.8",
|
||||||
"messageformat": "0.1.5",
|
"messageformat": "0.1.5",
|
||||||
|
"path-browserify": "^1.0.1",
|
||||||
"pretender": "^3.4.7",
|
"pretender": "^3.4.7",
|
||||||
"qunit": "^2.20.0",
|
"qunit": "^2.20.0",
|
||||||
"qunit-dom": "^2.0.0",
|
"qunit-dom": "^2.0.0",
|
||||||
@ -103,6 +104,7 @@
|
|||||||
"sinon": "^16.0.0",
|
"sinon": "^16.0.0",
|
||||||
"float-kit": "1.0.0",
|
"float-kit": "1.0.0",
|
||||||
"source-map": "^0.7.4",
|
"source-map": "^0.7.4",
|
||||||
|
"source-map-support": "^0.5.21",
|
||||||
"terser": "^5.20.0",
|
"terser": "^5.20.0",
|
||||||
"truth-helpers": "1.0.0",
|
"truth-helpers": "1.0.0",
|
||||||
"util": "^0.12.5",
|
"util": "^0.12.5",
|
||||||
|
@ -41,6 +41,13 @@ import SiteSettingService from "discourse/services/site-settings";
|
|||||||
import jQuery from "jquery";
|
import jQuery from "jquery";
|
||||||
import { setupDeprecationCounter } from "discourse/tests/helpers/deprecation-counter";
|
import { setupDeprecationCounter } from "discourse/tests/helpers/deprecation-counter";
|
||||||
import { configureRaiseOnDeprecation } from "discourse/tests/helpers/raise-on-deprecation";
|
import { configureRaiseOnDeprecation } from "discourse/tests/helpers/raise-on-deprecation";
|
||||||
|
import SourceMapSupport from "source-map-support";
|
||||||
|
|
||||||
|
// Updates Error.stack to include source-mapped locations.
|
||||||
|
// Makes QUnit errors more human-readable
|
||||||
|
SourceMapSupport.install({
|
||||||
|
handleUncaughtExceptions: false,
|
||||||
|
});
|
||||||
|
|
||||||
const Plugin = $.fn.modal;
|
const Plugin = $.fn.modal;
|
||||||
const Modal = Plugin.Constructor;
|
const Modal = Plugin.Constructor;
|
||||||
@ -301,8 +308,18 @@ export default function setupTests(config) {
|
|||||||
throw new Error(error);
|
throw new Error(error);
|
||||||
};
|
};
|
||||||
|
|
||||||
pretender.checkPassthrough = (request) =>
|
pretender.checkPassthrough = (request) => {
|
||||||
request.requestHeaders["Discourse-Script"];
|
const requestUrl = new URL(request.url, location.href);
|
||||||
|
if (
|
||||||
|
requestUrl.origin === location.origin &&
|
||||||
|
requestUrl.pathname.startsWith("/assets/")
|
||||||
|
) {
|
||||||
|
// Likely a request from source-map-support package
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return request.requestHeaders["Discourse-Script"];
|
||||||
|
};
|
||||||
|
|
||||||
applyPretender(ctx.module, pretender, pretenderHelpers());
|
applyPretender(ctx.module, pretender, pretenderHelpers());
|
||||||
|
|
||||||
@ -394,6 +411,7 @@ export default function setupTests(config) {
|
|||||||
setupToolbar();
|
setupToolbar();
|
||||||
reportMemoryUsageAfterTests();
|
reportMemoryUsageAfterTests();
|
||||||
patchFailedAssertion();
|
patchFailedAssertion();
|
||||||
|
patchStacktraceOrigin();
|
||||||
|
|
||||||
if (!hasPluginJs && !hasThemeJs) {
|
if (!hasPluginJs && !hasThemeJs) {
|
||||||
configureRaiseOnDeprecation();
|
configureRaiseOnDeprecation();
|
||||||
@ -421,6 +439,25 @@ function patchFailedAssertion() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stacktraces tend to look something like `http://localhost:4200/assets/...`.
|
||||||
|
* This patch removes the `http://localhost:4200` part to make things cleaner.
|
||||||
|
*/
|
||||||
|
function patchStacktraceOrigin() {
|
||||||
|
const oldPushResult = QUnit.assert.pushResult;
|
||||||
|
|
||||||
|
QUnit.assert.pushResult = function (resultInfo) {
|
||||||
|
if (resultInfo.source) {
|
||||||
|
resultInfo.source = resultInfo.source.replaceAll(
|
||||||
|
`${window.origin}/`,
|
||||||
|
"/"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
oldPushResult.call(this, resultInfo);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function handleLegacyParameters() {
|
function handleLegacyParameters() {
|
||||||
for (const param of [
|
for (const param of [
|
||||||
"qunit_single_plugin",
|
"qunit_single_plugin",
|
||||||
|
@ -8781,6 +8781,11 @@ patch-package@^8.0.0:
|
|||||||
tmp "^0.0.33"
|
tmp "^0.0.33"
|
||||||
yaml "^2.2.2"
|
yaml "^2.2.2"
|
||||||
|
|
||||||
|
path-browserify@^1.0.1:
|
||||||
|
version "1.0.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-1.0.1.tgz#d98454a9c3753d5790860f16f68867b9e46be1fd"
|
||||||
|
integrity sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==
|
||||||
|
|
||||||
path-exists@^3.0.0:
|
path-exists@^3.0.0:
|
||||||
version "3.0.0"
|
version "3.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-3.0.0.tgz#ce0ebeaa5f78cb18925ea7d810d7b59b010fd515"
|
resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-3.0.0.tgz#ce0ebeaa5f78cb18925ea7d810d7b59b010fd515"
|
||||||
@ -9860,7 +9865,7 @@ source-map-resolve@^0.5.0:
|
|||||||
source-map-url "^0.4.0"
|
source-map-url "^0.4.0"
|
||||||
urix "^0.1.0"
|
urix "^0.1.0"
|
||||||
|
|
||||||
source-map-support@~0.5.20:
|
source-map-support@^0.5.21, source-map-support@~0.5.20:
|
||||||
version "0.5.21"
|
version "0.5.21"
|
||||||
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.21.tgz#04fe7c7f9e1ed2d662233c28cb2b35b9f63f6e4f"
|
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.21.tgz#04fe7c7f9e1ed2d662233c28cb2b35b9f63f6e4f"
|
||||||
integrity sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==
|
integrity sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==
|
||||||
|
Loading…
x
Reference in New Issue
Block a user