| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -179,10 +179,14 @@ export class PlaywrightBrowserProvider implements BrowserProvider { | |||
| 179 | 179 | const ids = sessionIds.get(sessionId) || [] | |
| 180 | 180 | ids.push(moduleUrl.href) | |
| 181 | 181 | sessionIds.set(sessionId, ids) | |
| 182 | - idPreficates.set(moduleUrl.href, predicate) | ||
| 182 | + idPreficates.set(predicateKey(sessionId, moduleUrl.href), predicate) | ||
| 183 | 183 | return predicate | |
| 184 | 184 | } | |
| 185 | 185 | ||
| 186 | + function predicateKey(sessionId: string, url: string) { | ||
| 187 | + return `${sessionId}:${url}` | ||
| 188 | + } | ||
| 189 | + | ||
| 186 | 190 | return { | |
| 187 | 191 | register: async (sessionId: string, module: MockedModule): Promise<void> => { | |
| 188 | 192 | const page = this.getPage(sessionId) | |
@@ -200,17 +204,17 @@ export class PlaywrightBrowserProvider implements BrowserProvider { | |||
| 200 | 204 | // https://github.com/microsoft/playwright/issues/18318 | |
| 201 | 205 | const isWebkit = this.browserName === 'webkit' | |
| 202 | 206 | if (isWebkit) { | |
| 203 | - const url = module.type === 'redirect' | ||
| 204 | - ? (() => { | ||
| 205 | - // url has http:// which vite.trasnformRequest doesn't understand | ||
| 206 | - const url = new URL(module.redirect) | ||
| 207 | - return url.href.slice(url.origin.length) | ||
| 208 | - })() | ||
| 209 | - : (() => { | ||
| 210 | - const url = new URL(route.request().url()) | ||
| 211 | - url.searchParams.set('mock', module.type) | ||
| 212 | - return url.href.slice(url.origin.length) | ||
| 213 | - })() | ||
| 207 | + let url: string | ||
| 208 | + if (module.type === 'redirect') { | ||
| 209 | + const redirect = new URL(module.redirect) | ||
| 210 | + url = redirect.href.slice(redirect.origin.length) | ||
| 211 | + } | ||
| 212 | + else { | ||
| 213 | + const request = new URL(route.request().url()) | ||
| 214 | + request.searchParams.set('mock', module.type) | ||
| 215 | + url = request.href.slice(request.origin.length) | ||
| 216 | + } | ||
| 217 | + | ||
| 214 | 218 | const result = await this.project.browser!.vite.transformRequest(url).catch(() => null) | |
| 215 | 219 | if (!result) { | |
| 216 | 220 | return route.continue() | |
@@ -252,18 +256,20 @@ export class PlaywrightBrowserProvider implements BrowserProvider { | |||
| 252 | 256 | }, | |
| 253 | 257 | delete: async (sessionId: string, id: string): Promise<void> => { | |
| 254 | 258 | const page = this.getPage(sessionId) | |
| 255 | - const predicate = idPreficates.get(id) | ||
| 259 | + const key = predicateKey(sessionId, id) | ||
| 260 | + const predicate = idPreficates.get(key) | ||
| 256 | 261 | if (predicate) { | |
| 257 | - await page.unroute(predicate).finally(() => idPreficates.delete(id)) | ||
| 262 | + await page.unroute(predicate).finally(() => idPreficates.delete(key)) | ||
| 258 | 263 | } | |
| 259 | 264 | }, | |
| 260 | 265 | clear: async (sessionId: string): Promise<void> => { | |
| 261 | 266 | const page = this.getPage(sessionId) | |
| 262 | 267 | const ids = sessionIds.get(sessionId) || [] | |
| 263 | 268 | const promises = ids.map((id) => { | |
| 264 | - const predicate = idPreficates.get(id) | ||
| 269 | + const key = predicateKey(sessionId, id) | ||
| 270 | + const predicate = idPreficates.get(key) | ||
| 265 | 271 | if (predicate) { | |
| 266 | - return page.unroute(predicate).finally(() => idPreficates.delete(id)) | ||
| 272 | + return page.unroute(predicate).finally(() => idPreficates.delete(key)) | ||
| 267 | 273 | } | |
| 268 | 274 | return null | |
| 269 | 275 | }) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -55,7 +55,7 @@ export class ModuleMockerMSWInterceptor implements ModuleMockerInterceptor { | |||
| 55 | 55 | this.mocks.delete(url) | |
| 56 | 56 | } | |
| 57 | 57 | ||
| 58 | - invalidate(): void { | ||
| 58 | + async invalidate(): Promise<void> { | ||
| 59 | 59 | this.mocks.clear() | |
| 60 | 60 | } | |
| 61 | 61 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,7 +11,7 @@ export class ModuleMockerServerInterceptor implements ModuleMockerInterceptor { | |||
| 11 | 11 | await rpc('vitest:interceptor:delete', id) | |
| 12 | 12 | } | |
| 13 | 13 | ||
| 14 | - invalidate(): void { | ||
| 15 | - rpc('vitest:interceptor:invalidate') | ||
| 14 | + async invalidate(): Promise<void> { | ||
| 15 | + await rpc('vitest:interceptor:invalidate') | ||
| 16 | 16 | } | |
| 17 | 17 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,5 +3,5 @@ import type { MockedModule } from '../registry' | |||
| 3 | 3 | export interface ModuleMockerInterceptor { | |
| 4 | 4 | register: (module: MockedModule) => Promise<void> | |
| 5 | 5 | delete: (url: string) => Promise<void> | |
| 6 | - invalidate: () => void | ||
| 6 | + invalidate: () => Promise<void> | ||
| 7 | 7 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -53,7 +53,7 @@ export class ModuleMocker { | |||
| 53 | 53 | return | |
| 54 | 54 | } | |
| 55 | 55 | await this.rpc.invalidate(ids) | |
| 56 | - this.interceptor.invalidate() | ||
| 56 | + await this.interceptor.invalidate() | ||
| 57 | 57 | this.registry.clear() | |
| 58 | 58 | } | |
| 59 | 59 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments