Skip to content

Commit

Permalink
chore: add test for empty sourcesContent
Browse files Browse the repository at this point in the history
Refs: #1053
  • Loading branch information
subzero10 committed Apr 26, 2023
1 parent 586c0f5 commit 2c1354f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/rollup-plugin/src/rollupUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function isSourcemap(file: OutputAsset | OutputChunk): file is OutputAsset {
const source = typeof file.source === 'string' ? file.source : file.source.toString()
const json = JSON.parse(source)

return json.sourcesContent && json.sourcesContent.length > 0
return !!json.sourcesContent && json.sourcesContent.length > 0
}

function isNotIgnored(sourceMapInfo: SourcemapInfo, ignorePaths: Array<string | RegExp>) {
Expand Down
13 changes: 10 additions & 3 deletions packages/rollup-plugin/test/fixtures/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const assets = {
fileName: 'index.js.map',
name: undefined,
source: '{"version":3,"file":"index.js","sources":["../src/index.js"],"sourcesContent":["import foo from \'./foo.js\';\\nimport bar from \'./subfolder/bar.js\'\\n\\nexport default function () {\\n console.log(foo)\\n console.log(bar)\\n}"],"names":[],"mappings":";;;;;AAGe,cAAQ,IAAI;AAC3B,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,EAAC;AAClB,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,EAAC;AAClB;;;;"}',
type: 'asset' as const,
type: 'asset' as const,
needsCodeReference: false
},
'subfolder/bar.js.map': {
Expand All @@ -126,8 +126,15 @@ const assets = {
source: '{"version":3,"file":"foo.js","sources":["../src/foo.js"],"sourcesContent":["export default \'hello world!\'"],"names":[],"mappings":";;AAAA,UAAe;;;;"}',
type: 'asset' as const,
needsCodeReference: false
},
'empty.js.map': {
fileName: 'empty.js.map',
name: undefined,
source: '{"version":3,"file":"empty.js","sources":[], "sourcesContent": [], "names":[],"mappings":""}',
type: 'asset' as const,
needsCodeReference: false
}
}
}


export default { ...chunks, ...assets }
export default { ...chunks, ...assets }
22 changes: 22 additions & 0 deletions packages/rollup-plugin/test/rollupUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,28 @@ describe('extractSourcemapDataFromBundle', () => {
])
})
}

it('should ignore files with empty sourcesContent', () => {
expect(bundle).to.include.keys(['empty.js.map'])
expect(bundle['empty.js.map']).to.deep.equal({
fileName: 'empty.js.map',
name: undefined,
source: '{"version":3,"file":"empty.js","sources":[], "sourcesContent": [], "names":[],"mappings":""}',
type: 'asset' as const,
needsCodeReference: false,
})

const data = extractSourcemapDataFromBundle(outputOptions, bundle, [])
expect(data).to.be.an('array').lengthOf(3)
expect(data).to.not.have.deep.members([
{
sourcemapFilename: 'empty.js.map',
sourcemapFilePath: path.resolve('dist/empty.js.map'),
jsFilename: 'empty.js',
jsFilePath: path.resolve('dist/empty.js')
},
])
})
})

describe('isNonProdEnv', () => {
Expand Down

0 comments on commit 2c1354f

Please sign in to comment.