Skip to content

report per-file chunks over coverage start/stop offsets and lines #2

@bartveneman

Description

@bartveneman

See

// TODO: { is_covered: boolean, start_offset: number, start_line: number, end_offset: number, end_line: number }[]

This is useful because in projectwallace.com I'm manually calculating these things myself.

// Split coverage line numbers into chunks so we can easily loop over them in our layout
	let line_number_chunks = $derived.by(() => {
		if (!show_coverage) return

		let chunks = [
			{
				start_line: 0,
				is_covered: line_coverage[0] === 1,
				end_line: 0,
				size: 0
			}
		]

		for (let index = 0; index < line_coverage.length; index++) {
			let is_covered = line_coverage[index]
			if (index > 0 && is_covered !== line_coverage[index - 1]) {
				let last_chunk = chunks.at(-1)!
				last_chunk.end_line = index
				last_chunk.size = index - last_chunk.start_line

				chunks.push({
					start_line: index,
					is_covered: is_covered === 1,
					end_line: index,
					size: 0
				})
			}
		}

		let last_chunk = chunks.at(-1)!
		last_chunk.size = line_coverage.length - last_chunk.start_line

		return chunks
	})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions