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
This commit is contained in:
Pete Bacon Darwin 2021-04-06 15:21:35 +01:00 committed by Zach Arend
parent 5600df28e9
commit 7d8efe323b
1 changed files with 77 additions and 10 deletions

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {Statement} from '@angular/compiler'; 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 MagicString from 'magic-string';
import {encode, SourceMapMappings} from 'sourcemap-codec'; import {encode, SourceMapMappings} from 'sourcemap-codec';
import * as ts from 'typescript'; import * as ts from 'typescript';
@ -201,19 +201,84 @@ runInEachFileSystem(() => {
'file': 'file.js', 'file': 'file.js',
'sources': ['file.js'], 'sources': ['file.js'],
'names': [], '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], 'sourcesContent': [JS_CONTENT.contents],
}); });
const MERGED_OUTPUT_PROGRAM_MAPPINGS: SourceMapMappings =
[[], [], [], [], [], [], [], [], [], [], [], [], ...JS_CONTENT_MAPPINGS];
MERGED_OUTPUT_PROGRAM_MAP = fromObject({ MERGED_OUTPUT_PROGRAM_MAP = fromObject({
'version': 3, 'version': 3,
'file': 'file.js', 'file': 'file.js',
'sources': ['file.ts'], 'sources': ['file.ts'],
'names': [], '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], 'sourcesContent': [TS_CONTENT.contents],
}); });
}); });
@ -226,8 +291,9 @@ runInEachFileSystem(() => {
const [sourceFile, mapFile] = renderer.renderProgram( const [sourceFile, mapFile] = renderer.renderProgram(
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses); decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
expect(sourceFile.path).toEqual(_('/node_modules/test-package/src/file.js')); expect(sourceFile.path).toEqual(_('/node_modules/test-package/src/file.js'));
expect(sourceFile.contents) expect(sourceFile.contents).toContain(RENDERED_CONTENTS);
.toEqual(RENDERED_CONTENTS + '\n' + OUTPUT_PROGRAM_MAP.toComment()); expect(fromSource(sourceFile.contents)!.toObject())
.toEqual(OUTPUT_PROGRAM_MAP.toObject());
expect(mapFile).toBeUndefined(); expect(mapFile).toBeUndefined();
}); });
@ -616,8 +682,9 @@ UndecoratedBase.ɵdir = /*@__PURE__*/ ɵngcc0.ɵɵdefineDirective({ type: Undeco
const [sourceFile, mapFile] = renderer.renderProgram( const [sourceFile, mapFile] = renderer.renderProgram(
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses); decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
expect(sourceFile.path).toEqual(_('/node_modules/test-package/src/file.js')); expect(sourceFile.path).toEqual(_('/node_modules/test-package/src/file.js'));
expect(sourceFile.contents) expect(sourceFile.contents).toContain(RENDERED_CONTENTS);
.toEqual(RENDERED_CONTENTS + '\n' + MERGED_OUTPUT_PROGRAM_MAP.toComment()); expect(fromSource(sourceFile.contents)!.toObject())
.toEqual(MERGED_OUTPUT_PROGRAM_MAP.toObject());
expect(mapFile).toBeUndefined(); expect(mapFile).toBeUndefined();
}); });