diff --git a/front/package.json b/front/package.json index 40e77ef02..10f3d908a 100644 --- a/front/package.json +++ b/front/package.json @@ -77,6 +77,7 @@ "@vue/eslint-config-typescript": "11.0.2", "@vue/test-utils": "2.2.7", "@vue/tsconfig": "0.1.3", + "axios-mock-adapter": "1.21.4", "eslint": "8.30.0", "eslint-config-standard": "17.0.0", "eslint-plugin-html": "7.1.0", @@ -87,9 +88,9 @@ "eslint-plugin-vue": "9.8.0", "jsdom": "20.0.3", "jsonc-eslint-parser": "2.1.0", - "moxios": "0.4.0", "sass": "1.57.1", "sinon": "15.0.1", + "standardized-audio-context-mock": "9.6.18", "typescript": "4.9.4", "utility-types": "3.10.0", "vite": "4.0.4", diff --git a/front/test/setup/mock-audio-context.ts b/front/test/setup/mock-audio-context.ts new file mode 100644 index 000000000..f8cd9d1c5 --- /dev/null +++ b/front/test/setup/mock-audio-context.ts @@ -0,0 +1,9 @@ +import { AudioContext } from 'standardized-audio-context-mock' +import { vi, beforeAll } from 'vitest' + +beforeAll(() => { + vi.mock('standardized-audio-context', () => ({ + AudioContext + })) +}) + diff --git a/front/test/setup/mock-vue-i18n.ts b/front/test/setup/mock-vue-i18n.ts new file mode 100644 index 000000000..6edfc1a4b --- /dev/null +++ b/front/test/setup/mock-vue-i18n.ts @@ -0,0 +1,14 @@ +import { config } from '@vue/test-utils' +import { createI18n } from 'vue-i18n' +import en from '~/locales/en_US.json' + +const i18n = createI18n({ + legacy: false, + locale: 'en', + messages: { + en + } +}) + +config.global.plugins ??= [] +config.global.plugins.push(i18n) diff --git a/front/test/specs/views/admin/library.test.ts b/front/test/specs/views/admin/library.test.ts index ab17613cb..8e8583afa 100644 --- a/front/test/specs/views/admin/library.test.ts +++ b/front/test/specs/views/admin/library.test.ts @@ -3,7 +3,8 @@ import AlbumDetail from '~/views/admin/library/AlbumDetail.vue' import SanitizedHtml from '~/components/SanitizedHtml.vue' import HumanDate from '~/components/common/HumanDate.vue' -import moxios from 'moxios' +import MockAdapter from 'axios-mock-adapter' +import axios from 'axios' import { shallowMount } from '@vue/test-utils' import { sleep } from '?/utils' @@ -11,23 +12,15 @@ import { sleep } from '?/utils' import router from '~/router' import store from '~/store' -beforeEach(() => moxios.install()) -afterEach(() => moxios.uninstall()) +const axiosMock = new MockAdapter(axios) describe('views/admin/library', () => { describe('Album details', () => { it('displays default cover', async () => { const album = { cover: null, artist: { id: 1 }, title: 'dummy', id: 1, creation_date: '2020-01-01' } - moxios.stubRequest('manage/library/albums/1/', { - status: 200, - response: album - }) - - moxios.stubRequest('manage/library/albums/1/stats/', { - status: 200, - response: {} - }) + axiosMock.onGet('manage/library/albums/1/').reply(200, album) + axiosMock.onGet('manage/library/albums/1/stats/').reply(200, {}) const wrapper = shallowMount(AlbumDetail, { props: { id: 1 }, diff --git a/front/vite.config.ts b/front/vite.config.ts index 369a7c668..86382f293 100644 --- a/front/vite.config.ts +++ b/front/vite.config.ts @@ -52,6 +52,10 @@ export default defineConfig(({ mode }) => ({ src: './src', all: true, reporter: ['text', 'cobertura'] - } + }, + setupFiles: [ + './test/setup/mock-audio-context.ts', + './test/setup/mock-vue-i18n.ts', + ] } })) diff --git a/front/yarn.lock b/front/yarn.lock index 83289c781..ee1f17172 100644 --- a/front/yarn.lock +++ b/front/yarn.lock @@ -884,6 +884,13 @@ dependencies: regenerator-runtime "^0.13.11" +"@babel/runtime@^7.21.5": + version "7.21.5" + resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.21.5.tgz#8492dddda9644ae3bda3b45eabe87382caee7200" + integrity sha512-8jI69toZqqcsnqGGqwGS4Qb1VwLOEp4hz+CXPywcvjs60u3B4Pom/U/7rm4W8tMOYEB+E9wgD0mW1l3r8qlI9Q== + dependencies: + regenerator-runtime "^0.13.11" + "@babel/template@^7.18.10", "@babel/template@^7.20.7": version "7.20.7" resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.20.7.tgz#a15090c2839a83b02aa996c0b4994005841fd5a8" @@ -1399,6 +1406,13 @@ dependencies: type-detect "4.0.8" +"@sinonjs/commons@^3.0.0": + version "3.0.0" + resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-3.0.0.tgz#beb434fe875d965265e04722ccfc21df7f755d72" + integrity sha512-jXBtWAF4vmdNmZgD5FoKsVLv3rPgDnLgPbU84LIJ3otV44vJlDRokVng5v8NFJdCf/da9legHcKaRuZs4L7faA== + dependencies: + type-detect "4.0.8" + "@sinonjs/fake-timers@10.0.2", "@sinonjs/fake-timers@^10.0.2": version "10.0.2" resolved "https://registry.yarnpkg.com/@sinonjs/fake-timers/-/fake-timers-10.0.2.tgz#d10549ed1f423d80639c528b6c7f5a1017747d0c" @@ -1415,6 +1429,15 @@ lodash.get "^4.4.2" type-detect "^4.0.8" +"@sinonjs/samsam@^8.0.0": + version "8.0.0" + resolved "https://registry.yarnpkg.com/@sinonjs/samsam/-/samsam-8.0.0.tgz#0d488c91efb3fa1442e26abea81759dfc8b5ac60" + integrity sha512-Bp8KUVlLp8ibJZrnvq2foVhP0IVX2CIprMJPK0vqGqgrDa0OHVKeZyBykqskkrdxV6yKBPmGasO8LVjAKR3Gew== + dependencies: + "@sinonjs/commons" "^2.0.0" + lodash.get "^4.4.2" + type-detect "^4.0.8" + "@sinonjs/text-encoding@^0.7.1": version "0.7.2" resolved "https://registry.yarnpkg.com/@sinonjs/text-encoding/-/text-encoding-0.7.2.tgz#5981a8db18b56ba38ef0efb7d995b12aa7b51918" @@ -2293,6 +2316,14 @@ automation-events@^5.0.0: "@babel/runtime" "^7.20.7" tslib "^2.4.1" +automation-events@^6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/automation-events/-/automation-events-6.0.1.tgz#2c645461907d6e6de834a6c4f3345a7172de7cfb" + integrity sha512-AHpETuZtlDy9/lupkn7GZIpUxgAlx7AjVGU6uh04wrrMawNf9Zjr6Erl/QoHRhQvIGMdFrs+6B2ngkh50lNJ9w== + dependencies: + "@babel/runtime" "^7.21.5" + tslib "^2.5.0" + available-typed-arrays@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz#92f95616501069d07d10edb2fc37d3e1c65123b7" @@ -2303,6 +2334,14 @@ axios-auth-refresh@3.3.6: resolved "https://registry.yarnpkg.com/axios-auth-refresh/-/axios-auth-refresh-3.3.6.tgz#a879f6296a889d6616e51069c2a8135b697966e7" integrity sha512-2CeBUce/SxIfFxow5/n8vApJ97yYF6qoV4gh1UrswT7aEOnlOdBLxxyhOI4IaxGs6BY0l8YujU2jlc4aCmK17Q== +axios-mock-adapter@1.21.4: + version "1.21.4" + resolved "https://registry.yarnpkg.com/axios-mock-adapter/-/axios-mock-adapter-1.21.4.tgz#ced09b54b245b338422e3af425ae529bfa26e051" + integrity sha512-ztnENm28ONAKeRXC/6SUW6pcsaXbThKq93MRDRAA47LYTzrGSDoO/DCr1NHz7jApEl95DrBoGPvZ0r9xtSbjqw== + dependencies: + fast-deep-equal "^3.1.3" + is-buffer "^2.0.5" + axios@1.2.3, axios@>=0.13.0: version "1.2.3" resolved "https://registry.yarnpkg.com/axios/-/axios-1.2.3.tgz#31a3d824c0ebf754a004b585e5f04a5f87e6c4ff" @@ -2691,7 +2730,7 @@ debug@^3.2.7: dependencies: ms "^2.1.1" -decimal.js@^10.4.2: +decimal.js@^10.4.2, decimal.js@^10.4.3: version "10.4.3" resolved "https://registry.yarnpkg.com/decimal.js/-/decimal.js-10.4.3.tgz#1044092884d245d1b7f65725fa4ad4c6f781cc23" integrity sha512-VBBaLc1MgL5XpzgIP7ny5Z6Nx3UrRkIViUkPUdtl9aya5amy3De1gsUUSB1g3+3sExYNjCAsAznmukyxCb1GRA== @@ -2726,7 +2765,7 @@ delayed-stream@~1.0.0: resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619" integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ== -diff@5.1.0, diff@^5.0.0: +diff@5.1.0, diff@^5.0.0, diff@^5.1.0: version "5.1.0" resolved "https://registry.yarnpkg.com/diff/-/diff-5.1.0.tgz#bc52d298c5ea8df9194800224445ed43ffc87e40" integrity sha512-D+mk+qE8VC/PAUrlAU34N+VfXev0ghe5ywmpqrawphmVZc1bEfn56uo9qpyGp1p4xpzOHkSW4ztBd6L7Xx4ACw== @@ -3735,6 +3774,11 @@ is-boolean-object@^1.1.0: call-bind "^1.0.2" has-tostringtag "^1.0.0" +is-buffer@^2.0.5: + version "2.0.5" + resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-2.0.5.tgz#ebc252e400d22ff8d77fa09888821a24a658c191" + integrity sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ== + is-callable@^1.1.3, is-callable@^1.1.4, is-callable@^1.2.7: version "1.2.7" resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.2.7.tgz#3bc2a85ea742d9e36205dcacdd72ca1fdc51b055" @@ -4248,11 +4292,6 @@ moment@2.29.4: resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.4.tgz#3dbe052889fe7c1b2ed966fcb3a77328964ef108" integrity sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w== -moxios@0.4.0: - version "0.4.0" - resolved "https://registry.yarnpkg.com/moxios/-/moxios-0.4.0.tgz#fc0da2c65477d725ca6b9679d58370ed0c52f53b" - integrity sha512-r+7DOsTcoTAwY6TGIDtjeTEBXMW8aGgk74MfASOC1tgYXD8Kq+cnqQHUdMnvfjf/CK7Pg/Wo52ohqy5zlyv9XQ== - ms@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" @@ -4288,7 +4327,7 @@ natural-compare@^1.4.0: resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" integrity sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw== -nise@^5.1.2: +nise@^5.1.2, nise@^5.1.4: version "5.1.4" resolved "https://registry.yarnpkg.com/nise/-/nise-5.1.4.tgz#491ce7e7307d4ec546f5a659b2efe94a18b4bbc0" integrity sha512-8+Ib8rRJ4L0o3kfmyVCL7gzrohyDe0cMFTBa2d364yIrEGMEoetznKJx899YxjybU6bL9SQkYPSBBs1gyYs8Xg== @@ -4812,6 +4851,18 @@ sinon@15.0.1: nise "^5.1.2" supports-color "^7.2.0" +sinon@^15.0.4: + version "15.0.4" + resolved "https://registry.yarnpkg.com/sinon/-/sinon-15.0.4.tgz#bcca6fef19b14feccc96473f0d7adc81e0bc5268" + integrity sha512-uzmfN6zx3GQaria1kwgWGeKiXSSbShBbue6Dcj0SI8fiCNFbiUDqKl57WFlY5lyhxZVUKmXvzgG2pilRQCBwWg== + dependencies: + "@sinonjs/commons" "^3.0.0" + "@sinonjs/fake-timers" "^10.0.2" + "@sinonjs/samsam" "^8.0.0" + diff "^5.1.0" + nise "^5.1.4" + supports-color "^7.2.0" + slash@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634" @@ -4852,6 +4903,18 @@ sourcemap-codec@^1.4.8: resolved "https://registry.yarnpkg.com/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz#ea804bd94857402e6992d05a38ef1ae35a9ab4c4" integrity sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA== +standardized-audio-context-mock@9.6.18: + version "9.6.18" + resolved "https://registry.yarnpkg.com/standardized-audio-context-mock/-/standardized-audio-context-mock-9.6.18.tgz#0b2dc9039a0f923a64012cf53407072a7e05c62e" + integrity sha512-yUaPX9qdRRKTxkS9h3QvKd+OQ7nRoIKj0cVg/9D6ugQynvRczJIS6KMTZcigi2OfwOKI3X0Gy1aKZC5YUl79Tw== + dependencies: + "@babel/runtime" "^7.21.5" + automation-events "^6.0.1" + sinon "^15.0.4" + standardized-audio-context "^25.3.46" + tslib "^2.5.0" + vehicles "^9.0.1" + standardized-audio-context@25.3.37: version "25.3.37" resolved "https://registry.yarnpkg.com/standardized-audio-context/-/standardized-audio-context-25.3.37.tgz#2b0f00aa5baf369680bc388522504595447c25d9" @@ -4861,6 +4924,15 @@ standardized-audio-context@25.3.37: automation-events "^5.0.0" tslib "^2.4.1" +standardized-audio-context@^25.3.46: + version "25.3.46" + resolved "https://registry.yarnpkg.com/standardized-audio-context/-/standardized-audio-context-25.3.46.tgz#08e55d5305c2d3f614f90f19ad47c6686457ae68" + integrity sha512-kI7oM1IrGUawaBgCizRnVuS/+xSwRzwEDSqDkvJASAh+0IwuxUBYJFG4JSuaD6OkLQVg5i8oCf5aLOBX4dfVPw== + dependencies: + "@babel/runtime" "^7.21.5" + automation-events "^6.0.1" + tslib "^2.5.0" + string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" @@ -5091,6 +5163,11 @@ tslib@^2.4.0, tslib@^2.4.1: resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.1.tgz#0d0bfbaac2880b91e22df0768e55be9753a5b17e" integrity sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA== +tslib@^2.5.0: + version "2.5.0" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.0.tgz#42bfed86f5787aeb41d031866c8f402429e0fddf" + integrity sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg== + tsutils@^3.21.0: version "3.21.0" resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.21.0.tgz#b48717d394cea6c1e096983eed58e9d61715b623" @@ -5261,6 +5338,15 @@ v8-to-istanbul@^9.0.0: "@types/istanbul-lib-coverage" "^2.0.1" convert-source-map "^1.6.0" +vehicles@^9.0.1: + version "9.0.1" + resolved "https://registry.yarnpkg.com/vehicles/-/vehicles-9.0.1.tgz#54f6a6be4e37f6f0351550707a585671d79b279e" + integrity sha512-ENq0QowVueyf6KfmJlBqz/w739TvbnFqkzc3sKcqXBwHgZ/xvwca1f4P8AokdsHIrjYDIKD9FWd5U4Mec4HBPw== + dependencies: + "@babel/runtime" "^7.21.5" + decimal.js "^10.4.3" + tslib "^2.5.0" + vite-plugin-pwa@0.14.1: version "0.14.1" resolved "https://registry.yarnpkg.com/vite-plugin-pwa/-/vite-plugin-pwa-0.14.1.tgz#c32905d77916aab23e86522e2d4882c652f008d5"