@dargmuesli/nuxt-vio-testing 20.6.2 → 20.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,64 @@
1
+ import { type Page, test, expect } from '@playwright/test'
2
+
3
+ const createDefaultPage = (page: Page) => {
4
+ return {
5
+ page,
6
+ goto: async (
7
+ url: string,
8
+ options?: {
9
+ cookieControl?: boolean
10
+ isLoading?: boolean
11
+ },
12
+ ) => {
13
+ await page.goto(url)
14
+
15
+ // if (!options || options.cookieControl !== false) {
16
+ // await expect(
17
+ // page.getByRole('button', { name: 'Cookie control' }),
18
+ // ).toBeVisible()
19
+ // }
20
+
21
+ if (!options || options.isLoading !== false) {
22
+ await expect(page.getByTestId('is-loading')).toHaveAttribute(
23
+ 'data-is-loading',
24
+ 'false',
25
+ )
26
+ }
27
+ },
28
+ }
29
+ }
30
+
31
+ export const vioTest = test.extend<{
32
+ defaultPage: ReturnType<typeof createDefaultPage>
33
+ _autoSnapshotSuffix: unknown
34
+ }>({
35
+ defaultPage: async ({ page, context }, use) => {
36
+ await context.addCookies([
37
+ {
38
+ domain: 'localhost',
39
+ name: 'vio_is-testing',
40
+ path: '/',
41
+ value: 'true',
42
+ },
43
+ {
44
+ domain: 'localhost',
45
+ name: 'vio_tz',
46
+ path: '/',
47
+ value: 'Europe/Berlin',
48
+ },
49
+ {
50
+ domain: 'localhost',
51
+ name: 'ncc_c',
52
+ path: '/',
53
+ value: 'ctga',
54
+ },
55
+ ])
56
+
57
+ const defaultPage = createDefaultPage(page)
58
+
59
+ await use(defaultPage)
60
+
61
+ // After use a cleanup function could be run for data that has been created for the test
62
+ // await cleanup()
63
+ },
64
+ })
@@ -1,7 +1,6 @@
1
1
  import { expect } from '@playwright/test'
2
2
  import type { Page } from 'playwright-core'
3
3
 
4
- export const COOKIE_CONTROL_CONSENT_COOKIE_DEFAULT = 'ctga'
5
4
  export const TIMEOUT = 60000
6
5
  export const PAGE_READY = async ({
7
6
  page,
@@ -1,7 +1,35 @@
1
+ import AxeBuilder from '@axe-core/playwright'
1
2
  import { expect, type Page } from '@playwright/test'
2
3
  import { joinURL, withoutTrailingSlash } from 'ufo'
3
4
 
4
- import { SITE_URL } from '#tests/e2e/utils/constants'
5
+ // the following imports cannot use the #tests alias because downstream consumers of this package typically cannot resolve that alias
6
+ import { vioTest } from '../fixtures/vioTest'
7
+ import { SITE_URL, TIMEOUT } from '../utils/constants'
8
+
9
+ export const testA11y = (url: string) =>
10
+ vioTest.describe('a11y', () => {
11
+ vioTest(
12
+ 'should not have any automatically detectable accessibility issues',
13
+ async ({ defaultPage }) => {
14
+ await defaultPage.goto(url)
15
+
16
+ const accessibilityScanResults = await new AxeBuilder({
17
+ page: defaultPage.page,
18
+ }).analyze()
19
+
20
+ expect(
21
+ accessibilityScanResults.violations
22
+ .map(
23
+ (x) =>
24
+ `${x.id}\n${x.nodes.map(
25
+ (y) => `${y.failureSummary}\n(${y.html}\n(${y.target})`,
26
+ )}`,
27
+ )
28
+ .join('\n'),
29
+ ).toEqual('')
30
+ },
31
+ )
32
+ })
5
33
 
6
34
  export const testMetadata = async ({
7
35
  page,
@@ -512,3 +540,45 @@ export const testMetadata = async ({
512
540
  // ).toMatchSnapshot(`content-security-policy.txt`)
513
541
  // }
514
542
  }
543
+
544
+ export const testOgImage = (url: string) =>
545
+ vioTest.describe('visual regression', () => {
546
+ vioTest('generates the open graph image', async ({ page }) => {
547
+ await page.goto(
548
+ joinURL(
549
+ `/__og-image__/${process.env.VIO_SERVER === 'static' ? 'static' : 'image'}${url}/og.png`,
550
+ ),
551
+ )
552
+ await expect(page).toHaveScreenshot()
553
+
554
+ await page.goto(
555
+ joinURL(
556
+ `/__og-image__/${process.env.VIO_SERVER === 'static' ? 'static' : 'image'}/de${url}/og.png`,
557
+ ),
558
+ )
559
+ await expect(page).toHaveScreenshot()
560
+ })
561
+ })
562
+
563
+ export const testPageLoad = (url: string, status = 200) =>
564
+ vioTest.describe('page load', () => {
565
+ vioTest('loads the page successfully', async ({ request }) => {
566
+ const resp = await request.get(url, {
567
+ headers: {
568
+ Cookie: 'vio_is-testing=true',
569
+ },
570
+ })
571
+ expect(resp.status()).toBe(status)
572
+ })
573
+ })
574
+
575
+ export const testVisualRegression = (url: string, plain?: boolean) =>
576
+ vioTest.describe('visual regression', () => {
577
+ vioTest('looks as before', async ({ defaultPage, page }) => {
578
+ await (plain ? page : defaultPage).goto(url)
579
+
580
+ await expect(plain ? page : defaultPage.page).toHaveScreenshot({
581
+ timeout: TIMEOUT,
582
+ })
583
+ })
584
+ })
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "@axe-core/playwright": "4.11.1",
4
4
  "@eslint/js": "9.39.2",
5
5
  "@playwright/test": "1.58.2",
6
- "@types/node": "24.10.11",
6
+ "@types/node": "24.10.12",
7
7
  "cross-env": "10.1.0",
8
8
  "eslint": "9.39.2",
9
9
  "eslint-config-prettier": "10.1.8",
@@ -54,5 +54,5 @@
54
54
  "test:e2e:server:static": "cross-env NODE_ENV=production PORT=3002 NUXT_PUBLIC_SITE_URL=https://localhost:3002 VIO_SERVER=static pnpm run test:e2e"
55
55
  },
56
56
  "type": "module",
57
- "version": "20.6.2"
57
+ "version": "20.6.4"
58
58
  }
@@ -1,7 +1,6 @@
1
1
  import { defineConfig, devices } from '@playwright/test'
2
2
 
3
- import { SITE_URL } from '#src/node/static'
4
- import { TIMEOUT } from '#tests/e2e/utils/constants'
3
+ import { SITE_URL, TIMEOUT } from '#tests/e2e/utils/constants' // importing from `src` does not work with the test module release
5
4
 
6
5
  /**
7
6
  * Read environment variables from file.
package/tsconfig.json CHANGED
@@ -3,8 +3,6 @@
3
3
  "module": "ESNext",
4
4
  "moduleResolution": "Bundler",
5
5
  "paths": {
6
- "~/*": ["../src/*"],
7
- "#src/*": ["../src/*"],
8
6
  "#tests/*": ["./*"]
9
7
  },
10
8
  "target": "ESNext",