Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
"@sinonjs/fake-timers@14.0.0": "patches/@sinonjs__fake-timers@14.0.0.patch",
"cac@6.7.14": "patches/cac@6.7.14.patch",
"@types/sinonjs__fake-timers@8.1.5": "patches/@types__sinonjs__fake-timers@8.1.5.patch",
"acorn@8.11.3": "patches/acorn@8.11.3.patch"
"acorn@8.11.3": "patches/acorn@8.11.3.patch",
"turbo-stream": "patches/turbo-stream.patch"
},
"onlyBuiltDependencies": [
"@sveltejs/kit",
Expand Down
19 changes: 5 additions & 14 deletions packages/ui/client/composables/client/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import type {
WebSocketEvents,
WebSocketHandlers,
} from 'vitest'
import { decompressSync, strFromU8 } from 'fflate'
import { parse } from 'flatted'
import { decode } from 'turbo-stream'
import { reactive } from 'vue'
import { StateManager } from '../../../../ws-client/src/state'

Expand Down Expand Up @@ -98,18 +97,10 @@ export function createStaticClient(): VitestClient {

async function registerMetadata() {
const res = await fetch(window.METADATA_PATH!)
const contentType = res.headers.get('content-type')?.toLowerCase() || ''
if (
contentType.includes('application/gzip')
|| contentType.includes('application/x-gzip')
) {
const compressed = new Uint8Array(await res.arrayBuffer())
const decompressed = strFromU8(decompressSync(compressed))
metadata = parse(decompressed) as HTMLReportMetadata
}
else {
metadata = parse(await res.text()) as HTMLReportMetadata
}
const contentStream = res.body!
.pipeThrough(new DecompressionStream('gzip'))
.pipeThrough(new TextDecoderStream())
metadata = await decode(contentStream)
const event = new Event('open')
ctx.ws.dispatchEvent(event)
}
Expand Down
21 changes: 10 additions & 11 deletions packages/ui/node/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import type { Reporter } from 'vitest/reporters'
import crypto from 'node:crypto'
import { promises as fs } from 'node:fs'
import { readFile, writeFile } from 'node:fs/promises'
import { Readable } from 'node:stream'
import { fileURLToPath } from 'node:url'
import { promisify } from 'node:util'
import { gzip, constants as zlibConstants } from 'node:zlib'
import { stringify } from 'flatted'
import mime from 'mime/lite'
import { dirname, extname, relative, resolve } from 'pathe'
import { globSync } from 'tinyglobby'
import c from 'tinyrainbow'
import { encode } from 'turbo-stream'
import { getModuleGraph } from '../../vitest/src/utils/graph'

interface PotentialConfig {
Expand Down Expand Up @@ -122,7 +121,7 @@ export default class HTMLReporter implements Reporter {
}))

await Promise.all(promises)
await this.writeReport(stringify(result))
await this.writeReport(result)
}

async processAttachment(attachment: TestAttachment): Promise<void> {
Expand Down Expand Up @@ -161,14 +160,14 @@ export default class HTMLReporter implements Reporter {
}
}

async writeReport(report: string): Promise<void> {
const metaFile = resolve(this.reporterDir, 'html.meta.json.gz')
async writeReport(report: unknown): Promise<void> {
const metaFile = resolve(this.reporterDir, 'html.meta.bin')
const contentStream = encode(report)
const rawStream = contentStream
.pipeThrough(new TextEncoderStream())
.pipeThrough(new CompressionStream('gzip'))
await writeFile(metaFile, Readable.fromWeb(rawStream as any))

const promiseGzip = promisify(gzip)
const data = await promiseGzip(report, {
level: zlibConstants.Z_BEST_COMPRESSION,
})
await fs.writeFile(metaFile, data, 'base64')
const ui = resolve(distDir, 'client')
// copy ui
const files = globSync(['**/*'], { cwd: ui, expandDirectories: false })
Expand Down
1 change: 1 addition & 0 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"mime": "^4.1.0",
"rollup": "^4.53.3",
"splitpanes": "^4.0.4",
"turbo-stream": "^3.1.0",
"typescript": "^5.9.3",
"unocss": "catalog:",
"vite": "^5.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default defineConfig({
// name: 'debug-html-report',
// apply: 'serve',
// transformIndexHtml(html) {
// return html.replace('<!-- !LOAD_METADATA! -->', `<script>window.METADATA_PATH="${debugLink}/html.meta.json.gz"</script>`)
// return html.replace('<!-- !LOAD_METADATA! -->', `<script>window.METADATA_PATH="${debugLink}/html.meta.bin"</script>`)
// },
// },

Expand Down
15 changes: 15 additions & 0 deletions packages/vitest/LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,21 @@ Repository: git+https://github.com/antfu/strip-literal.git

---------------------------------------

## turbo-stream
License: MIT
By: Jacob Ebey
Repository: https://github.com/jacob-ebey/turbo-stream.git

> Copyright (c) 2018-19 [these people](https://github.com/rich-harris/devalue/graphs/contributors)
>
> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

---------------------------------------

## type-detect
License: MIT
By: Jake Luer, Keith Cirkel, David Losert, Aleksey Shvayka, Lucas Fernandes da Costa, Grant Snodgrass, Jeremy Tice, Edward Betts, dvlsg, Amila Welihinda, Jake Champion, Miroslav Bajtoš
Expand Down
1 change: 1 addition & 0 deletions packages/vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@
"mime": "^4.1.0",
"prompts": "^2.4.2",
"strip-literal": "catalog:",
"turbo-stream": "^3.1.0",
"ws": "catalog:"
}
}
33 changes: 22 additions & 11 deletions packages/vitest/src/node/reporters/blob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ import type { Vitest } from '../core'
import type { TestProject } from '../project'
import type { Reporter } from '../types/reporter'
import type { TestModule } from './reported-tasks'
import { existsSync } from 'node:fs'
import { mkdir, readdir, readFile, stat, writeFile } from 'node:fs/promises'
import { parse, stringify } from 'flatted'
import { createReadStream, existsSync } from 'node:fs'
import { mkdir, readdir, stat, writeFile } from 'node:fs/promises'
import { Readable } from 'node:stream'
import { createDebug } from 'obug'
import { dirname, resolve } from 'pathe'
import { decode, encode } from 'turbo-stream'
import { getOutputFile } from '../../utils/config-helpers'

const debug = createDebug('vitest:reporter:blob')

export interface BlobOptions {
outputFile?: string
}
Expand Down Expand Up @@ -50,8 +54,8 @@ export class BlobReporter implements Reporter {
if (!outputFile) {
const shard = this.ctx.config.shard
outputFile = shard
? `.vitest-reports/blob-${shard.index}-${shard.count}.json`
: '.vitest-reports/blob.json'
? `.vitest-reports/blob-${shard.index}-${shard.count}.bin`
: '.vitest-reports/blob.bin'
}

const modules = this.ctx.projects.map<MergeReportModuleKeys>(
Expand Down Expand Up @@ -85,14 +89,19 @@ export class BlobReporter implements Reporter {
}

export async function writeBlob(content: MergeReport, filename: string): Promise<void> {
const report = stringify(content)
debug('writeBlob:start %s', filename)
const contentStream = encode(content)
const rawStream = contentStream
.pipeThrough(new TextEncoderStream())
.pipeThrough(new CompressionStream('gzip'))

const dir = dirname(filename)
if (!existsSync(dir)) {
await mkdir(dir, { recursive: true })
}

await writeFile(filename, report, 'utf-8')
await writeFile(filename, Readable.fromWeb(rawStream as any))
debug('writeBlob:end %s', filename)
}

export async function readBlobs(
Expand All @@ -111,10 +120,12 @@ export async function readBlobs(
`vitest.mergeReports() expects all paths in "${blobsDirectory}" to be files generated by the blob reporter, but "${filename}" is not a file`,
)
}
const content = await readFile(fullPath, 'utf-8')
const [version, files, errors, moduleKeys, coverage, executionTime] = parse(
content,
) as MergeReport
const rawStream = Readable.toWeb(createReadStream(fullPath)) as ReadableStream
const contentStream = rawStream
.pipeThrough(new DecompressionStream('gzip'))
.pipeThrough(new TextDecoderStream())
const decoded = await decode(contentStream)
const [version, files, errors, moduleKeys, coverage, executionTime] = decoded as MergeReport
if (!version) {
throw new TypeError(
`vitest.mergeReports() expects all paths in "${blobsDirectory}" to be files generated by the blob reporter, but "${filename}" is not a valid blob file`,
Expand Down
54 changes: 54 additions & 0 deletions patches/turbo-stream.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
diff --git a/dist/encode.js b/dist/encode.js
index b597f63b4e2165b4652bbeaf0d5df5be94607f68..a7c1c47c00bf9fe72c4610a87d3dda673ff309fd 100644
--- a/dist/encode.js
+++ b/dist/encode.js
@@ -20,9 +20,17 @@ function encode(value, { plugins = [], redactErrors = true, signal } = {}) {
let wg = new shared_js_1.WaitGroup();
let chunks = [];
let encode = (value) => {
- encodeSync(value, chunks, refCache, asyncCache, promises, counters, plugins, redactErrors);
- controller.enqueue(chunks.join("") + "\n");
- chunks.length = 0;
+ // https://github.com/jacob-ebey/turbo-stream/pull/78
+ const chunks = {
+ push(...items) {
+ controller.enqueue(items.join("") + "\n");
+ }
+ }
+ encodeSync(value, chunks, refCache, asyncCache, promises, counters, plugins, redactErrors)
+ controller.enqueue("\n");
+ // encodeSync(value, chunks, refCache, asyncCache, promises, counters, plugins, redactErrors);
+ // controller.enqueue(chunks.join("") + "\n");
+ // chunks.length = 0;
};
let handlePromiseResolved = (id, value) => {
wg.done();
diff --git a/dist/turbo-stream.mjs b/dist/turbo-stream.mjs
index 91233adde3b313b822d8573cd83fb261df83d8d5..e74565dd96a789491e4d0d2803ee521ea7a02f04 100644
--- a/dist/turbo-stream.mjs
+++ b/dist/turbo-stream.mjs
@@ -842,6 +842,12 @@ function encode(value, { plugins = [], redactErrors = true, signal } = {}) {
let wg = new WaitGroup();
let chunks = [];
let encode2 = (value2) => {
+ // https://github.com/jacob-ebey/turbo-stream/pull/78
+ const chunks = {
+ push(...items) {
+ controller.enqueue(items.join(""));
+ }
+ }
encodeSync(
value2,
chunks,
@@ -852,8 +858,9 @@ function encode(value, { plugins = [], redactErrors = true, signal } = {}) {
plugins,
redactErrors
);
- controller.enqueue(chunks.join("") + "\n");
- chunks.length = 0;
+ controller.enqueue("\n");
+ // controller.enqueue(chunks.join("") + "\n");
+ // chunks.length = 0;
};
let handlePromiseResolved = (id, value2) => {
wg.done();
Loading
Loading