From debbfe570810d9b37b3c209d2fc9a8d8834794a8 Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Thu, 21 Dec 2023 13:32:59 -0800 Subject: [PATCH] chore(lavapack): comment out unused test & harness --- packages/lavapack/test/sourcemaps.spec.js | 151 +++++++++++----------- 1 file changed, 74 insertions(+), 77 deletions(-) diff --git a/packages/lavapack/test/sourcemaps.spec.js b/packages/lavapack/test/sourcemaps.spec.js index 40dd86a541..23f4d62ac9 100644 --- a/packages/lavapack/test/sourcemaps.spec.js +++ b/packages/lavapack/test/sourcemaps.spec.js @@ -5,85 +5,82 @@ const test = require('ava') // const UglifyJS = require('uglify-js') // const { SourceMapConsumer } = require('source-map') -test.skip('sourcemaps - adjust maps for wrapper', async (t) => { - const { wrapIntoModuleInitializer } = require('../src/sourcemaps') - const fooSource = ` - var two = 1 + 1 - throw new Error('Boom') - var three = two + 1 - ` +test.todo('sourcemaps - adjust maps for wrapper') +// test('sourcemaps - adjust maps for wrapper', async (t) => { +// const { wrapIntoModuleInitializer } = require('../src/sourcemaps') +// const fooSource = ` +// var two = 1 + 1 +// throw new Error('Boom') +// var three = two + 1 +// ` +// // eslint-disable-next-line no-undef +// const result = UglifyJS.minify( +// { './foo.js': fooSource }, +// { +// // skip logical compression like removing unused stuff +// compress: false, +// sourceMap: { +// filename: './foo.js', +// // inline sourcemaps with sources included +// url: 'inline', +// includeSources: true, +// }, +// } +// ) +// if (result.error) { +// t.ifError(result.error) +// } +// // ensure minification worked +// t.true(indicesOf('\n', fooSource).length > 1) +// t.is(indicesOf('\n', result.code).length, 1) +// // wrap into bundle with external sourcemaps +// const wrappedSourceMeta = wrapIntoModuleInitializer(result.code) +// await validateSourcemaps(t, wrappedSourceMeta) +// }) - // eslint-disable-next-line no-undef - const result = UglifyJS.minify( - { './foo.js': fooSource }, - { - // skip logical compression like removing unused stuff - compress: false, - sourceMap: { - filename: './foo.js', - // inline sourcemaps with sources included - url: 'inline', - includeSources: true, - }, - } - ) +// function indicesOf(substring, string) { +// const result = [] +// let index = -1 +// while ((index = string.indexOf(substring, index + 1)) >= 0) { +// result.push(index) +// } +// return result +// } - if (result.error) { - t.ifError(result.error) - } +// // this is not perfecct - just a heuristic +// async function validateSourcemaps(t, sourceMeta) { +// const targetSlug = 'new Error' +// // eslint-disable-next-line no-undef +// const consumer = await new SourceMapConsumer(sourceMeta.maps) +// t.true(consumer.hasContentsOfAllSources(), 'has the contents of all sources') - // ensure minification worked - t.true(indicesOf('\n', fooSource).length > 1) - t.is(indicesOf('\n', result.code).length, 1) +// const sourceLines = sourceMeta.code.split('\n') - // wrap into bundle with external sourcemaps - const wrappedSourceMeta = wrapIntoModuleInitializer(result.code) - await validateSourcemaps(t, wrappedSourceMeta) -}) +// sourceLines +// .map((line) => indicesOf(targetSlug, line)) +// .forEach((errorIndices, lineIndex) => { +// // if (errorIndex === null) return console.log('line does not contain "new Error"') +// errorIndices.forEach((errorIndex) => { +// const position = { line: lineIndex + 1, column: errorIndex } +// const result = consumer.originalPositionFor(position) +// if (!result.source) { +// t.fail(`missing source for position: ${JSON.stringify(position)}`) +// t.log('=======') +// t.log(contentForPosition(sourceLines, position)) +// t.log('=======') +// return +// } +// const sourceContent = consumer.sourceContentFor(result.source) +// const sourceLines = sourceContent.split('\n') +// const line = sourceLines[result.line - 1] +// if (!line.includes(targetSlug)) { +// t.fail(`could not find target "${targetSlug}" in source`) +// } +// }) +// }) +// t.true(true, 'sourcemaps look ok') +// } -function indicesOf(substring, string) { - const result = [] - let index = -1 - while ((index = string.indexOf(substring, index + 1)) >= 0) { - result.push(index) - } - return result -} - -// this is not perfecct - just a heuristic -async function validateSourcemaps(t, sourceMeta) { - const targetSlug = 'new Error' - // eslint-disable-next-line no-undef - const consumer = await new SourceMapConsumer(sourceMeta.maps) - t.true(consumer.hasContentsOfAllSources(), 'has the contents of all sources') - - const sourceLines = sourceMeta.code.split('\n') - - sourceLines - .map((line) => indicesOf(targetSlug, line)) - .forEach((errorIndices, lineIndex) => { - // if (errorIndex === null) return console.log('line does not contain "new Error"') - errorIndices.forEach((errorIndex) => { - const position = { line: lineIndex + 1, column: errorIndex } - const result = consumer.originalPositionFor(position) - if (!result.source) { - t.fail(`missing source for position: ${JSON.stringify(position)}`) - t.log('=======') - t.log(contentForPosition(sourceLines, position)) - t.log('=======') - return - } - const sourceContent = consumer.sourceContentFor(result.source) - const sourceLines = sourceContent.split('\n') - const line = sourceLines[result.line - 1] - if (!line.includes(targetSlug)) { - t.fail(`could not find target "${targetSlug}" in source`) - } - }) - }) - t.true(true, 'sourcemaps look ok') -} - -function contentForPosition(sourceLines, position) { - return sourceLines[position.line - 1].slice(position.column) -} +// function contentForPosition(sourceLines, position) { +// return sourceLines[position.line - 1].slice(position.column) +// }