c8 icon indicating copy to clipboard operation
c8 copied to clipboard

feat: exclude unexpected file in sourcemap result

Open bvanjoi opened this issue 3 years ago • 11 comments

Checklist
  • [x] npm test, tests passing
  • [x] npm run test:snap (to update the snapshot)
  • [x] tests and/or benchmarks are included
Background

Sometimes we need to do coverage on the bundled code file, which contains a lot of useless code, for example node_modules.

Feature

This PR ensure useless files are remove by this.exclude.

bvanjoi avatar Jan 19 '22 08:01 bvanjoi

Such as test case in my PR, which try run c8 bundle.js, and its output only contains index.js.

If we do not exclude, the result will contains index.js and node_modules/path-exists:

image

bvanjoi avatar Jan 19 '22 08:01 bvanjoi

@bvanjoi if I'm understanding correctly, this specifically addresses the issue of 1:many source maps, where a single bundled file might expand out into a few files, some of which are excluded?

bcoe avatar Jan 24 '22 14:01 bcoe

@bvanjoi if I'm understanding correctly, this specifically addresses the issue of 1:many source maps, where a single bundled file might expand out into a few files, some of which are excluded?

Yeah, It is. Maybe I need to update snapshot.

bvanjoi avatar Jan 24 '22 14:01 bvanjoi

image

Differents node version had differents branch coverage.

  • <= 12 tag branch coverage is 0.
  • but >= 14 tag it is 100.

This is probably due to the coverage file generated by node(left is node 14, and right is node12)

image

bvanjoi avatar Feb 06 '22 10:02 bvanjoi

@bvanjoi the culprit is the between the closing } and the catch on line 55.

> code.slice(1936, 1949)
' catch (err) '

@glromeo I don't suppose any of the work you've been doing in v8-to-istanbul happens to solve this edge-case? (I don't expect it does, since the problem is mid-line).

bcoe avatar Feb 06 '22 14:02 bcoe

@bcoe I checked out @bvanjoi branch and I verified that my https://github.com/istanbuljs/v8-to-istanbul/pull/179 fixes that failing test. Also https://github.com/istanbuljs/v8-to-istanbul/pull/180 fixes that error but for a different reason (in general it goes one character short and picks the previous sourcemapped point if one is absent...which tends to happen for closing brackets)

glromeo avatar Feb 06 '22 16:02 glromeo

@bvanjoi could I bother you to update to the latest version of v8-to-istanbul on your branch, to see if it addresses some of your failing tests.

bcoe avatar Mar 23 '22 19:03 bcoe

@bvanjoi could I bother you to update to the latest version of v8-to-istanbul on your branch, to see if it addresses some of your failing tests.

I had upgrade v8-to-istanbul to 8.1.1, but it still failed in node 12, succeed in node14, node16:

image

bvanjoi avatar Mar 24 '22 14:03 bvanjoi

@bvanjoi give things a shot with the latest fixes to v8-to-istanbul?

bcoe avatar Apr 20 '22 13:04 bcoe

@bvanjoi give things a shot with the latest fixes to v8-to-istanbul?

It still had some problems in node 10 and node 12 😢

image image

bvanjoi avatar Apr 20 '22 15:04 bvanjoi

@bvanjoi, it seems like @glromeo's upstream tweaks might be necessary for this PR to work on both Node 12 and Node 10.

bcoe avatar Apr 20 '22 17:04 bcoe