From 4621760b39eb7089a4467b5e44bd3dd86be0bccb Mon Sep 17 00:00:00 2001 From: Lucas Werkmeister Date: Mon, 5 Jun 2023 16:23:52 +0200 Subject: [PATCH] Fix image URLs in build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Vite is supposed to prefix asset [1] URLs with the base / origin, and you can see this working for url() in CSS (otherwise the Wikidata logo would be broken), but due to vitejs/vite-plugin-vue#85 [2] this doesn’t work for src= attributes. Work around it by importing the importing the files and then using that URL dynamically. (In the tests, we need to map those imports to a fake module so Jest doesn’t try to load the real file content as JS source.) [1]: https://vitejs.dev/guide/assets.html [2]: https://github.com/vitejs/vite-plugin-vue/issues/85 Bug: T335754 Change-Id: Ie3c1cf9c225c646b2f7d94727a634e9ff78aad4e --- jest.config.js | 1 + src/components/LanguageSelector.vue | 4 +++- src/components/LanguageSelectorInput.vue | 12 ++++++++++-- tests/config/fileMock.js | 1 + 4 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 tests/config/fileMock.js diff --git a/jest.config.js b/jest.config.js index 3494acd7..2ad83b42 100644 --- a/jest.config.js +++ b/jest.config.js @@ -8,6 +8,7 @@ module.exports = { collectCoverageFrom: [ 'src/**/*.{ts,vue}' ], moduleNameMapper: { '^@/(.*)$': '/src/$1', + '/img/(.*)$': '/tests/config/fileMock.js', }, transform: { '.*\\.(vue)$': '@vue/vue2-jest', diff --git a/src/components/LanguageSelector.vue b/src/components/LanguageSelector.vue index fa040d5c..673296e9 100644 --- a/src/components/LanguageSelector.vue +++ b/src/components/LanguageSelector.vue @@ -3,7 +3,7 @@
{{ $i18n( 'query-builder-language-selector-mobile-header' ) }}
( { searchInput: '', highlightedIndex: -1, + closeUrl, } ), computed: { languages(): Language[] { diff --git a/src/components/LanguageSelectorInput.vue b/src/components/LanguageSelectorInput.vue index c701f7ab..203eb780 100644 --- a/src/components/LanguageSelectorInput.vue +++ b/src/components/LanguageSelectorInput.vue @@ -2,7 +2,7 @@
- +
- +