From 1f3b840b23ce615a252239c7ccc8a019ed57c9f5 Mon Sep 17 00:00:00 2001 From: Sebastian Alex Date: Fri, 8 Dec 2023 11:25:14 +0100 Subject: [PATCH 1/4] sourcemap-tools: add force and more results to add sources --- tools/sourcemap-tools/src/SourceProcessor.ts | 52 ++++++++++++++++--- .../tests/SourceProcessor.spec.ts | 23 ++++++-- 2 files changed, 62 insertions(+), 13 deletions(-) diff --git a/tools/sourcemap-tools/src/SourceProcessor.ts b/tools/sourcemap-tools/src/SourceProcessor.ts index a372c42d..89e00a28 100644 --- a/tools/sourcemap-tools/src/SourceProcessor.ts +++ b/tools/sourcemap-tools/src/SourceProcessor.ts @@ -18,6 +18,25 @@ export interface ProcessResultWithPaths extends ProcessResult { readonly sourceMapPath: string; } +export interface AddSourcesResult { + readonly sourceMap: RawSourceMap; + + /** + * Source paths that were successfully added. + */ + readonly succeeded: string[]; + + /** + * Source paths that failed to read, but source content was already in the sourcemap. + */ + readonly skipped: string[]; + + /** + * Source paths that failed to read and the sources content was not in the sourcemap. + */ + readonly failed: string[]; +} + export class SourceProcessor { constructor(private readonly _debugIdGenerator: DebugIdGenerator) {} @@ -223,7 +242,8 @@ export class SourceProcessor { public async addSourcesToSourceMap( sourceMap: string | RawSourceMap, sourceMapPath: string, - ): ResultPromise { + force: boolean, + ): ResultPromise { if (typeof sourceMap === 'string') { const parseResult = parseJSON(sourceMap); if (parseResult.isErr()) { @@ -236,19 +256,35 @@ export class SourceProcessor { ? path.resolve(path.dirname(sourceMapPath), sourceMap.sourceRoot) : path.resolve(path.dirname(sourceMapPath)); - const sourcesContent: string[] = []; - for (const sourcePath of sourceMap.sources) { + const succeeded: string[] = []; + const skipped: string[] = []; + const failed: string[] = []; + + const sourcesContent: string[] = sourceMap.sourcesContent ?? []; + for (let i = 0; i < sourceMap.sources.length; i++) { + const sourcePath = sourceMap.sources[i]; + if (sourcesContent[i] && !force) { + skipped.push(sourcePath); + continue; + } + const readResult = await readFile(path.resolve(sourceRoot, sourcePath)); if (readResult.isErr()) { - return readResult; + failed.push(sourcePath); + } else { + sourcesContent[i] = readResult.data; + succeeded.push(sourcePath); } - - sourcesContent.push(readResult.data); } return Ok({ - ...sourceMap, - sourcesContent, + sourceMap: { + ...sourceMap, + sourcesContent, + }, + succeeded, + skipped, + failed, }); } diff --git a/tools/sourcemap-tools/tests/SourceProcessor.spec.ts b/tools/sourcemap-tools/tests/SourceProcessor.spec.ts index 744acea4..f69c8113 100644 --- a/tools/sourcemap-tools/tests/SourceProcessor.spec.ts +++ b/tools/sourcemap-tools/tests/SourceProcessor.spec.ts @@ -303,13 +303,26 @@ function foo(){console.log("Hello World!")}foo();`; const sourceMapContent = await fs.promises.readFile(sourceMapPath, 'utf-8'); const sourceProcessor = new SourceProcessor(new DebugIdGenerator()); - const result = await sourceProcessor.addSourcesToSourceMap(sourceMapContent, sourceMapPath); + const result = await sourceProcessor.addSourcesToSourceMap(sourceMapContent, sourceMapPath, false); assert(result.isOk()); - expect(result.data.sourcesContent).toEqual([sourceContent]); + expect(result.data.sourceMap.sourcesContent).toEqual([sourceContent]); }); - it('should overwrite sources in source map', async () => { + it('should not overwrite sources in source map when force is false', async () => { + const sourceMapPath = path.join(__dirname, './testFiles/source.js.map'); + + const sourceMapContent = JSON.parse(await fs.promises.readFile(sourceMapPath, 'utf-8')) as RawSourceMap; + sourceMapContent.sourcesContent = ['abc']; + + const sourceProcessor = new SourceProcessor(new DebugIdGenerator()); + const result = await sourceProcessor.addSourcesToSourceMap(sourceMapContent, sourceMapPath, false); + assert(result.isOk()); + + expect(result.data.sourceMap.sourcesContent).toEqual(['abc']); + }); + + it('should overwrite sources in source map when force is true', async () => { const originalSourcePath = path.join(__dirname, './testFiles/source.ts'); const sourceMapPath = path.join(__dirname, './testFiles/source.js.map'); @@ -318,10 +331,10 @@ function foo(){console.log("Hello World!")}foo();`; sourceMapContent.sourcesContent = ['abc']; const sourceProcessor = new SourceProcessor(new DebugIdGenerator()); - const result = await sourceProcessor.addSourcesToSourceMap(sourceMapContent, sourceMapPath); + const result = await sourceProcessor.addSourcesToSourceMap(sourceMapContent, sourceMapPath, true); assert(result.isOk()); - expect(result.data.sourcesContent).toEqual([sourceContent]); + expect(result.data.sourceMap.sourcesContent).toEqual([sourceContent]); }); }); From b429a39f7a828733e54f6bb0a783067e52ba242d Mon Sep 17 00:00:00 2001 From: Sebastian Alex Date: Fri, 8 Dec 2023 11:26:41 +0100 Subject: [PATCH 2/4] cli: add overload to logAsset and rename it to createAssetLogger --- tools/cli/src/helpers/logs.ts | 33 ++++++++++++++++--------- tools/cli/src/sourcemaps/add-sources.ts | 7 +++--- tools/cli/src/sourcemaps/process.ts | 4 +-- tools/cli/src/sourcemaps/run.ts | 8 +++--- tools/cli/src/sourcemaps/upload.ts | 8 +++--- 5 files changed, 36 insertions(+), 24 deletions(-) diff --git a/tools/cli/src/helpers/logs.ts b/tools/cli/src/helpers/logs.ts index c3374c67..8315bdf3 100644 --- a/tools/cli/src/helpers/logs.ts +++ b/tools/cli/src/helpers/logs.ts @@ -2,19 +2,30 @@ import { Asset, log, LogLevel, ProcessAssetResult } from '@backtrace/sourcemap-t import { CliLogger } from '../logger'; import { SourceAndSourceMapPaths } from '../models/Asset'; -export function logAsset(logger: CliLogger, level: LogLevel) { - const logFn = log(logger, level); +export function createAssetLogger( + logger: CliLogger, +): (level: LogLevel) => (message: string | ((t: T) => string)) => (asset: T) => T; +export function createAssetLogger( + logger: CliLogger, + level: LogLevel, +): (message: string | ((t: T) => string)) => (asset: T) => T; +export function createAssetLogger(logger: CliLogger, level?: LogLevel) { + function logAsset(level: LogLevel) { + const logFn = log(logger, level); - return function logAsset(message: string | ((t: T) => string)) { - return function logAsset(asset: T) { - return logFn( - (t) => - `${'name' in t ? t.name : t.asset.name}: ${ - typeof message === 'function' ? message(asset) : message - }`, - )(asset); + return function logAsset(message: string | ((t: T) => string)) { + return function logAsset(asset: T) { + return logFn( + (t) => + `${'name' in t ? t.name : t.asset.name}: ${ + typeof message === 'function' ? message(asset) : message + }`, + )(asset); + }; }; - }; + } + + return level ? logAsset(level) : logAsset; } export const logAssets = diff --git a/tools/cli/src/sourcemaps/add-sources.ts b/tools/cli/src/sourcemaps/add-sources.ts index c2756272..279b4ef9 100644 --- a/tools/cli/src/sourcemaps/add-sources.ts +++ b/tools/cli/src/sourcemaps/add-sources.ts @@ -27,7 +27,7 @@ import { Command, CommandContext } from '../commands/Command'; import { readSourceMapFromPathOrFromSource, toAsset, writeAsset } from '../helpers/common'; import { ErrorBehaviors, filterBehaviorSkippedElements, getErrorBehavior, handleError } from '../helpers/errorBehavior'; import { buildIncludeExclude, file2Or1FromTuple, findTuples } from '../helpers/find'; -import { logAsset } from '../helpers/logs'; +import { createAssetLogger } from '../helpers/logs'; import { normalizePaths, relativePaths } from '../helpers/normalizePaths'; import { CliLogger } from '../logger'; import { findConfig, loadOptionsForCommand } from '../options/loadOptions'; @@ -123,8 +123,9 @@ export async function addSourcesToSourcemaps({ opts, logger, getHelpMessage }: C const logDebug = log(logger, 'debug'); const logTrace = log(logger, 'trace'); - const logDebugAsset = logAsset(logger, 'debug'); - const logTraceAsset = logAsset(logger, 'trace'); + const logAsset = createAssetLogger(logger); + const logDebugAsset = logAsset('debug'); + const logTraceAsset = logAsset('trace'); const assetErrorBehaviorResult = getErrorBehavior(opts['asset-error-behavior'] ?? 'exit'); if (assetErrorBehaviorResult.isErr()) { diff --git a/tools/cli/src/sourcemaps/process.ts b/tools/cli/src/sourcemaps/process.ts index b0cdb60a..4d2c9bfa 100644 --- a/tools/cli/src/sourcemaps/process.ts +++ b/tools/cli/src/sourcemaps/process.ts @@ -26,7 +26,7 @@ import { Command, CommandContext } from '../commands/Command'; import { readSourceAndSourceMap, toSourceAndSourceMapPaths, writeSourceAndSourceMap } from '../helpers/common'; import { ErrorBehaviors, filterBehaviorSkippedElements, getErrorBehavior, handleError } from '../helpers/errorBehavior'; import { buildIncludeExclude, findTuples } from '../helpers/find'; -import { logAsset, logAssets } from '../helpers/logs'; +import { createAssetLogger, logAssets } from '../helpers/logs'; import { normalizePaths, relativePaths } from '../helpers/normalizePaths'; import { CliLogger } from '../logger'; import { SourceAndSourceMapPaths } from '../models/Asset'; @@ -135,7 +135,7 @@ export async function processSources({ opts, logger, getHelpMessage }: CommandCo const handleFailedAsset = handleError(assetErrorBehavior); const logAssetBehaviorError = (asset: Asset) => (err: string, level: LogLevel) => - logAsset(logger, level)(err)(asset); + createAssetLogger(logger, level)(err)(asset); const processAssetCommand = (asset: SourceAndSourceMapPaths) => pipe( diff --git a/tools/cli/src/sourcemaps/run.ts b/tools/cli/src/sourcemaps/run.ts index 0dc1a814..b4fbbe14 100644 --- a/tools/cli/src/sourcemaps/run.ts +++ b/tools/cli/src/sourcemaps/run.ts @@ -37,7 +37,7 @@ import { } from '../helpers/common'; import { ErrorBehaviors, filterBehaviorSkippedElements, getErrorBehavior, handleError } from '../helpers/errorBehavior'; import { buildIncludeExclude, findTuples } from '../helpers/find'; -import { logAsset, logAssets } from '../helpers/logs'; +import { createAssetLogger, logAssets } from '../helpers/logs'; import { normalizePaths, relativePaths } from '../helpers/normalizePaths'; import { SourceAndSourceMapPaths } from '../models/Asset'; import { findConfig, joinOptions, loadOptions } from '../options/loadOptions'; @@ -225,8 +225,8 @@ export async function runSourcemapCommands({ opts, logger, getHelpMessage }: Com const logInfo = log(logger, 'info'); const logDebug = log(logger, 'debug'); const logTrace = log(logger, 'trace'); - const logDebugAsset = logAsset(logger, 'trace'); - const logTraceAsset = logAsset(logger, 'trace'); + const logDebugAsset = createAssetLogger(logger, 'trace'); + const logTraceAsset = createAssetLogger(logger, 'trace'); const logDebugAssets = logAssets(logger, 'debug'); const logTraceAssets = logAssets(logger, 'trace'); @@ -241,7 +241,7 @@ export async function runSourcemapCommands({ opts, logger, getHelpMessage }: Com const handleFailedAsset = handleError(assetErrorBehavior); const logAssetBehaviorError = (asset: Asset) => (err: string, level: LogLevel) => - logAsset(logger, level)(err)(asset); + createAssetLogger(logger, level)(err)(asset); const readAssetCommand = (asset: SourceAndSourceMapPaths) => pipe( diff --git a/tools/cli/src/sourcemaps/upload.ts b/tools/cli/src/sourcemaps/upload.ts index e76c2855..52b8858a 100644 --- a/tools/cli/src/sourcemaps/upload.ts +++ b/tools/cli/src/sourcemaps/upload.ts @@ -37,7 +37,7 @@ import { Command, CommandContext } from '../commands/Command'; import { isAssetProcessed, readSourceMapFromPathOrFromSource, toAsset, uniqueBy, validateUrl } from '../helpers/common'; import { ErrorBehaviors, filterBehaviorSkippedElements, getErrorBehavior, handleError } from '../helpers/errorBehavior'; import { buildIncludeExclude, file2Or1FromTuple, findTuples } from '../helpers/find'; -import { logAsset } from '../helpers/logs'; +import { createAssetLogger } from '../helpers/logs'; import { normalizePaths, relativePaths } from '../helpers/normalizePaths'; import { CliLogger } from '../logger'; import { findConfig, loadOptionsForCommand } from '../options/loadOptions'; @@ -196,8 +196,8 @@ export async function uploadSourcemaps({ opts, logger, getHelpMessage }: Command const logDebug = log(logger, 'debug'); const logTrace = log(logger, 'trace'); - const logDebugAsset = logAsset(logger, 'debug'); - const logTraceAsset = logAsset(logger, 'trace'); + const logDebugAsset = createAssetLogger(logger, 'debug'); + const logTraceAsset = createAssetLogger(logger, 'trace'); const assetErrorBehaviorResult = getErrorBehavior(opts['asset-error-behavior'] ?? 'exit'); if (assetErrorBehaviorResult.isErr()) { @@ -210,7 +210,7 @@ export async function uploadSourcemaps({ opts, logger, getHelpMessage }: Command const handleFailedAsset = handleError(assetErrorBehavior); const logAssetBehaviorError = (asset: Asset) => (err: string, level: LogLevel) => - logAsset(logger, level)(err)(asset); + createAssetLogger(logger, level)(err)(asset); const isAssetProcessedCommand = (asset: AssetWithContent) => pipe( From bb1017ad69012fc7b643d864cf719e70ac49d294 Mon Sep 17 00:00:00 2001 From: Sebastian Alex Date: Fri, 8 Dec 2023 11:26:55 +0100 Subject: [PATCH 3/4] cli: add helper methods to errorBehavior --- tools/cli/src/helpers/errorBehavior.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/cli/src/helpers/errorBehavior.ts b/tools/cli/src/helpers/errorBehavior.ts index e86ddc3f..6b5fe3bf 100644 --- a/tools/cli/src/helpers/errorBehavior.ts +++ b/tools/cli/src/helpers/errorBehavior.ts @@ -1,4 +1,4 @@ -import { Err, Ok, Result, ResultErr } from '@backtrace/sourcemap-tools'; +import { Err, LogLevel, Ok, Result, ResultErr } from '@backtrace/sourcemap-tools'; export const ErrorBehaviors = { exit: 'exit', @@ -52,3 +52,17 @@ export function filterBehaviorSkippedElements(asset: Array !(typeof a === 'object' && !!a && 'reason' in a && a.reason instanceof ResultErr), ) as T[]; } + +export function isFatal(behavior: ErrorBehavior) { + return behavior === 'exit'; +} + +export function shouldLog(behavior: ErrorBehavior): behavior is LogLevel { + switch (behavior) { + case 'exit': + case 'skip': + return false; + default: + return true; + } +} From 3b0f06678f15162904c4a9441121439f1476b8c9 Mon Sep 17 00:00:00 2001 From: Sebastian Alex Date: Fri, 8 Dec 2023 11:27:22 +0100 Subject: [PATCH 4/4] cli: process addSources result with behavior --- tools/cli/src/sourcemaps/add-sources.ts | 80 ++++++++++++++++--- .../cli/tests/sourcemaps/add-sources.spec.ts | 35 ++++++-- tools/cli/tests/sourcemaps/run.spec.ts | 9 ++- 3 files changed, 104 insertions(+), 20 deletions(-) diff --git a/tools/cli/src/sourcemaps/add-sources.ts b/tools/cli/src/sourcemaps/add-sources.ts index 279b4ef9..26d0f05d 100644 --- a/tools/cli/src/sourcemaps/add-sources.ts +++ b/tools/cli/src/sourcemaps/add-sources.ts @@ -1,4 +1,5 @@ import { + AddSourcesResult, Asset, AssetWithContent, DebugIdGenerator, @@ -18,6 +19,7 @@ import { pipe, R, RawSourceMap, + Result, ResultPromise, SourceProcessor, } from '@backtrace/sourcemap-tools'; @@ -25,7 +27,15 @@ import path from 'path'; import { GlobalOptions } from '..'; import { Command, CommandContext } from '../commands/Command'; import { readSourceMapFromPathOrFromSource, toAsset, writeAsset } from '../helpers/common'; -import { ErrorBehaviors, filterBehaviorSkippedElements, getErrorBehavior, handleError } from '../helpers/errorBehavior'; +import { + ErrorBehavior, + ErrorBehaviors, + filterBehaviorSkippedElements, + getErrorBehavior, + handleError, + isFatal, + shouldLog, +} from '../helpers/errorBehavior'; import { buildIncludeExclude, file2Or1FromTuple, findTuples } from '../helpers/find'; import { createAssetLogger } from '../helpers/logs'; import { normalizePaths, relativePaths } from '../helpers/normalizePaths'; @@ -41,6 +51,11 @@ export interface AddSourcesOptions extends GlobalOptions { readonly skipFailing: boolean; readonly 'pass-with-no-files': boolean; readonly 'asset-error-behavior': string; + readonly 'source-error-behavior': string; +} + +interface AssetAddSourcesResult extends AssetWithContent { + readonly result: AddSourcesResult; } export const addSourcesCmd = new Command({ @@ -86,6 +101,13 @@ export const addSourcesCmd = new Command({ type: String, description: `What to do when an asset fails. Can be one of: ${Object.keys(ErrorBehaviors).join(', ')}.`, }) + .option({ + name: 'source-error-behavior', + type: String, + description: `What to do when reading sourcepath fails. Can be one of: ${Object.keys(ErrorBehaviors).join( + ', ', + )}.`, + }) .option({ name: 'pass-with-no-files', type: Boolean, @@ -135,10 +157,46 @@ export async function addSourcesToSourcemaps({ opts, logger, getHelpMessage }: C const assetErrorBehavior = assetErrorBehaviorResult.data; + const sourceErrorBehaviorResult = getErrorBehavior(opts['source-error-behavior'] ?? 'warn'); + if (sourceErrorBehaviorResult.isErr()) { + logger.info(getHelpMessage()); + return sourceErrorBehaviorResult; + } + + const sourceErrorBehavior = sourceErrorBehaviorResult.data; + const handleFailedAsset = handleError(assetErrorBehavior); const logAssetBehaviorError = (asset: Asset) => (err: string, level: LogLevel) => - logAsset(logger, level)(err)(asset); + createAssetLogger(logger, level)(err)(asset); + + const processAssetResult = + (behavior: ErrorBehavior) => + (result: AssetAddSourcesResult): Result => { + const { succeeded, skipped, failed } = result.result; + if (failed.length) { + if (isFatal(behavior)) { + return Err( + `failed to find source for ${failed[0]}` + + (failed.length > 1 ? ` (and ${failed.length} more)` : ''), + ); + } else if (shouldLog(behavior)) { + for (const path of failed) { + logAsset(behavior)(`failed to find source for ${path}`)(result); + } + } + } + + for (const path of skipped) { + logDebugAsset(`skipped source for ${path}`)(result); + } + + for (const path of succeeded) { + logTraceAsset(`added source for ${path}`)(result); + } + + return Ok(result); + }; const addSourcesCommand = (asset: Asset) => pipe( @@ -148,6 +206,7 @@ export async function addSourcesToSourcemaps({ opts, logger, getHelpMessage }: C R.map(logDebugAsset('read sourcemap')), R.map(logTraceAsset('adding source')), R.map(addSourceToSourceMap(opts.force ?? false)), + R.map(processAssetResult(sourceErrorBehavior)), R.map(logDebugAsset('source added')), R.map( opts['dry-run'] @@ -193,19 +252,14 @@ export async function addSourcesToSourcemaps({ opts, logger, getHelpMessage }: C export function addSourceToSourceMap(force: boolean) { const sourceProcessor = new SourceProcessor(new DebugIdGenerator()); - const hasSources = (asset: AssetWithContent): asset is AssetWithContent => - sourceProcessor.doesSourceMapHaveSources(asset.content); - return async function addSourceToSourceMap( asset: AssetWithContent, - ): ResultPromise, string> { - return !hasSources(asset) || force - ? pipe( - asset, - (asset) => sourceProcessor.addSourcesToSourceMap(asset.content, asset.path), - R.map((content) => ({ ...asset, content } as AssetWithContent)), - ) - : Ok(asset); + ): ResultPromise { + return pipe( + asset, + (asset) => sourceProcessor.addSourcesToSourceMap(asset.content, asset.path, force), + R.map((result) => ({ ...asset, content: result.sourceMap, result })), + ); }; } diff --git a/tools/cli/tests/sourcemaps/add-sources.spec.ts b/tools/cli/tests/sourcemaps/add-sources.spec.ts index cca975bb..49a2a143 100644 --- a/tools/cli/tests/sourcemaps/add-sources.spec.ts +++ b/tools/cli/tests/sourcemaps/add-sources.spec.ts @@ -7,6 +7,10 @@ import { expectAllKeysToChange, filterKeys, getHelpMessage } from '../_helpers/c import { expectHashesToChange, hashEachFile, hashFiles, withWorkingCopy } from '../_helpers/testFiles'; describe('add-sources', () => { + beforeEach(() => { + jest.clearAllMocks(); + }); + describe('returning value', () => { it( 'should return processed sourcemaps', @@ -79,7 +83,7 @@ describe('add-sources', () => { const files = await glob(`${workingDir}/*.js.map`); for (const file of files) { - expect(spy).toBeCalledWith(expect.anything(), file); + expect(spy).toBeCalledWith(expect.anything(), file, expect.any(Boolean)); } }), ); @@ -167,7 +171,7 @@ describe('add-sources', () => { const files = await glob(`${workingDir}/*.js.map`); for (const file of files) { - expect(spy).toBeCalledWith(expect.anything(), file); + expect(spy).toBeCalledWith(expect.anything(), file, expect.any(Boolean)); } }), ); @@ -226,7 +230,7 @@ describe('add-sources', () => { const files = await glob(`${workingDir}/*.js.map`); for (const file of files) { - expect(spy).toBeCalledWith(expect.anything(), file); + expect(spy).toBeCalledWith(expect.anything(), file, expect.any(Boolean)); } }), ); @@ -266,6 +270,7 @@ describe('add-sources', () => { getHelpMessage, opts: { path: workingDir, + 'source-error-behavior': 'exit', }, }); @@ -286,6 +291,7 @@ describe('add-sources', () => { getHelpMessage, opts: { path: [workingDir], + 'source-error-behavior': 'exit', }, }); @@ -309,6 +315,7 @@ describe('add-sources', () => { getHelpMessage, opts: { path: [workingDir], + 'source-error-behavior': 'exit', }, }); @@ -336,6 +343,22 @@ describe('add-sources', () => { }), ); + it( + 'should not fail with source-error-behavior=skip', + withWorkingCopy('invalid', async (workingDir) => { + const result = await addSourcesToSourcemaps({ + logger: new CliLogger({ level: 'output', silent: true }), + getHelpMessage, + opts: { + path: workingDir, + 'source-error-behavior': 'skip', + }, + }); + + assert(result.isOk(), result.data as string); + }), + ); + it( 'should modify valid sourcemaps in place with asset-error-behavior=skip', withWorkingCopy(['invalid', 'original'], async (workingDir) => { @@ -390,7 +413,7 @@ describe('add-sources', () => { const files = await glob(`${workingDir}/*.js.map`); for (const file of files) { - expect(spy).toBeCalledWith(expect.anything(), file); + expect(spy).toBeCalledWith(expect.anything(), file, expect.any(Boolean)); } }), ); @@ -449,7 +472,7 @@ describe('add-sources', () => { const files = await glob(`${workingDir}/*.js.map`); for (const file of files) { - expect(spy).toBeCalledWith(expect.anything(), file); + expect(spy).toBeCalledWith(expect.anything(), file, expect.any(Boolean)); } }), ); @@ -514,7 +537,7 @@ describe('add-sources', () => { const files = await glob(`${workingDir}/*.js.map`); for (const file of files) { - expect(spy).toBeCalledWith(expect.anything(), file); + expect(spy).toBeCalledWith(expect.anything(), file, expect.any(Boolean)); } }), ); diff --git a/tools/cli/tests/sourcemaps/run.spec.ts b/tools/cli/tests/sourcemaps/run.spec.ts index 4fa3c52a..5331e680 100644 --- a/tools/cli/tests/sourcemaps/run.spec.ts +++ b/tools/cli/tests/sourcemaps/run.spec.ts @@ -257,7 +257,14 @@ describe('run', () => { type InnerAddSources = ReturnType; const innerAddSources = jest .fn, Parameters>() - .mockImplementation((asset) => Promise.resolve(Ok(asset))); + .mockImplementation((asset) => + Promise.resolve( + Ok({ + ...asset, + result: { sourceMap: {} as never, succeeded: [], skipped: [], failed: [] }, + }), + ), + ); const addSourcesSpy = jest .spyOn(addSourcesCmd, 'addSourceToSourceMap')