Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Current deno coverage interface is not compatible with istanbul #20007

Open
loynoir opened this issue Aug 1, 2023 · 1 comment
Open

Current deno coverage interface is not compatible with istanbul #20007

loynoir opened this issue Aug 1, 2023 · 1 comment

Comments

@loynoir
Copy link

loynoir commented Aug 1, 2023

Comparison

  • c8 generate coverage, able to integrate with istanbul without hardcode

  • playwright generate coverage compatible with istanbul https://playwright.dev/docs/api/class-coverage

  • When integrate deno coverage with istanbul, need to hard code. Else geneate wrong report.

Interface Comparison

interface CoverageC8 {
  result: Array<{
    scriptId: `${number}`
    url: `${string}:${string}`
    functions: Array<{
      functionName: string
      ranges: Array<{
        startOffset: number
        endOffset: number
        count: number
      }>
      isBlockCoverage: boolean
    }>
  }>
  timestamp: number
  'source-map-cache': Record<
    `${string}://${string}`,
    {
      lineLengths: [number, number, number]
      data: {
        version: 3
        file?: null
        mappings: string
        names: never[]
        sources: [`${string}://${string}`]
        sourcesContent: [string]
        sourceRoot: ''
      }
      url: null
      sourceURL: null
    }
  >
}

interface CoveragePlaywright {
  url: `${string}://${string}`
  scriptId: `${number}`
  source: string
  functions: Array<{
    functionName: string
    isBlockCoverage: boolean
    ranges: Array<{
      startOffset: number
      endOffset: number
      count: number
    }>
  }>
}

interface CoverageDeno {
  scriptId: `${number}`
  url: `${string}://${string}`
  functions: Array<{
    functionName: string
    isBlockCoverage: boolean
    ranges: Array<{
      startOffset: number
      endOffset: number
      count: number
    }>
  }>
}

Reproduce

Adapt from https://playwright.dev/docs/api/class-coverage, which have similar interface like deno coverage.

When use below code, generate wrong report.

          const converter = v8toIstanbul(entry.url, 0, {
            source: entry.source ?? (await read(entry.url))
          })

Workaround

Adapt from https://playwright.dev/docs/api/class-coverage, which have similar interface like deno coverage.

To generate correct report, must use hard code:

  • make sure using same typescript version with deno

  • make sure using same typescript config with deno

          const converter = v8toIstanbul(entry.url, 0, {
            source: entry.source ?? ts.transpile(await read(entry.url), compileOptions, entry.url)
          })

Suggestion

  • Or add .source which represent the js after compiled should work. So, user don't need to hard code typescript version and config, to ensure .source is identical with deno coverage .range.

  • Or use interface CoverageC8, with provide .source-map-cache, and should be better than CoveragePlaywright

@loynoir
Copy link
Author

loynoir commented Aug 1, 2023

Reproduce

          const converter = v8toIstanbul(entry.url, 0, {
            source: entry.source ?? (await read(entry.url))
          })

reproduce

Workaround

          const converter = v8toIstanbul(entry.url, 0, {
            source: entry.source ?? ts.transpile(await read(entry.url), compileOptions, entry.url)
          })

workaround

@loynoir loynoir changed the title Current deno coverage implement is not compatible with istanbul Current deno coverage interface is not compatible with istanbul Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant