|
1 | | -import type { Stats } from 'node:fs' |
2 | 1 | import type { HtmlTagDescriptor } from 'vite' |
3 | 2 | import type { Plugin } from 'vitest/config' |
4 | 3 | import type { Vitest } from 'vitest/node' |
5 | 4 | import type { ParentBrowserProject } from './projectParent' |
6 | | -import { createReadStream, lstatSync, readFileSync } from 'node:fs' |
| 5 | +import { createReadStream, readFileSync } from 'node:fs' |
7 | 6 | import { createRequire } from 'node:module' |
8 | 7 | import { dynamicImportPlugin } from '@vitest/mocker/node' |
9 | 8 | import { toArray } from '@vitest/utils/helpers' |
10 | 9 | import MagicString from 'magic-string' |
11 | | -import { basename, dirname, extname, join, resolve } from 'pathe' |
| 10 | +import { basename, dirname, join, resolve } from 'pathe' |
12 | 11 | import sirv from 'sirv' |
13 | 12 | import { coverageConfigDefaults } from 'vitest/config' |
14 | 13 | import { |
@@ -97,61 +96,6 @@ export default (parentServer: ParentBrowserProject, base = '/'): Plugin[] => { |
97 | 96 | ) |
98 | 97 | } |
99 | 98 |
|
100 | | - const uiEnabled = parentServer.config.browser.ui |
101 | | - |
102 | | - if (uiEnabled) { |
103 | | - // eslint-disable-next-line prefer-arrow-callback |
104 | | - server.middlewares.use(`${base}__screenshot-error`, function vitestBrowserScreenshotError(req, res) { |
105 | | - if (!req.url) { |
106 | | - res.statusCode = 404 |
107 | | - res.end() |
108 | | - return |
109 | | - } |
110 | | - |
111 | | - const url = new URL(req.url, 'http://localhost') |
112 | | - const id = url.searchParams.get('id') |
113 | | - if (!id) { |
114 | | - res.statusCode = 404 |
115 | | - res.end() |
116 | | - return |
117 | | - } |
118 | | - |
119 | | - const task = parentServer.vitest.state.idMap.get(id) |
120 | | - const file = task?.meta.failScreenshotPath |
121 | | - if (!file) { |
122 | | - res.statusCode = 404 |
123 | | - res.end() |
124 | | - return |
125 | | - } |
126 | | - |
127 | | - let stat: Stats | undefined |
128 | | - try { |
129 | | - stat = lstatSync(file) |
130 | | - } |
131 | | - catch { |
132 | | - } |
133 | | - |
134 | | - if (!stat?.isFile()) { |
135 | | - res.statusCode = 404 |
136 | | - res.end() |
137 | | - return |
138 | | - } |
139 | | - |
140 | | - const ext = extname(file) |
141 | | - const buffer = readFileSync(file) |
142 | | - res.setHeader( |
143 | | - 'Cache-Control', |
144 | | - 'public,max-age=0,must-revalidate', |
145 | | - ) |
146 | | - res.setHeader('Content-Length', buffer.length) |
147 | | - res.setHeader('Content-Type', ext === 'jpeg' || ext === 'jpg' |
148 | | - ? 'image/jpeg' |
149 | | - : ext === 'webp' |
150 | | - ? 'image/webp' |
151 | | - : 'image/png') |
152 | | - res.end(buffer) |
153 | | - }) |
154 | | - } |
155 | 99 | server.middlewares.use((req, res, next) => { |
156 | 100 | // 9000 mega head move |
157 | 101 | // Vite always caches optimized dependencies, but users might mock |
|
0 commit comments