File tree Expand file tree Collapse file tree 3 files changed +50
-1
lines changed Expand file tree Collapse file tree 3 files changed +50
-1
lines changed Original file line number Diff line number Diff line change 22// https://on.cypress.io/intelligent-code-completion
33/// <reference types="Cypress" />
44
5- import { add } from '../unit'
5+ import { add } from '../unit'
6+ const { fixSourcePathes } = require ( '../../utils' )
67
78context ( 'Page test' , ( ) => {
89 beforeEach ( ( ) => {
@@ -28,4 +29,33 @@ context('Unit tests', () => {
2829 it ( 'concatenates strings' , ( ) => {
2930 expect ( add ( 'foo' , 'Bar' ) ) . to . equal ( 'fooBar' )
3031 } )
32+
33+ it ( 'fixes webpack loader source-map path' , ( ) => {
34+ const coverage = {
35+ '/folder/module.js' : {
36+ inputSourceMap : {
37+ sources : [ '/folder/module.js' ]
38+ }
39+ } ,
40+ '/folder/component.vue' : {
41+ inputSourceMap : {
42+ sources : [
43+ '/folder/node_modules/cache-loader/dist/cjs.js??ref--0-0!/folder/node_modules/vue-loader/lib/index.js??vue-loader-options!/folder/component.vue?vue&type=script&lang=ts&'
44+ ]
45+ }
46+ } ,
47+ '/folder/module-without-sourcemap.js' : {
48+ path : '/folder/module-without-sourcemap.js'
49+ }
50+ }
51+
52+ fixSourcePathes ( coverage )
53+
54+ expect ( coverage [ '/folder/module.js' ] . inputSourceMap . sources )
55+ . to . deep . equal ( [ '/folder/module.js' ] )
56+ expect ( coverage [ '/folder/component.vue' ] . inputSourceMap . sources )
57+ . to . deep . equal ( [ '/folder/component.vue' ] )
58+ expect ( coverage [ '/folder/module-without-sourcemap.js' ] . path )
59+ . to . eq ( '/folder/module-without-sourcemap.js' )
60+ } )
3161} )
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ const { join } = require('path')
33const { existsSync, mkdirSync, readFileSync, writeFileSync } = require ( 'fs' )
44const execa = require ( 'execa' )
55const debug = require ( 'debug' ) ( 'code-coverage' )
6+ const { fixSourcePathes } = require ( './utils' )
67
78// these are standard folder and file names used by NYC tools
89const outputFolder = '.nyc_output'
@@ -49,6 +50,7 @@ module.exports = {
4950 * with previously collected coverage.
5051 */
5152 combineCoverage ( coverage ) {
53+ fixSourcePathes ( coverage )
5254 const previous = existsSync ( nycFilename )
5355 ? JSON . parse ( readFileSync ( nycFilename ) )
5456 : istanbul . createCoverageMap ( { } )
Original file line number Diff line number Diff line change 1+ module . exports = {
2+ /**
3+ * Remove potential Webpack loaders string and query parameters from sourcemap path
4+ */
5+ fixSourcePathes ( coverage ) {
6+ Object . keys ( coverage ) . forEach ( file => {
7+ const sourcemap = coverage [ file ] . inputSourceMap
8+ if ( ! sourcemap ) return
9+ sourcemap . sources = sourcemap . sources . map ( source => {
10+ let cleaned = source
11+ if ( cleaned . includes ( '!' ) ) cleaned = cleaned . split ( '!' ) . pop ( )
12+ if ( cleaned . includes ( '?' ) ) cleaned = cleaned . split ( '?' ) . shift ( )
13+ return cleaned
14+ } )
15+ } )
16+ }
17+ }
You can’t perform that action at this time.
0 commit comments