nuxt-spec 0.3.3 → 0.3.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.
@@ -1,33 +1,33 @@
1
- const messageFilters = [
2
- // Node+Windows false positive
3
- // https://github.com/nuxt/icon/issues/140
4
- 'Use of deprecated trailing slash pattern mapping',
5
- // remove once Vue stops considering <Suspense> experimental
6
- '<Suspense> is an experimental feature',
7
- // merge defaults with user-defined filters from NUXT_SPEC_MESSAGE_FILTERS env variable
8
- ...(process.env.NUXT_SPEC_MESSAGE_FILTERS
9
- ? process.env.NUXT_SPEC_MESSAGE_FILTERS.split(',')
10
- : []),
11
- ]
12
-
13
- // 1) filter-out unnecessary stderr/stdout logs coming from Vitest
14
- // (applied as side-effect on import)
15
-
16
- const _stderrWrite = process.stderr.write.bind(process.stderr)
17
- process.stderr.write = (chunk, ...args) => {
18
- if (typeof chunk === 'string' && messageFilters.some(f => chunk.includes(f))) return true
19
- return _stderrWrite(chunk, ...args)
20
- }
21
-
22
- const _stdoutWrite = process.stdout.write.bind(process.stdout)
23
- process.stdout.write = (chunk, ...args) => {
24
- if (typeof chunk === 'string' && messageFilters.some(f => chunk.includes(f))) return true
25
- return _stdoutWrite(chunk, ...args)
26
- }
27
-
28
- // 2) filter-out unnecessary console logs coming from Vitest
29
- // (used as Vitest onConsoleLog hook)
30
-
31
- export function onConsoleLog(log) {
32
- if (messageFilters.some(f => log.includes(f))) return false
33
- }
1
+ const messageFilters = [
2
+ // Node+Windows false positive
3
+ // https://github.com/nuxt/icon/issues/140
4
+ 'Use of deprecated trailing slash pattern mapping',
5
+ // remove once Vue stops considering <Suspense> experimental
6
+ '<Suspense> is an experimental feature',
7
+ // merge defaults with user-defined filters from NUXT_SPEC_MESSAGE_FILTERS env variable
8
+ ...(process.env.NUXT_SPEC_MESSAGE_FILTERS
9
+ ? process.env.NUXT_SPEC_MESSAGE_FILTERS.split(',')
10
+ : []),
11
+ ]
12
+
13
+ // 1) filter-out unnecessary stderr/stdout logs coming from Vitest
14
+ // (applied as side-effect on import)
15
+
16
+ const _stderrWrite = process.stderr.write.bind(process.stderr)
17
+ process.stderr.write = (chunk, ...args) => {
18
+ if (typeof chunk === 'string' && messageFilters.some(f => chunk.includes(f))) return true
19
+ return _stderrWrite(chunk, ...args)
20
+ }
21
+
22
+ const _stdoutWrite = process.stdout.write.bind(process.stdout)
23
+ process.stdout.write = (chunk, ...args) => {
24
+ if (typeof chunk === 'string' && messageFilters.some(f => chunk.includes(f))) return true
25
+ return _stdoutWrite(chunk, ...args)
26
+ }
27
+
28
+ // 2) filter-out unnecessary console logs coming from Vitest
29
+ // (used as Vitest onConsoleLog hook)
30
+
31
+ export function onConsoleLog(log) {
32
+ if (messageFilters.some(f => log.includes(f))) return false
33
+ }
package/nuxt.config.ts CHANGED
@@ -1,24 +1,24 @@
1
- // @nuxt/hints module is included by default
2
- // set NUXT_SPEC_HINTS_ENABLED=false to exclude it
3
- const hintsEnabled = process.env.NUXT_SPEC_HINTS_ENABLED !== 'false'
4
-
5
- export default defineNuxtConfig({
6
- modules: [
7
- '@nuxt/eslint',
8
- '@nuxt/test-utils/module',
9
- ...(hintsEnabled ? ['@nuxt/hints'] : []),
10
- ],
11
-
12
- // exclude file used for explicit exports (nuxt-spec/components) from Nuxt resolution
13
- components: {
14
- dirs: [{ path: '~/components', ignore: ['index.ts'] }],
15
- },
16
-
17
- compatibilityDate: '2026-08-08',
18
-
19
- eslint: {
20
- config: {
21
- stylistic: true,
22
- },
23
- },
24
- })
1
+ // @nuxt/hints module is included by default
2
+ // set NUXT_SPEC_HINTS_ENABLED=false to exclude it
3
+ const hintsEnabled = process.env.NUXT_SPEC_HINTS_ENABLED !== 'false'
4
+
5
+ export default defineNuxtConfig({
6
+ modules: [
7
+ '@nuxt/eslint',
8
+ '@nuxt/test-utils/module',
9
+ ...(hintsEnabled ? ['@nuxt/hints'] : []),
10
+ ],
11
+
12
+ // exclude file used for explicit exports (nuxt-spec/components) from Nuxt resolution
13
+ components: {
14
+ dirs: [{ path: '~/components', ignore: ['index.ts'] }],
15
+ },
16
+
17
+ compatibilityDate: '2026-08-08',
18
+
19
+ eslint: {
20
+ config: {
21
+ stylistic: true,
22
+ },
23
+ },
24
+ })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-spec",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "Test-pack layer for Nuxt Applications",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,20 +9,6 @@
9
9
  "license": "MIT",
10
10
  "type": "module",
11
11
  "main": "./nuxt.config.ts",
12
- "scripts": {
13
- "analyze": "nuxt analyze",
14
- "eslint": "eslint .",
15
- "typecheck": "nuxi typecheck",
16
- "build": "nuxt build",
17
- "dev": "nuxt dev",
18
- "generate": "nuxt generate",
19
- "prepublishOnly": "node bin/prepublish-check.js",
20
- "preview": "nuxt preview",
21
- "start": "nuxt start",
22
- "test": "vitest run",
23
- "test-u": "vitest run -u",
24
- "test-i": "vitest"
25
- },
26
12
  "bin": {
27
13
  "nuxt-spec": "bin/cli.js"
28
14
  },
@@ -62,16 +48,30 @@
62
48
  "@vue/test-utils": "2.5.0",
63
49
  "elrh-cosca": "0.3.6",
64
50
  "fast-png": "~8.0.0",
65
- "happy-dom": "~20.12.0",
51
+ "h3-next": "npm:h3@~2.0.1-rc.31",
52
+ "happy-dom": "~20.14.0",
66
53
  "nuxt": "4.5.2",
67
54
  "pixelmatch": "~7.2.0",
55
+ "playwright": "~1.62.1",
68
56
  "playwright-core": "~1.62.1",
69
57
  "typescript": "~6.0.3",
70
58
  "vitest": "4.1.11",
71
59
  "vitest-browser-vue": "2.1.0",
72
60
  "vue": "~3.5.42",
73
- "vue-router": "~5.3.0",
61
+ "vue-router": "~5.3.1",
74
62
  "vue-tsc": "~3.3.11"
75
63
  },
76
- "packageManager": "pnpm@11.24.0"
77
- }
64
+ "scripts": {
65
+ "analyze": "nuxt analyze",
66
+ "eslint": "eslint .",
67
+ "typecheck": "nuxi typecheck",
68
+ "build": "nuxt build",
69
+ "dev": "nuxt dev",
70
+ "generate": "nuxt generate",
71
+ "preview": "nuxt preview",
72
+ "start": "nuxt start",
73
+ "test": "vitest run",
74
+ "test-u": "vitest run -u",
75
+ "test-i": "vitest"
76
+ }
77
+ }
package/utils/e2e.ts CHANGED
@@ -1,131 +1,131 @@
1
- import { createPage, url } from '@nuxt/test-utils/e2e'
2
- import type { GotoOptions, NuxtPage } from '@nuxt/test-utils'
3
- import { checkPageParam, checkStringParam } from './helpers/check-params'
4
-
5
- /**
6
- * Extra settings object for `gotoPage()` function.
7
- * All properties are optional.
8
- */
9
- export type GotoPageOptions = {
10
- /** Event to be awaited before NuxtPage instance is returned (defaults to `'hydration'`) */
11
- waitUntil?: GotoOptions['waitUntil']
12
- }
13
-
14
- /**
15
- * Visit a specified URL and return the page instance for further interaction.
16
- *
17
- * @param pageName - Path segment appended to the base URL (e.g. `'about'` → `/<about>`)
18
- * @param options - Optional extra settings (see `GotoPageOptions`)
19
- * @returns Playwright page instance after navigation and `hydration` event
20
- */
21
- export async function gotoPage(pageName: string, options?: GotoPageOptions): Promise<NuxtPage> {
22
- const { waitUntil } = options ?? {}
23
-
24
- // verify params
25
- checkStringParam('gotoPage:pageName', pageName)
26
- if (waitUntil) {
27
- checkStringParam('gotoPage:options.waitUntil', waitUntil)
28
- }
29
-
30
- // construct NuxtPage instance
31
- const page = await createPage()
32
- const urlPath = pageName.startsWith('/') ? url(pageName) : url(`/${pageName}`)
33
- await page.goto(urlPath, { waitUntil: waitUntil ?? 'hydration' })
34
-
35
- return page
36
- }
37
-
38
- /**
39
- * Extra settings object for `getDataHtml()` function.
40
- * All properties are optional.
41
- */
42
- export type GetDataHtmlOptions = {
43
- /** Event to be awaited before NuxtPage instance is returned (defaults to `'hydration'`) */
44
- waitUntil?: GotoOptions['waitUntil']
45
- /** CSS selector identifying the target element (defaults to `<body>` tag) */
46
- element?: string
47
- }
48
-
49
- /**
50
- * Extract inner HTML content from a specified element on a given page.
51
- * If no element is specified via `options.element`, the entire `<body>` content is returned.
52
- *
53
- * @param page - Playwright page instance, or a page name string (will call `gotoPage` internally)
54
- * @param options - Optional extra settings (see `GetDataHtmlOptions`)
55
- * @returns The inner HTML of the matched element
56
- */
57
- export async function getDataHtml(page: NuxtPage | string, options?: GetDataHtmlOptions): Promise<string> {
58
- const { waitUntil, element } = options ?? {}
59
-
60
- // verify params
61
- if (typeof page === 'string') {
62
- checkStringParam('getDataHtml:page', page)
63
- }
64
- if (waitUntil) {
65
- checkStringParam('getDataHtml:options.waitUntil', waitUntil)
66
- }
67
- if (element) {
68
- checkStringParam('getDataHtml:options.element', element)
69
- }
70
-
71
- // get NuxtPage instance
72
- const pageInstance = typeof page === 'string' ? await gotoPage(page, { waitUntil }) : page
73
- checkPageParam('getDataHtml:pageInstance', pageInstance)
74
-
75
- // extract target HTML
76
- const dataElement = pageInstance.locator(element ?? 'body')
77
- return await dataElement.innerHTML()
78
- }
79
-
80
- /**
81
- * Extra settings object for `getAPIResultHtml()` function.
82
- * Due to nature of the function, `triggerElement`, `targetUrl`, and `responseElement` are required.
83
- */
84
- export type GetAPIResultHtmlOptions = {
85
- /** Event to be awaited before NuxtPage instance is returned (defaults to `'hydration'`) */
86
- waitUntil?: GotoOptions['waitUntil']
87
- /** CSS selector for the clickable element that triggers the API request (required) */
88
- triggerElement: string
89
- /** Substring matched against the response URL to identify the expected API call (required) */
90
- targetUrl: string
91
- /** CSS selector for the element displaying the API response (required) */
92
- responseElement: string
93
- }
94
-
95
- /**
96
- * Execute an API call by clicking a trigger element, wait for a successful
97
- * response matching the target URL, then extract the inner HTML from the
98
- * response element.
99
- *
100
- * @param page - Playwright page instance, or a page name string (will call `gotoPage` internally)
101
- * @param options - Extra settings (see `GetAPIResultHtmlOptions`)
102
- * @returns The inner HTML of the response element
103
- */
104
- export async function getAPIResultHtml(page: NuxtPage | string, options: GetAPIResultHtmlOptions) {
105
- const { waitUntil, triggerElement, targetUrl, responseElement } = options
106
-
107
- // verify params
108
- if (typeof page === 'string') {
109
- checkStringParam('getAPIResultHtml:page', page)
110
- }
111
- if (waitUntil) {
112
- checkStringParam('getAPIResultHtml:options.waitUntil', waitUntil)
113
- }
114
- checkStringParam('getAPIResultHtml:triggerElement', triggerElement)
115
- checkStringParam('getAPIResultHtml:targetUrl', targetUrl)
116
- checkStringParam('getAPIResultHtml:responseElement', responseElement)
117
-
118
- // get NuxtPage instance
119
- const pageInstance = typeof page === 'string' ? await gotoPage(page, { waitUntil }) : page
120
- checkPageParam('getAPIResultHtml:pageInstance', pageInstance)
121
-
122
- // trigger API call
123
- await pageInstance.click(triggerElement)
124
- await pageInstance.waitForResponse(response =>
125
- response.url().includes(targetUrl) && response.ok(),
126
- )
127
-
128
- // extract target HTML
129
- const dataElement = pageInstance.locator(responseElement)
130
- return await dataElement.innerHTML()
131
- }
1
+ import { createPage, url } from '@nuxt/test-utils/e2e'
2
+ import type { GotoOptions, NuxtPage } from '@nuxt/test-utils'
3
+ import { checkPageParam, checkStringParam } from './helpers/check-params'
4
+
5
+ /**
6
+ * Extra settings object for `gotoPage()` function.
7
+ * All properties are optional.
8
+ */
9
+ export type GotoPageOptions = {
10
+ /** Event to be awaited before NuxtPage instance is returned (defaults to `'hydration'`) */
11
+ waitUntil?: GotoOptions['waitUntil']
12
+ }
13
+
14
+ /**
15
+ * Visit a specified URL and return the page instance for further interaction.
16
+ *
17
+ * @param pageName - Path segment appended to the base URL (e.g. `'about'` → `/<about>`)
18
+ * @param options - Optional extra settings (see `GotoPageOptions`)
19
+ * @returns Playwright page instance after navigation and `hydration` event
20
+ */
21
+ export async function gotoPage(pageName: string, options?: GotoPageOptions): Promise<NuxtPage> {
22
+ const { waitUntil } = options ?? {}
23
+
24
+ // verify params
25
+ checkStringParam('gotoPage:pageName', pageName)
26
+ if (waitUntil) {
27
+ checkStringParam('gotoPage:options.waitUntil', waitUntil)
28
+ }
29
+
30
+ // construct NuxtPage instance
31
+ const page = await createPage()
32
+ const urlPath = pageName.startsWith('/') ? url(pageName) : url(`/${pageName}`)
33
+ await page.goto(urlPath, { waitUntil: waitUntil ?? 'hydration' })
34
+
35
+ return page
36
+ }
37
+
38
+ /**
39
+ * Extra settings object for `getDataHtml()` function.
40
+ * All properties are optional.
41
+ */
42
+ export type GetDataHtmlOptions = {
43
+ /** Event to be awaited before NuxtPage instance is returned (defaults to `'hydration'`) */
44
+ waitUntil?: GotoOptions['waitUntil']
45
+ /** CSS selector identifying the target element (defaults to `<body>` tag) */
46
+ element?: string
47
+ }
48
+
49
+ /**
50
+ * Extract inner HTML content from a specified element on a given page.
51
+ * If no element is specified via `options.element`, the entire `<body>` content is returned.
52
+ *
53
+ * @param page - Playwright page instance, or a page name string (will call `gotoPage` internally)
54
+ * @param options - Optional extra settings (see `GetDataHtmlOptions`)
55
+ * @returns The inner HTML of the matched element
56
+ */
57
+ export async function getDataHtml(page: NuxtPage | string, options?: GetDataHtmlOptions): Promise<string> {
58
+ const { waitUntil, element } = options ?? {}
59
+
60
+ // verify params
61
+ if (typeof page === 'string') {
62
+ checkStringParam('getDataHtml:page', page)
63
+ }
64
+ if (waitUntil) {
65
+ checkStringParam('getDataHtml:options.waitUntil', waitUntil)
66
+ }
67
+ if (element) {
68
+ checkStringParam('getDataHtml:options.element', element)
69
+ }
70
+
71
+ // get NuxtPage instance
72
+ const pageInstance = typeof page === 'string' ? await gotoPage(page, { waitUntil }) : page
73
+ checkPageParam('getDataHtml:pageInstance', pageInstance)
74
+
75
+ // extract target HTML
76
+ const dataElement = pageInstance.locator(element ?? 'body')
77
+ return await dataElement.innerHTML()
78
+ }
79
+
80
+ /**
81
+ * Extra settings object for `getAPIResultHtml()` function.
82
+ * Due to nature of the function, `triggerElement`, `targetUrl`, and `responseElement` are required.
83
+ */
84
+ export type GetAPIResultHtmlOptions = {
85
+ /** Event to be awaited before NuxtPage instance is returned (defaults to `'hydration'`) */
86
+ waitUntil?: GotoOptions['waitUntil']
87
+ /** CSS selector for the clickable element that triggers the API request (required) */
88
+ triggerElement: string
89
+ /** Substring matched against the response URL to identify the expected API call (required) */
90
+ targetUrl: string
91
+ /** CSS selector for the element displaying the API response (required) */
92
+ responseElement: string
93
+ }
94
+
95
+ /**
96
+ * Execute an API call by clicking a trigger element, wait for a successful
97
+ * response matching the target URL, then extract the inner HTML from the
98
+ * response element.
99
+ *
100
+ * @param page - Playwright page instance, or a page name string (will call `gotoPage` internally)
101
+ * @param options - Extra settings (see `GetAPIResultHtmlOptions`)
102
+ * @returns The inner HTML of the response element
103
+ */
104
+ export async function getAPIResultHtml(page: NuxtPage | string, options: GetAPIResultHtmlOptions) {
105
+ const { waitUntil, triggerElement, targetUrl, responseElement } = options
106
+
107
+ // verify params
108
+ if (typeof page === 'string') {
109
+ checkStringParam('getAPIResultHtml:page', page)
110
+ }
111
+ if (waitUntil) {
112
+ checkStringParam('getAPIResultHtml:options.waitUntil', waitUntil)
113
+ }
114
+ checkStringParam('getAPIResultHtml:triggerElement', triggerElement)
115
+ checkStringParam('getAPIResultHtml:targetUrl', targetUrl)
116
+ checkStringParam('getAPIResultHtml:responseElement', responseElement)
117
+
118
+ // get NuxtPage instance
119
+ const pageInstance = typeof page === 'string' ? await gotoPage(page, { waitUntil }) : page
120
+ checkPageParam('getAPIResultHtml:pageInstance', pageInstance)
121
+
122
+ // trigger API call
123
+ await pageInstance.click(triggerElement)
124
+ await pageInstance.waitForResponse(response =>
125
+ response.url().includes(targetUrl) && response.ok(),
126
+ )
127
+
128
+ // extract target HTML
129
+ const dataElement = pageInstance.locator(responseElement)
130
+ return await dataElement.innerHTML()
131
+ }
@@ -1,41 +1,41 @@
1
- import type { NuxtPage } from '@nuxt/test-utils'
2
- import { locationHint } from './location-hint'
3
-
4
- // given string param must be an actual non-empty string
5
- export function checkStringParam(paramName: string, paramValue?: string) {
6
- if (!paramValue) {
7
- console.warn(`Passed value '${paramName}' is missing or empty.\n${locationHint()}`)
8
- }
9
- if (typeof paramValue !== 'string') {
10
- console.warn(`Passed value '${paramName}' is not a string.\n${locationHint()}`)
11
- }
12
- }
13
-
14
- // given string param must be an actual number
15
- export function checkNumberParam(paramName: string, paramValue?: number) {
16
- if (paramValue === undefined || paramValue === null) {
17
- console.warn(`Passed value '${paramName}' is missing or empty.\n${locationHint()}`)
18
- }
19
- if (typeof paramValue !== 'number') {
20
- console.warn(`Passed value '${paramName}' is not a number.\n${locationHint()}`)
21
- }
22
- }
23
-
24
- // given NuxtPage param must be an actual non-nullish NuxtPage instance
25
- export function checkPageParam(paramName: string, paramValue?: NuxtPage) {
26
- if (!paramValue) {
27
- console.warn(`Passed value '${paramName}' is missing or empty.\n${locationHint()}`)
28
- }
29
- if (typeof paramValue !== 'object') {
30
- console.warn(`Passed value '${paramName}' is not a NuxtPage.\n${locationHint()}`)
31
- } else {
32
- const pageInstance = paramValue as unknown as Record<string, unknown>
33
- if (
34
- typeof pageInstance.goto !== 'function'
35
- || typeof pageInstance.locator !== 'function'
36
- || typeof pageInstance.waitForResponse !== 'function'
37
- ) {
38
- console.warn(`Passed value '${paramName}' is not a NuxtPage.\n${locationHint()}`)
39
- }
40
- }
41
- }
1
+ import type { NuxtPage } from '@nuxt/test-utils'
2
+ import { locationHint } from './location-hint'
3
+
4
+ // given string param must be an actual non-empty string
5
+ export function checkStringParam(paramName: string, paramValue?: string) {
6
+ if (!paramValue) {
7
+ console.warn(`Passed value '${paramName}' is missing or empty.\n${locationHint()}`)
8
+ }
9
+ if (typeof paramValue !== 'string') {
10
+ console.warn(`Passed value '${paramName}' is not a string.\n${locationHint()}`)
11
+ }
12
+ }
13
+
14
+ // given string param must be an actual number
15
+ export function checkNumberParam(paramName: string, paramValue?: number) {
16
+ if (paramValue === undefined || paramValue === null) {
17
+ console.warn(`Passed value '${paramName}' is missing or empty.\n${locationHint()}`)
18
+ }
19
+ if (typeof paramValue !== 'number') {
20
+ console.warn(`Passed value '${paramName}' is not a number.\n${locationHint()}`)
21
+ }
22
+ }
23
+
24
+ // given NuxtPage param must be an actual non-nullish NuxtPage instance
25
+ export function checkPageParam(paramName: string, paramValue?: NuxtPage) {
26
+ if (!paramValue) {
27
+ console.warn(`Passed value '${paramName}' is missing or empty.\n${locationHint()}`)
28
+ }
29
+ if (typeof paramValue !== 'object') {
30
+ console.warn(`Passed value '${paramName}' is not a NuxtPage.\n${locationHint()}`)
31
+ } else {
32
+ const pageInstance = paramValue as unknown as Record<string, unknown>
33
+ if (
34
+ typeof pageInstance.goto !== 'function'
35
+ || typeof pageInstance.locator !== 'function'
36
+ || typeof pageInstance.waitForResponse !== 'function'
37
+ ) {
38
+ console.warn(`Passed value '${paramName}' is not a NuxtPage.\n${locationHint()}`)
39
+ }
40
+ }
41
+ }
@@ -1,30 +1,30 @@
1
- import { createRequire } from 'node:module'
2
- import { dirname } from 'node:path'
3
-
4
- // shows "(at path-to-file:line:column)" hint to locate cause from stack trace
5
- // this syntax allow tools like VS Code to create clickable link directly to the source
6
- export function locationHint(): string {
7
- return ` (at ${getCallSite()})`
8
- }
9
-
10
- // path to nuxt-spec/utils directory computed on runtime
11
- const pkgUtilsDir = normalizePath(dirname(createRequire(import.meta.url).resolve('nuxt-spec/utils')))
12
-
13
- // handle possible Win backslashes
14
- function normalizePath(path: string): string {
15
- return path.replace(/^file:\/\//, '').replace(/\\/g, '/')
16
- }
17
-
18
- // locate first stack frame outside of nuxt-spec utils
19
- // which will the place where the utility function is being called from
20
- function getCallSite(): string | undefined {
21
- const stack = new Error().stack?.split('\n').slice(1) ?? []
22
- for (const raw of stack) {
23
- const match = raw.match(/\(?((?:file:\/\/)?[^()\s]+:\d+:\d+)\)?\s*$/)
24
- if (!match?.[1]) continue
25
- const location = normalizePath(match[1])
26
- if (location.includes(pkgUtilsDir)) continue
27
- return location
28
- }
29
- return undefined
30
- }
1
+ import { createRequire } from 'node:module'
2
+ import { dirname } from 'node:path'
3
+
4
+ // shows "(at path-to-file:line:column)" hint to locate cause from stack trace
5
+ // this syntax allow tools like VS Code to create clickable link directly to the source
6
+ export function locationHint(): string {
7
+ return ` (at ${getCallSite()})`
8
+ }
9
+
10
+ // path to nuxt-spec/utils directory computed on runtime
11
+ const pkgUtilsDir = normalizePath(dirname(createRequire(import.meta.url).resolve('nuxt-spec/utils')))
12
+
13
+ // handle possible Win backslashes
14
+ function normalizePath(path: string): string {
15
+ return path.replace(/^file:\/\//, '').replace(/\\/g, '/')
16
+ }
17
+
18
+ // locate first stack frame outside of nuxt-spec utils
19
+ // which will the place where the utility function is being called from
20
+ function getCallSite(): string | undefined {
21
+ const stack = new Error().stack?.split('\n').slice(1) ?? []
22
+ for (const raw of stack) {
23
+ const match = raw.match(/\(?((?:file:\/\/)?[^()\s]+:\d+:\d+)\)?\s*$/)
24
+ if (!match?.[1]) continue
25
+ const location = normalizePath(match[1])
26
+ if (location.includes(pkgUtilsDir)) continue
27
+ return location
28
+ }
29
+ return undefined
30
+ }
package/utils/index.ts CHANGED
@@ -1,12 +1,12 @@
1
- import { gotoPage, getDataHtml, getAPIResultHtml } from './e2e'
2
- import { compareScreenshot } from './screenshot'
3
- import type { CompareScreenshotOptions } from './screenshot'
4
-
5
- export {
6
- compareScreenshot,
7
- gotoPage,
8
- getDataHtml,
9
- getAPIResultHtml,
10
- }
11
-
12
- export type { CompareScreenshotOptions }
1
+ import { gotoPage, getDataHtml, getAPIResultHtml } from './e2e'
2
+ import { compareScreenshot } from './screenshot'
3
+ import type { CompareScreenshotOptions } from './screenshot'
4
+
5
+ export {
6
+ compareScreenshot,
7
+ gotoPage,
8
+ getDataHtml,
9
+ getAPIResultHtml,
10
+ }
11
+
12
+ export type { CompareScreenshotOptions }
@@ -1,20 +1,20 @@
1
- // Vitest setup file for the `e2e` project
2
- // allows connecting to an external Playwright instance,
3
- // if NUXT_SPEC_EXTERNAL_PLAYWRIGHT is set
4
-
5
- import { chromium, firefox, webkit } from 'playwright-core'
6
- import type { Browser, BrowserType } from 'playwright-core'
7
-
8
- const externalPlaywright = process.env.NUXT_SPEC_EXTERNAL_PLAYWRIGHT
9
-
10
- if (externalPlaywright) {
11
- for (const browserType of [chromium, firefox, webkit] as BrowserType[]) {
12
- console.log(`[Nuxt Spec - e2e] Using external Playwright instance at: ${externalPlaywright}`)
13
- // @nuxt/test-utils always calls `playwright[type].launch()` with no way to opt into
14
- // `connect()`, so the launch method is swapped for a connect against the WS endpoint
15
- browserType.launch = (): Promise<Browser> => browserType.connect(externalPlaywright, {
16
- // this allows reaching caller's localhost from within the external Playwright
17
- exposeNetwork: '<loopback>',
18
- })
19
- }
20
- }
1
+ // Vitest setup file for the `e2e` project
2
+ // allows connecting to an external Playwright instance,
3
+ // if NUXT_SPEC_EXTERNAL_PLAYWRIGHT is set
4
+
5
+ import { chromium, firefox, webkit } from 'playwright-core'
6
+ import type { Browser, BrowserType } from 'playwright-core'
7
+
8
+ const externalPlaywright = process.env.NUXT_SPEC_EXTERNAL_PLAYWRIGHT
9
+
10
+ if (externalPlaywright) {
11
+ for (const browserType of [chromium, firefox, webkit] as BrowserType[]) {
12
+ console.log(`[Nuxt Spec - e2e] Using external Playwright instance at: ${externalPlaywright}`)
13
+ // @nuxt/test-utils always calls `playwright[type].launch()` with no way to opt into
14
+ // `connect()`, so the launch method is swapped for a connect against the WS endpoint
15
+ browserType.launch = (): Promise<Browser> => browserType.connect(externalPlaywright, {
16
+ // this allows reaching caller's localhost from within the external Playwright
17
+ exposeNetwork: '<loopback>',
18
+ })
19
+ }
20
+ }