DEV: Load svg icons in dev-environment qunit tests (#24542)

Making the icons available generally in tests is tricky because they're generated dynamically by the rails server. However, if we restrict it to dev-mode (`/tests` in a browser) then it's possible to load them from the running rails server. This is purely a visual thing to make debugging easier - it should not affect test behavior.
This commit is contained in:
David Taylor 2023-11-24 10:12:10 +00:00 committed by GitHub
parent 46782a9f1c
commit 0253cba9be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -42,6 +42,8 @@
</style> </style>
</head> </head>
<body> <body>
<discourse-assets-icons></discourse-assets-icons>
{{content-for "body"}} {{content-for "test-body"}} {{content-for "body"}} {{content-for "test-body"}}
<script src="/testem.js" integrity="" data-embroider-ignore></script> <script src="/testem.js" integrity="" data-embroider-ignore></script>

View File

@ -46,6 +46,7 @@ import { setDefaultOwner } from "discourse-common/lib/get-owner";
import { setupS3CDN, setupURL } from "discourse-common/lib/get-url"; import { setupS3CDN, setupURL } from "discourse-common/lib/get-url";
import { buildResolver } from "discourse-common/resolver"; import { buildResolver } from "discourse-common/resolver";
import Application from "../app"; import Application from "../app";
import { loadSprites } from "../lib/svg-sprite-loader";
const Plugin = $.fn.modal; const Plugin = $.fn.modal;
const Modal = Plugin.Constructor; const Modal = Plugin.Constructor;
@ -394,6 +395,14 @@ export default function setupTests(config) {
setupToolbar(); setupToolbar();
reportMemoryUsageAfterTests(); reportMemoryUsageAfterTests();
patchFailedAssertion(); patchFailedAssertion();
if (!window.Testem) {
// Running in a dev server - svg sprites are available
// Using a fake 40-char version hash will redirect to the current one
loadSprites(
"/svg-sprite/localhost/svg--aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.js",
"fontawesome"
);
}
if (!hasPluginJs && !hasThemeJs) { if (!hasPluginJs && !hasThemeJs) {
configureRaiseOnDeprecation(); configureRaiseOnDeprecation();