Skip to content

Commit 6da1135

Browse files
committed
minor #2146 Upgrade Vitest, use a real browser for Map Bridges tests (Kocal)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- Upgrade Vitest, use a real browser for Map Bridges tests | Q | A | ------------- | --- | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Issues | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT <!-- Replace this notice by a description of your feature/bugfix. This will help reviewers and should be a good start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - For new features, provide some code snippets to help understand usage. - Features and deprecations must be submitted against branch main. - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry - Never break backward compatibility (see https://symfony.com/bc). --> Follow #2138 (comment). It looks like Google Maps changed a bit their implementation and now manipulates [`SVGImageElement`](developer.mozilla.org/en-us/docs/web/api/svgimageelement) and [`SVGAnimatedString`](https://developer.mozilla.org/en-US/docs/Web/API/SVGAnimatedString): <img width="1559" alt="image" src="https://github.com/user-attachments/assets/3d82559d-500a-45fa-9730-1a1ccd3adde8"> But, this API is not supported by https://github.com/capricorn86/happy-dom. Instead of reimplementing things ourselves, I think it's more clever to use a **real browser** (here Chromium) through [Playwright](playwright.dev/), when using [Vitest's Browser mode](https://vitest.dev/guide/browser/). This PR also upgrade Vitest from ^0.34 to ^2.0, and Vite from 4.5.0 to 5.4.3, which comes with https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated (that I fixed in a second commit) Commits ------- eaab0f6 chore: rename vitest.config.js to vitest.config.mjs, to get rid of https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated cebd8e2 Upgrade Vitest, use a real browser for Map Bridges tests
2 parents f8a2a8c + eaab0f6 commit 6da1135

File tree

15 files changed

+894
-434
lines changed

15 files changed

+894
-434
lines changed

.github/workflows/test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,5 @@ jobs:
141141
restore-keys: |
142142
${{ runner.os }}-yarn-
143143
- run: yarn --immutable
144+
- run: yarn playwright install
144145
- run: yarn test

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
"@rollup/plugin-node-resolve": "^15.2.3",
2020
"@rollup/plugin-typescript": "^11.1.6",
2121
"@symfony/stimulus-testing": "^2.0.1",
22+
"@vitest/browser": "^2.0.5",
2223
"clean-css-cli": "^5.6.2",
24+
"playwright": "^1.47.0",
2325
"rollup": "^4.21.0",
2426
"tslib": "^2.6.3",
2527
"typescript": "^5.5.4",
26-
"vitest": "^0.34.6"
28+
"vitest": "^2.0.5"
2729
}
2830
}

src/Chartjs/assets/vitest.config.js renamed to src/Chartjs/assets/vitest.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { defineConfig, mergeConfig } from 'vitest/config';
2-
import configShared from '../../../vitest.config.js'
2+
import configShared from '../../../vitest.config.mjs'
33
import path from 'path';
44

55
export default mergeConfig(

src/Map/src/Bridge/Google/assets/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"devDependencies": {
3434
"@googlemaps/js-api-loader": "^1.16.6",
3535
"@hotwired/stimulus": "^3.0.0",
36-
"@types/google.maps": "^3.55.9",
37-
"happy-dom": "^14.12.3"
36+
"@types/google.maps": "^3.55.9"
3837
}
3938
}

src/Map/src/Bridge/Google/assets/vitest.config.js

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { defineConfig, mergeConfig } from 'vitest/config';
2+
import configShared from '../../../../../../vitest.config.mjs'
3+
4+
export default mergeConfig(
5+
configShared,
6+
defineConfig({
7+
resolve: {
8+
alias: {
9+
'@symfony/ux-map/abstract-map-controller': __dirname + '/../../../../assets/src/abstract_map_controller.ts',
10+
},
11+
},
12+
define: {
13+
// Prevent the following error:
14+
// ReferenceError: global is not defined
15+
// ❯ ../../../../../../node_modules/pretty-format/build/plugins/AsymmetricMatcher.js ../../../../../../../../../../node_modules/.vite/deps/@testing-library_dom.js:139:19
16+
// ❯ ../../../../../../node_modules/pretty-format/build/index.js ../../../../../../../../../../node_modules/.vite/deps/@testing-library_dom.js:805:7
17+
// ❯ ../../../../../../../../../../node_modules/.vite/deps/@testing-library_dom.js:13445:36
18+
global: {}
19+
},
20+
test: {
21+
browser: {
22+
enabled: true,
23+
provider: 'playwright', // or 'webdriverio'
24+
name: 'chromium', // browser name is required
25+
headless: true,
26+
},
27+
},
28+
})
29+
);

src/Map/src/Bridge/Leaflet/assets/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"devDependencies": {
3434
"@hotwired/stimulus": "^3.0.0",
3535
"@types/leaflet": "^1.9.12",
36-
"happy-dom": "^14.12.3",
3736
"leaflet": "^1.9.4"
3837
}
3938
}

src/Map/src/Bridge/Leaflet/assets/vitest.config.js

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { defineConfig, mergeConfig } from 'vitest/config';
2+
import configShared from '../../../../../../vitest.config.mjs'
3+
4+
export default mergeConfig(
5+
configShared,
6+
defineConfig({
7+
resolve: {
8+
alias: {
9+
'@symfony/ux-map/abstract-map-controller': __dirname + '/../../../../assets/src/abstract_map_controller.ts',
10+
'leaflet/dist/leaflet.min.css': 'leaflet/dist/leaflet.css',
11+
},
12+
},
13+
define: {
14+
// Prevent the following error:
15+
// ReferenceError: global is not defined
16+
// ❯ ../../../../../../node_modules/pretty-format/build/plugins/AsymmetricMatcher.js ../../../../../../../../../../node_modules/.vite/deps/@testing-library_dom.js:139:19
17+
// ❯ ../../../../../../node_modules/pretty-format/build/index.js ../../../../../../../../../../node_modules/.vite/deps/@testing-library_dom.js:805:7
18+
// ❯ ../../../../../../../../../../node_modules/.vite/deps/@testing-library_dom.js:13445:36
19+
global: {}
20+
},
21+
test: {
22+
browser: {
23+
enabled: true,
24+
provider: 'playwright', // or 'webdriverio'
25+
name: 'chromium', // browser name is required
26+
headless: true,
27+
},
28+
},
29+
})
30+
);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// vitest.config.ts
22
import { defineConfig, mergeConfig } from 'vitest/config';
33
import react from '@vitejs/plugin-react';
4-
import configShared from '../../../vitest.config.js'
4+
import configShared from '../../../vitest.config.mjs'
55

66
export default mergeConfig(
77
configShared,
88
defineConfig({
99
plugins: [react()],
1010
})
11-
);
11+
);

0 commit comments

Comments
 (0)