From 7d8efe323bf3fe0e4a0d94a25d2c862e59417f44 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Tue, 6 Apr 2021 15:21:35 +0100 Subject: [PATCH] test(ngcc): provide correct source-mappings for renderer tests (#41434) The recent update to MagicString, results in a different basic set of mappings in the renderer. This change updates our tests to match. PR Close #41434 --- .../ngcc/test/rendering/renderer_spec.ts | 87 ++++++++++++++++--- 1 file changed, 77 insertions(+), 10 deletions(-) diff --git a/packages/compiler-cli/ngcc/test/rendering/renderer_spec.ts b/packages/compiler-cli/ngcc/test/rendering/renderer_spec.ts index 5ea2e0ce07..b369880b55 100644 --- a/packages/compiler-cli/ngcc/test/rendering/renderer_spec.ts +++ b/packages/compiler-cli/ngcc/test/rendering/renderer_spec.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ import {Statement} from '@angular/compiler'; -import {fromObject, generateMapFileComment, SourceMapConverter} from 'convert-source-map'; +import {fromObject, fromSource, generateMapFileComment, SourceMapConverter} from 'convert-source-map'; import MagicString from 'magic-string'; import {encode, SourceMapMappings} from 'sourcemap-codec'; import * as ts from 'typescript'; @@ -201,19 +201,84 @@ runInEachFileSystem(() => { 'file': 'file.js', 'sources': ['file.js'], 'names': [], - 'mappings': encode([[], [], [], [], [], [], [], [], [], [], [], [], [[0, 0, 0, 0]]]), + 'mappings': encode([ + [], + [], + [], + [], + [], + [], + [], + [], + [], + [], + [], + [], + [[0, 0, 0, 0]], + [[0, 0, 1, 0]], + [[0, 0, 2, 0]], + [[0, 0, 3, 0]], + [[0, 0, 4, 0]], + [[0, 0, 5, 0]], + [[0, 0, 6, 0]], + [[0, 0, 7, 0]], + [[0, 0, 8, 0]] + ]), 'sourcesContent': [JS_CONTENT.contents], }); - const MERGED_OUTPUT_PROGRAM_MAPPINGS: SourceMapMappings = - [[], [], [], [], [], [], [], [], [], [], [], [], ...JS_CONTENT_MAPPINGS]; - MERGED_OUTPUT_PROGRAM_MAP = fromObject({ 'version': 3, 'file': 'file.js', 'sources': ['file.ts'], 'names': [], - 'mappings': encode(MERGED_OUTPUT_PROGRAM_MAPPINGS), + 'mappings': encode([ + [], + [], + [], + [], + [], + [], + [], + [], + [], + [], + [], + [], + [ + [0, 0, 0, 0], [7, 0, 0, 7], [9, 0, 0, 8], [18, 0, 0, 17], [20, 0, 0, 18], + [26, 0, 0, 24], [41, 0, 0, 39], [42, 0, 0, 40] + ], + [ + [0, 0, 2, 0], [4, 0, 2, 13], [5, 0, 2, 14], [8, 0, 2, 0], [14, 0, 2, 13], [15, 0, 2, 14] + ], + [[0, 0, 2, 16], [4, 0, 3, 2], [7, 0, 3, 5], [8, 0, 3, 6], [9, 0, 3, 15]], + [ + [0, 0, 3, 27], [7, 0, 3, 34], [8, 0, 3, 35], [9, 0, 3, 36], [10, 0, 3, 37], + [11, 0, 3, 38], [1, 0, 4, 1], [2, 0, 4, 1] + ], + [[0, 0, 2, 13], [1, 0, 2, 14]], + [[0, 0, 3, 3]], + [ + [0, 0, 3, 5], [2, 0, 1, 1], [11, 0, 1, 10], [12, 0, 1, 11], [14, 0, 1, 12], + [3, 0, 2, 13], [4, 0, 2, 14], [5, 0, 4, 1] + ], + [ + [0, 0, 4, 13], [5, 0, 1, 20], [7, 0, 1, 22], [12, 0, 1, 27], [14, 0, 1, 28], + [15, 0, 1, 29], [9, 0, 2, 13], [10, 0, 2, 14] + ], + [[0, 0, 4, 2]], + [], + [ + [0, 0, 0, 2], [0, 0, 0, 2], [0, 0, 0, 2], [0, 0, 0, 2], [0, 0, 0, 2], [0, 0, 0, 2], + [0, 0, 0, 2], [0, 0, 0, 2], [0, 0, 2, 2], [0, 0, 2, 2], [0, 0, 2, 2], [0, 0, 2, 2], + [0, 0, 2, 2], [0, 0, 2, 2], [0, 0, 3, 2], [0, 0, 3, 2], [0, 0, 3, 2], [0, 0, 3, 2], + [0, 0, 3, 2], [0, 0, 3, 2], [0, 0, 3, 2], [0, 0, 3, 2], [0, 0, 3, 2], [0, 0, 3, 2], + [0, 0, 4, 2], [0, 0, 4, 2], [0, 0, 2, 2], [0, 0, 2, 2], [0, 0, 1, 2], [0, 0, 1, 2], + [0, 0, 1, 2], [0, 0, 1, 2], [0, 0, 2, 2], [0, 0, 2, 2], [0, 0, 4, 2], [0, 0, 1, 2], + [0, 0, 1, 2], [0, 0, 1, 2], [0, 0, 1, 2], [0, 0, 1, 2], [0, 0, 2, 2], [0, 0, 2, 2] + ], + ]), 'sourcesContent': [TS_CONTENT.contents], }); }); @@ -226,8 +291,9 @@ runInEachFileSystem(() => { const [sourceFile, mapFile] = renderer.renderProgram( decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses); expect(sourceFile.path).toEqual(_('/node_modules/test-package/src/file.js')); - expect(sourceFile.contents) - .toEqual(RENDERED_CONTENTS + '\n' + OUTPUT_PROGRAM_MAP.toComment()); + expect(sourceFile.contents).toContain(RENDERED_CONTENTS); + expect(fromSource(sourceFile.contents)!.toObject()) + .toEqual(OUTPUT_PROGRAM_MAP.toObject()); expect(mapFile).toBeUndefined(); }); @@ -616,8 +682,9 @@ UndecoratedBase.ɵdir = /*@__PURE__*/ ɵngcc0.ɵɵdefineDirective({ type: Undeco const [sourceFile, mapFile] = renderer.renderProgram( decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses); expect(sourceFile.path).toEqual(_('/node_modules/test-package/src/file.js')); - expect(sourceFile.contents) - .toEqual(RENDERED_CONTENTS + '\n' + MERGED_OUTPUT_PROGRAM_MAP.toComment()); + expect(sourceFile.contents).toContain(RENDERED_CONTENTS); + expect(fromSource(sourceFile.contents)!.toObject()) + .toEqual(MERGED_OUTPUT_PROGRAM_MAP.toObject()); expect(mapFile).toBeUndefined(); });