From 280ad1ed9b3dc7a9558142586e34e8aecffb4172 Mon Sep 17 00:00:00 2001 From: Mohammad Bagher Abiat Date: Sun, 26 Mar 2023 11:35:12 +0330 Subject: [PATCH] fix: spy on popup apis like alert (#3076) Co-authored-by: Vladimir --- docs/guide/browser.md | 11 +- packages/browser/src/client/dialog.ts | 21 ++++ packages/browser/src/client/main.ts | 2 + pnpm-lock.yaml | 143 ++++++++++---------------- test/browser/specs/runner.test.mjs | 8 +- test/browser/test/dialog.test.ts | 15 +++ 6 files changed, 109 insertions(+), 91 deletions(-) create mode 100644 packages/browser/src/client/dialog.ts create mode 100644 test/browser/test/dialog.test.ts diff --git a/docs/guide/browser.md b/docs/guide/browser.md index a6aa55d68d29..154f2e288731 100644 --- a/docs/guide/browser.md +++ b/docs/guide/browser.md @@ -1,8 +1,8 @@ --- -title: Browser mode | Guide +title: Browser Mode | Guide --- -# Browser mode (experimental) +# Browser Mode (experimental) This page provides information about the experimental browser mode feature in the Vitest API, which allows you to run your tests in the browser natively, providing access to browser globals like window and document. This feature is currently under development, and APIs may change in the future. @@ -87,3 +87,10 @@ npx vitest --browser.name=chrome --browser.headless ``` In this case, Vitest will run in headless mode using the Chrome browser. + +## Limitations +### Thread Blocking Dialogs + +When using Vitest Browser, it's important to note that thread blocking dialogs like `alert` or `confirm` cannot be used natively. This is because they block the web page, which means Vitest cannot continue communicating with the page, causing the execution to hang. + +In such situations, Vitest provides default mocks with default returned values for these APIs. This ensures that if the user accidentally uses synchronous popup web APIs, the execution would not hang. However, it's still recommended for the user to mock these web APIs for better experience. Read more in [Mocking](/guide/mocking). diff --git a/packages/browser/src/client/dialog.ts b/packages/browser/src/client/dialog.ts new file mode 100644 index 000000000000..55fde3c1c4ef --- /dev/null +++ b/packages/browser/src/client/dialog.ts @@ -0,0 +1,21 @@ +const showPopupWarning = (name: string, value: T, defaultValue?: T) => (...params: any[]) => { + const formatedParams = params.map(p => JSON.stringify(p)).join(', ') + + console.warn(`Vitest encountered a \`${name}(${formatedParams})\` call that it cannot handle by default, so it returned \`${value}\`. Read more in https://vitest.dev/guide/browser#thread-blocking-dialogs. +If needed, mock the \`${name}\` call manually like: + +\`\`\` +import { expect, vi } from "vitest" + +vi.spyOn(window, "${name}")${defaultValue ? `.mockReturnValue(${JSON.stringify(defaultValue)})` : ''} +${name}(${formatedParams}) +expect(${name}).toHaveBeenCalledWith(${formatedParams}) +\`\`\``) + return value +} + +export const setupDialogsSpy = () => { + globalThis.alert = showPopupWarning('alert', undefined) + globalThis.confirm = showPopupWarning('confirm', false, true) + globalThis.prompt = showPopupWarning('prompt', null, 'your value') +} diff --git a/packages/browser/src/client/main.ts b/packages/browser/src/client/main.ts index 20d8140a732e..9633e46b07dc 100644 --- a/packages/browser/src/client/main.ts +++ b/packages/browser/src/client/main.ts @@ -7,6 +7,7 @@ import { BrowserSnapshotEnvironment } from './snapshot' import { importId } from './utils' import { setupConsoleLogSpy } from './logger' import { createSafeRpc, rpc, rpcDone } from './rpc' +import { setupDialogsSpy } from './dialog' // @ts-expect-error mocking some node apis globalThis.process = { env: {}, argv: [], cwd: () => '/', stdout: { write: () => {} }, nextTick: cb => cb() } @@ -71,6 +72,7 @@ ws.addEventListener('open', async () => { iFrame.setAttribute('src', '/__vitest__/') await setupConsoleLogSpy() + setupDialogsSpy() await runTests(paths, config) }) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3adc1d162c2f..7ffd84dab8d5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -240,7 +240,7 @@ importers: react-dom: 18.0.0_react@18.0.0 devDependencies: '@testing-library/react': 13.3.0_zpnidt7m3osuk7shl3s4oenomq - '@types/node': 18.15.3 + '@types/node': 18.15.7 '@types/react': 18.0.28 '@vitejs/plugin-react': 3.1.0 jsdom: 21.1.1 @@ -502,7 +502,7 @@ importers: vue: latest devDependencies: '@vitejs/plugin-vue': 4.1.0_vite@4.0.0+vue@3.2.47 - '@vue/test-utils': 2.3.1_vue@3.2.47 + '@vue/test-utils': 2.3.2_vue@3.2.47 jsdom: 21.1.1 vite: 4.0.0 vite-plugin-ruby: 3.1.2_vite@4.0.0 @@ -596,7 +596,7 @@ importers: devDependencies: '@vitejs/plugin-vue': 4.1.0_vite@4.0.0+vue@3.2.47 '@vitejs/plugin-vue-jsx': 3.0.1_vite@4.0.0+vue@3.2.47 - '@vue/test-utils': 2.3.1_vue@3.2.47 + '@vue/test-utils': 2.3.2_vue@3.2.47 jsdom: 21.1.1 vite: 4.0.0 vitest: link:../../packages/vitest @@ -1093,7 +1093,7 @@ importers: vue: latest devDependencies: '@vitejs/plugin-vue': 4.1.0_vite@4.0.0+vue@3.2.47 - '@vue/test-utils': 2.3.1_vue@3.2.47 + '@vue/test-utils': 2.3.2_vue@3.2.47 happy-dom: 8.9.0 vite: 4.0.0 vitest: link:../../packages/vitest @@ -1673,7 +1673,7 @@ packages: '@babel/parser': 7.20.7 '@babel/template': 7.20.7 '@babel/traverse': 7.20.12 - '@babel/types': 7.20.7 + '@babel/types': 7.21.3 convert-source-map: 1.9.0 debug: 4.3.4 gensync: 1.0.0-beta.2 @@ -1719,7 +1719,7 @@ packages: '@babel/parser': 7.20.7 '@babel/template': 7.20.7 '@babel/traverse': 7.20.12 - '@babel/types': 7.20.7 + '@babel/types': 7.21.3 convert-source-map: 1.9.0 debug: 4.3.4 gensync: 1.0.0-beta.2 @@ -1733,7 +1733,7 @@ packages: resolution: {integrity: sha512-CkPg8ySSPuHTYPJYo7IRALdqyjM9HCbt/3uOBEFbzyGVP6Mn8bwFPB0jX6982JVNBlYzM1nnPkfjuXSOPtQeEQ==} engines: {node: '>=6.9.0'} dependencies: - '@babel/types': 7.20.7 + '@babel/types': 7.21.3 '@jridgewell/gen-mapping': 0.3.2 jsesc: 2.5.2 @@ -1828,24 +1828,6 @@ packages: semver: 6.3.0 dev: true - /@babel/helper-create-class-features-plugin/7.20.5_@babel+core@7.20.12: - resolution: {integrity: sha512-3RCdA/EmEaikrhayahwToF0fpweU/8o2p8vhc1c/1kftHOdTKuC65kik/TLc+qfbS8JKw4qqJbne4ovICDhmww==} - engines: {node: '>=6.9.0'} - peerDependencies: - '@babel/core': ^7.0.0 - dependencies: - '@babel/core': 7.20.12 - '@babel/helper-annotate-as-pure': 7.18.6 - '@babel/helper-environment-visitor': 7.18.9 - '@babel/helper-function-name': 7.21.0 - '@babel/helper-member-expression-to-functions': 7.21.0 - '@babel/helper-optimise-call-expression': 7.18.6 - '@babel/helper-replace-supers': 7.20.7 - '@babel/helper-split-export-declaration': 7.18.6 - transitivePeerDependencies: - - supports-color - dev: true - /@babel/helper-create-class-features-plugin/7.21.0_@babel+core@7.18.13: resolution: {integrity: sha512-Q8wNiMIdwsv5la5SPxNYzzkPnjgC0Sy0i7jLkVOCdllu/xcVNkr3TeZzbHBJrj+XXRqzX5uCyCoV9eu6xUG7KQ==} engines: {node: '>=6.9.0'} @@ -1986,13 +1968,6 @@ packages: '@babel/types': 7.21.3 dev: true - /@babel/helper-function-name/7.19.0: - resolution: {integrity: sha512-WAwHBINyrpqywkUH0nTnNgI5ina5TFn85HKS0pbPDfxFfhyR/aNQEn4hGi1P1JyT//I0t4OgXUlofzWILRvS5w==} - engines: {node: '>=6.9.0'} - dependencies: - '@babel/template': 7.20.7 - '@babel/types': 7.21.3 - /@babel/helper-function-name/7.21.0: resolution: {integrity: sha512-HfK1aMRanKHpxemaY2gqBmL04iAPOPRj7DxtNbiDOrJK+gdwkiNRVpCpUJYbUT+aZyemKN8brqTOxzCaG6ExRg==} engines: {node: '>=6.9.0'} @@ -2037,7 +2012,7 @@ packages: '@babel/helper-validator-identifier': 7.19.1 '@babel/template': 7.20.7 '@babel/traverse': 7.20.12 - '@babel/types': 7.20.7 + '@babel/types': 7.21.3 transitivePeerDependencies: - supports-color @@ -2165,7 +2140,7 @@ packages: dependencies: '@babel/template': 7.20.7 '@babel/traverse': 7.20.12 - '@babel/types': 7.20.7 + '@babel/types': 7.21.3 transitivePeerDependencies: - supports-color @@ -2193,7 +2168,7 @@ packages: engines: {node: '>=6.0.0'} hasBin: true dependencies: - '@babel/types': 7.20.7 + '@babel/types': 7.21.3 /@babel/parser/7.20.7: resolution: {integrity: sha512-T3Z9oHybU+0vZlY9CiDSJQTD5ZapcW18ZctFMi0MOAl/4BjFF4ul7NVSARLdbGO5vDqy9eQiGTV0LtKfvCYvcg==} @@ -3727,7 +3702,7 @@ packages: '@babel/helper-module-imports': 7.18.6 '@babel/helper-plugin-utils': 7.20.2 '@babel/plugin-syntax-jsx': 7.18.6_@babel+core@7.18.13 - '@babel/types': 7.20.7 + '@babel/types': 7.21.3 dev: true /@babel/plugin-transform-react-jsx/7.19.0_@babel+core@7.18.13: @@ -3741,7 +3716,7 @@ packages: '@babel/helper-module-imports': 7.18.6 '@babel/helper-plugin-utils': 7.20.2 '@babel/plugin-syntax-jsx': 7.18.6_@babel+core@7.18.13 - '@babel/types': 7.20.7 + '@babel/types': 7.21.3 dev: true /@babel/plugin-transform-react-jsx/7.19.0_@babel+core@7.19.6: @@ -3755,7 +3730,7 @@ packages: '@babel/helper-module-imports': 7.18.6 '@babel/helper-plugin-utils': 7.20.2 '@babel/plugin-syntax-jsx': 7.18.6_@babel+core@7.19.6 - '@babel/types': 7.20.7 + '@babel/types': 7.21.3 dev: true /@babel/plugin-transform-react-jsx/7.19.0_@babel+core@7.20.12: @@ -3769,7 +3744,7 @@ packages: '@babel/helper-module-imports': 7.18.6 '@babel/helper-plugin-utils': 7.20.2 '@babel/plugin-syntax-jsx': 7.18.6_@babel+core@7.20.12 - '@babel/types': 7.20.7 + '@babel/types': 7.21.3 dev: true /@babel/plugin-transform-react-pure-annotations/7.18.6_@babel+core@7.18.13: @@ -3945,7 +3920,7 @@ packages: '@babel/core': ^7.0.0-0 dependencies: '@babel/core': 7.20.12 - '@babel/helper-create-class-features-plugin': 7.20.5_@babel+core@7.20.12 + '@babel/helper-create-class-features-plugin': 7.21.0_@babel+core@7.20.12 '@babel/helper-plugin-utils': 7.20.2 '@babel/plugin-syntax-typescript': 7.20.0_@babel+core@7.20.12 transitivePeerDependencies: @@ -4318,7 +4293,7 @@ packages: dependencies: '@babel/code-frame': 7.18.6 '@babel/parser': 7.20.7 - '@babel/types': 7.20.7 + '@babel/types': 7.21.3 /@babel/template/7.20.7: resolution: {integrity: sha512-8SegXApWe6VoNw0r9JHpSteLKTpTiLZ4rMlGIm9JQ18KiCtyQiAMEazujAHrUS5flrcqYZa75ukev3P6QmUwUw==} @@ -4335,11 +4310,11 @@ packages: '@babel/code-frame': 7.18.6 '@babel/generator': 7.20.7 '@babel/helper-environment-visitor': 7.18.9 - '@babel/helper-function-name': 7.19.0 + '@babel/helper-function-name': 7.21.0 '@babel/helper-hoist-variables': 7.18.6 '@babel/helper-split-export-declaration': 7.18.6 '@babel/parser': 7.20.7 - '@babel/types': 7.20.7 + '@babel/types': 7.21.3 debug: 4.3.4 globals: 11.12.0 transitivePeerDependencies: @@ -4370,14 +4345,6 @@ packages: '@babel/helper-validator-identifier': 7.19.1 to-fast-properties: 2.0.0 - /@babel/types/7.20.7: - resolution: {integrity: sha512-69OnhBxSSgK0OzTJai4kyPDiKTIe3j+ctaHdIGVbRahTLAT7L3R9oeXHC2aVSuGYt3cVnoAMDmOCgJ2yaiLMvg==} - engines: {node: '>=6.9.0'} - dependencies: - '@babel/helper-string-parser': 7.19.4 - '@babel/helper-validator-identifier': 7.19.1 - to-fast-properties: 2.0.0 - /@babel/types/7.21.3: resolution: {integrity: sha512-sBGdETxC+/M4o/zKC0sl6sjWv62WFR/uzxrJ6uYyMLZOUlPnwzw0tKgVHOXxaAd5l2g8pEDM5RZ495GPQI77kg==} engines: {node: '>=6.9.0'} @@ -5088,7 +5055,7 @@ packages: dependencies: '@types/istanbul-lib-coverage': 2.0.4 '@types/istanbul-reports': 3.0.1 - '@types/node': 18.15.3 + '@types/node': 18.15.7 '@types/yargs': 15.0.14 chalk: 4.1.2 dev: true @@ -5100,7 +5067,7 @@ packages: '@jest/schemas': 29.0.0 '@types/istanbul-lib-coverage': 2.0.4 '@types/istanbul-reports': 3.0.1 - '@types/node': 18.15.3 + '@types/node': 18.15.7 '@types/yargs': 17.0.12 chalk: 4.1.2 dev: true @@ -5612,7 +5579,7 @@ packages: engines: {node: '>=14'} hasBin: true dependencies: - '@types/node': 18.15.3 + '@types/node': 18.15.7 playwright-core: 1.28.0 dev: true @@ -6896,7 +6863,7 @@ packages: '@babel/generator': 7.20.7 '@babel/parser': 7.20.7 '@babel/preset-env': 7.18.10_@babel+core@7.18.13 - '@babel/types': 7.20.7 + '@babel/types': 7.21.3 '@mdx-js/mdx': 1.6.22 '@mdx-js/react': 1.6.22_react@17.0.2 '@types/lodash': 4.14.191 @@ -7450,7 +7417,7 @@ packages: /@types/cheerio/0.22.31: resolution: {integrity: sha512-Kt7Cdjjdi2XWSfrZ53v4Of0wG3ZcmaegFXjMmz9tfNrZSkzzo36G0AL1YqSdcIA78Etjt6E609pt5h1xnQkPUw==} dependencies: - '@types/node': 18.15.3 + '@types/node': 18.15.7 dev: true /@types/codemirror/5.60.6: @@ -7517,33 +7484,33 @@ packages: resolution: {integrity: sha512-zdV5odfHf95B4qr6bdpshG4VMm/3xgnPhSJLa3xh75CYr35e34k+4FQli82Q48sPqwHazJGy+6+jl4T+Vw1AMg==} dependencies: '@types/jsonfile': 6.1.1 - '@types/node': 18.15.3 + '@types/node': 18.15.7 dev: true /@types/fs-extra/9.0.13: resolution: {integrity: sha512-nEnwB++1u5lVDM2UI4c1+5R+FYaKfaAzS4OococimjVm3nQw3TuzH5UNsocrcTBbhnerblyHj4A49qXbIiZdpA==} dependencies: - '@types/node': 18.15.3 + '@types/node': 18.15.7 dev: true /@types/glob/7.2.0: resolution: {integrity: sha512-ZUxbzKl0IfJILTS6t7ip5fQQM/J3TJYubDm3nMbgubNNYS62eXeUpoLUC8/7fJNiFYHTrGPQn7hspDUzIHX3UA==} dependencies: '@types/minimatch': 5.1.1 - '@types/node': 18.15.3 + '@types/node': 18.15.7 dev: true /@types/glob/8.0.0: resolution: {integrity: sha512-l6NQsDDyQUVeoTynNpC9uRvCUint/gSUXQA2euwmTuWGvPY5LSDUu6tkCtJB2SvGQlJQzLaKqcGZP4//7EDveA==} dependencies: '@types/minimatch': 5.1.1 - '@types/node': 18.15.3 + '@types/node': 18.15.7 dev: true /@types/graceful-fs/4.1.5: resolution: {integrity: sha512-anKkLmZZ+xm4p8JWBf4hElkM4XR+EZeA2M9BAkkTldmcyDY4mbdIJnRghDJH3Ov5ooY7/UAoENtmdMSkaAd7Cw==} dependencies: - '@types/node': 18.15.3 + '@types/node': 18.15.7 dev: true /@types/hast/2.3.4: @@ -7608,7 +7575,7 @@ packages: /@types/jsdom/21.1.0: resolution: {integrity: sha512-leWreJOdnuIxq9Y70tBVm/bvTuh31DSlF/r4l7Cfi4uhVQqLHD0Q4v301GMisEMwwbMgF7ZKxuZ+Jbd4NcdmRw==} dependencies: - '@types/node': 18.15.3 + '@types/node': 18.15.7 '@types/tough-cookie': 4.0.2 parse5: 7.1.1 dev: true @@ -7624,7 +7591,7 @@ packages: /@types/jsonfile/6.1.1: resolution: {integrity: sha512-GSgiRCVeapDN+3pqA35IkQwasaCh/0YFH5dEF6S88iDvEn901DjOeH3/QPY+XYP1DFzDZPvIvfeEgk+7br5png==} dependencies: - '@types/node': 18.15.3 + '@types/node': 18.15.7 dev: true /@types/lodash/4.14.191: @@ -7658,7 +7625,7 @@ packages: /@types/node-fetch/2.6.2: resolution: {integrity: sha512-DHqhlq5jeESLy19TYhLakJ07kNumXWjcDdxXsLUMJZ6ue8VZJj4kLPQVE/2mdHh3xZziNF1xppu5lwmS53HR+A==} dependencies: - '@types/node': 18.15.3 + '@types/node': 18.15.7 form-data: 3.0.1 dev: true @@ -7674,8 +7641,8 @@ packages: resolution: {integrity: sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==} dev: true - /@types/node/18.15.3: - resolution: {integrity: sha512-p6ua9zBxz5otCmbpb5D3U4B5Nanw6Pk3PPyX05xnxbB/fRv71N7CPmORg7uAD5P70T0xmx1pzAx/FUfa5X+3cw==} + /@types/node/18.15.7: + resolution: {integrity: sha512-LFmUbFunqmBn26wJZgZPYZPrDR1RwGOu2v79Mgcka1ndO6V0/cwjivPTc4yoK6n9kmw4/ls1r8cLrvh2iMibFA==} dev: true /@types/node/18.7.13: @@ -7708,7 +7675,7 @@ packages: /@types/prompts/2.4.2: resolution: {integrity: sha512-TwNx7qsjvRIUv/BCx583tqF5IINEVjCNqg9ofKHRlSoUHE62WBHrem4B1HGXcIrG511v29d1kJ9a/t2Esz7MIg==} dependencies: - '@types/node': 18.15.3 + '@types/node': 18.15.7 kleur: 3.0.3 dev: true @@ -7781,7 +7748,7 @@ packages: /@types/resolve/1.17.1: resolution: {integrity: sha512-yy7HuzQhj0dhGpD8RLXSZWEkLsV9ibvxvi6EiJ3bkqLAO1RGo0WbkWQiwpRlSFymTJRz0d3k5LM3kkx8ArDbLw==} dependencies: - '@types/node': 18.15.3 + '@types/node': 18.15.7 dev: true /@types/resolve/1.20.2: @@ -7798,7 +7765,7 @@ packages: /@types/set-cookie-parser/2.4.2: resolution: {integrity: sha512-fBZgytwhYAUkj/jC/FAV4RQ5EerRup1YQsXQCh8rZfiHkc4UahC192oH0smGwsXol3cL3A5oETuAHeQHmhXM4w==} dependencies: - '@types/node': 18.15.3 + '@types/node': 18.15.7 dev: true /@types/sinonjs__fake-timers/8.1.1: @@ -7872,7 +7839,7 @@ packages: /@types/webpack-sources/3.2.0: resolution: {integrity: sha512-Ft7YH3lEVRQ6ls8k4Ff1oB4jN6oy/XmU6tQISKdhfh+1mR+viZFphS6WL0IrtDOzvefmJg5a0s7ZQoRXwqTEFg==} dependencies: - '@types/node': 18.15.3 + '@types/node': 18.15.7 '@types/source-list-map': 0.1.2 source-map: 0.7.4 dev: true @@ -7880,7 +7847,7 @@ packages: /@types/webpack/4.41.32: resolution: {integrity: sha512-cb+0ioil/7oz5//7tZUSwbrSAN/NWHrQylz5cW8G0dWTcF/g+/dSdMlKVZspBYuMAN1+WnwHrkxiRrLcwd0Heg==} dependencies: - '@types/node': 18.15.3 + '@types/node': 18.15.7 '@types/tapable': 1.0.8 '@types/uglify-js': 3.17.0 '@types/webpack-sources': 3.2.0 @@ -7895,7 +7862,7 @@ packages: /@types/ws/8.5.4: resolution: {integrity: sha512-zdQDHKUgcX/zBc4GrwsE/7dVdAD8JR4EuiAXiiUhhfyIJXXb2+PrGshFyeXWQPMmmZ2XxgaqclgpIC7eTXc1mg==} dependencies: - '@types/node': 18.15.3 + '@types/node': 18.15.7 dev: true /@types/yargs-parser/21.0.0: @@ -7918,7 +7885,7 @@ packages: resolution: {integrity: sha512-Cn6WYCm0tXv8p6k+A8PvbDG763EDpBoTzHdA+Q/MF6H3sapGjCm9NzoaJncJS9tUKSuCoDs9XHxYYsQDgxR6kw==} requiresBuild: true dependencies: - '@types/node': 18.15.3 + '@types/node': 18.15.7 dev: true optional: true @@ -8752,8 +8719,8 @@ packages: vue: 3.2.47 dev: true - /@vue/test-utils/2.3.1_vue@3.2.47: - resolution: {integrity: sha512-tRtHRPEETQSUrqXgAewNZHm5iypxDFxwenfdcvMRm1kbGo4bcqHb1XHHlsaIjoDbLkuE2NYiF8vBQDNYrzlrSA==} + /@vue/test-utils/2.3.2_vue@3.2.47: + resolution: {integrity: sha512-hJnVaYhbrIm0yBS0+e1Y0Sj85cMyAi+PAbK4JHqMRUZ6S622Goa+G7QzkRSyvCteG8wop7tipuEbHoZo26wsSA==} peerDependencies: vue: ^3.0.1 dependencies: @@ -8920,14 +8887,14 @@ packages: resolution: {integrity: sha512-96G4TzbYnRf95+GURo15FYt6iTYq85nbWU6YQedLRAV15RfSp4foKTbAnq++bKKMALNL6gdzTc+HGhQr3Q0sQg==} engines: {node: ^16.13 || >=18} dependencies: - '@types/node': 18.15.3 + '@types/node': 18.15.7 dev: true /@wdio/types/8.4.0: resolution: {integrity: sha512-1eA0D0jS8Ttg67zB2gsZJFUcHcRz4VRjLTjxdLKh70+ZfB1+YZr9tScLgQjc+qsjsK1wKSzOz03uZiidwNnN9g==} engines: {node: ^16.13 || >=18} dependencies: - '@types/node': 18.15.3 + '@types/node': 18.15.7 dev: true /@wdio/utils/8.6.1: @@ -10806,7 +10773,7 @@ packages: engines: {node: '>=12.13.0'} hasBin: true dependencies: - '@types/node': 18.15.3 + '@types/node': 18.15.7 escape-string-regexp: 4.0.0 is-wsl: 2.2.0 lighthouse-logger: 1.3.0 @@ -11999,7 +11966,7 @@ packages: resolution: {integrity: sha512-dqR5SUsqpJBkY+SpzSPyRwAdwn3PdoCFjgaRqO2jkF0IXgvBkKsXSepAN2QV4/nbcFXB6mokJZ0rlHSzVl7GkQ==} engines: {node: ^16.13 || >=18} dependencies: - '@types/node': 18.15.3 + '@types/node': 18.15.7 '@wdio/config': 8.6.2 '@wdio/logger': 8.1.0 '@wdio/protocols': 8.5.7 @@ -15364,7 +15331,7 @@ packages: dependencies: '@jest/types': 26.6.2 '@types/graceful-fs': 4.1.5 - '@types/node': 18.15.3 + '@types/node': 18.15.7 anymatch: 3.1.2 fb-watchman: 2.0.1 graceful-fs: 4.2.10 @@ -15432,7 +15399,7 @@ packages: resolution: {integrity: sha512-S5wqyz0DXnNJPd/xfIzZ5Xnp1HrJWBczg8mMfMpN78OJ5eDxXyf+Ygld9wX1DnUWbIbhM1YDY95NjR4CBXkb2g==} engines: {node: '>= 10.14.2'} dependencies: - '@types/node': 18.15.3 + '@types/node': 18.15.7 graceful-fs: 4.2.10 dev: true @@ -15441,7 +15408,7 @@ packages: engines: {node: '>= 10.14.2'} dependencies: '@jest/types': 26.6.2 - '@types/node': 18.15.3 + '@types/node': 18.15.7 chalk: 4.1.2 graceful-fs: 4.2.10 is-ci: 2.0.0 @@ -15453,7 +15420,7 @@ packages: engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} dependencies: '@jest/types': 29.0.1 - '@types/node': 18.15.3 + '@types/node': 18.15.7 chalk: 4.1.2 ci-info: 3.7.0 graceful-fs: 4.2.10 @@ -15464,7 +15431,7 @@ packages: resolution: {integrity: sha512-KWYVV1c4i+jbMpaBC+U++4Va0cp8OisU185o73T1vo99hqi7w8tSJfUXYswwqqrjzwxa6KpRK54WhPvwf5w6PQ==} engines: {node: '>= 10.13.0'} dependencies: - '@types/node': 18.15.3 + '@types/node': 18.15.7 merge-stream: 2.0.0 supports-color: 7.2.0 dev: true @@ -15473,7 +15440,7 @@ packages: resolution: {integrity: sha512-7vuh85V5cdDofPyxn58nrPjBktZo0u9x1g8WtjQol+jZDaE+fhN+cIvTj11GndBnMnyfrUOG1sZQxCdjKh+DKg==} engines: {node: '>= 10.13.0'} dependencies: - '@types/node': 18.15.3 + '@types/node': 18.15.7 merge-stream: 2.0.0 supports-color: 8.1.1 dev: true @@ -19897,7 +19864,7 @@ packages: dependencies: '@babel/generator': 7.20.7 '@babel/helper-module-imports': 7.18.6 - '@babel/types': 7.20.7 + '@babel/types': 7.21.3 solid-js: 1.5.2 dev: true @@ -22259,7 +22226,7 @@ packages: resolution: {integrity: sha512-jgnu/hB7O8hrjCZm6zW77QhBEdwteQF+liWvjZcflQXUmS/YLdS/UAfCBQzt1CIUHfbGrlxHshwFm+ywjT9XJw==} engines: {node: ^16.13 || >=18} dependencies: - '@types/node': 18.15.3 + '@types/node': 18.15.7 '@types/ws': 8.5.4 '@wdio/config': 8.6.2 '@wdio/logger': 8.1.0 @@ -22279,7 +22246,7 @@ packages: resolution: {integrity: sha512-XhS6lydSyCLnJcOBhLbSK6J0MQdfnSXaFcSvSEL10TMBnWcmETCfYIj7OX41weDI8F4YAasYyMH+mJUkWwC1Ww==} engines: {node: ^16.13 || >=18} dependencies: - '@types/node': 18.15.3 + '@types/node': 18.15.7 '@wdio/config': 8.6.2 '@wdio/logger': 8.1.0 '@wdio/protocols': 8.5.7 diff --git a/test/browser/specs/runner.test.mjs b/test/browser/specs/runner.test.mjs index 8c87292227b2..bf076a918df1 100644 --- a/test/browser/specs/runner.test.mjs +++ b/test/browser/specs/runner.test.mjs @@ -17,7 +17,7 @@ test('tests are actually running', async () => { const browserResult = await readFile('./browser.json', 'utf-8') const browserResultJson = JSON.parse(browserResult) - assert.ok(browserResultJson.testResults.length === 5, 'Not all the tests have been run') + assert.ok(browserResultJson.testResults.length === 6, 'Not all the tests have been run') for (const result of browserResultJson.testResults) assert.ok(result.status === 'passed', `${result.name} has failed`) @@ -49,3 +49,9 @@ test('logs are redirected to stderr', async () => { assert.match(stderr, /Timer "invalid timeLog" does not exist/, 'prints errored timeLog') assert.match(stderr, /Timer "invalid timeEnd" does not exist/, 'prints errored timeEnd') }) + +test('popup apis should log a warning', () => { + assert.ok(stderr.includes('Vitest encountered a \`alert\("test"\)\`'), 'prints warning for alert') + assert.ok(stderr.includes('Vitest encountered a \`confirm\("test"\)\`'), 'prints warning for confirm') + assert.ok(stderr.includes('Vitest encountered a \`prompt\("test"\)\`'), 'prints warning for prompt') +}) diff --git a/test/browser/test/dialog.test.ts b/test/browser/test/dialog.test.ts new file mode 100644 index 000000000000..05f0476808b6 --- /dev/null +++ b/test/browser/test/dialog.test.ts @@ -0,0 +1,15 @@ +/* eslint-disable no-alert */ + +import { expect, it } from 'vitest' + +it('alert', async () => { + expect(alert('test')).toBeUndefined() +}) + +it('prompt', async () => { + expect(prompt('test')).toBeNull() +}) + +it('confirm', async () => { + expect(confirm('test')).toBe(false) +})