From 1bd4891c9a9562f467c8d4679739f1a77c65ebb9 Mon Sep 17 00:00:00 2001 From: Alan Date: Tue, 30 Apr 2019 14:06:02 +0200 Subject: [PATCH] test: fix ngcc unit tests in windows (#30297) ``` //packages/compiler-cli/ngcc/test:test ``` Partially addresses #29785 PR Close #30297 --- .codefresh/codefresh.yml | 4 +--- packages/compiler-cli/ngcc/src/rendering/renderer.ts | 10 +++++++--- .../ngcc/test/dependencies/esm_dependency_host_spec.ts | 2 +- .../ngcc/test/packages/entry_point_spec.ts | 2 +- .../ngcc/test/writing/in_place_file_writer_spec.ts | 7 ++++--- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/.codefresh/codefresh.yml b/.codefresh/codefresh.yml index 2032ec4c5d..fd74b0f32f 100644 --- a/.codefresh/codefresh.yml +++ b/.codefresh/codefresh.yml @@ -20,7 +20,5 @@ steps: # Add Bazel CI config - copy .codefresh\bazel.rc %ProgramData%\bazel.bazelrc # Run tests - - yarn bazel test //tools/ts-api-guardian:all //packages/language-service/test //packages/compiler/test //packages/compiler-cli/test:ngc //packages/compiler-cli/test/ngtsc:ngtsc - yarn test-ivy-aot //packages/animations/test //packages/common/test //packages/forms/test //packages/http/test //packages/platform-browser/test //packages/platform-browser-dynamic/test //packages/router/test - - yarn bazel test //tools/public_api_guard/... - - yarn bazel test //packages/compiler-cli/integrationtest:integrationtest //packages/compiler-cli/test/compliance:compliance + - yarn bazel test //tools/ts-api-guardian:all //tools/public_api_guard/... //packages/language-service/test //packages/compiler-cli/ngcc/test:test //packages/compiler-cli/integrationtest:integrationtest //packages/compiler-cli/test/compliance:compliance //packages/compiler/test //packages/compiler-cli/test:ngc //packages/compiler-cli/test/ngtsc:ngtsc diff --git a/packages/compiler-cli/ngcc/src/rendering/renderer.ts b/packages/compiler-cli/ngcc/src/rendering/renderer.ts index 911a8aac75..b1410eed1a 100644 --- a/packages/compiler-cli/ngcc/src/rendering/renderer.ts +++ b/packages/compiler-cli/ngcc/src/rendering/renderer.ts @@ -173,7 +173,7 @@ export abstract class Renderer { renderDtsFile(dtsFile: ts.SourceFile, renderInfo: DtsRenderInfo): FileInfo[] { const input = this.extractSourceMap(dtsFile); const outputText = new MagicString(input.source); - const printer = ts.createPrinter(); + const printer = createPrinter(); const importManager = new ImportManager( this.getImportRewriter(this.bundle.dts !.r3SymbolsFile, false), IMPORT_PREFIX); @@ -476,7 +476,7 @@ export function mergeSourceMaps( */ export function renderConstantPool( sourceFile: ts.SourceFile, constantPool: ConstantPool, imports: ImportManager): string { - const printer = ts.createPrinter(); + const printer = createPrinter(); return constantPool.statements .map(stmt => translateStatement(stmt, imports, NOOP_DEFAULT_IMPORT_RECORDER)) .map(stmt => printer.printNode(ts.EmitHint.Unspecified, stmt, sourceFile)) @@ -493,7 +493,7 @@ export function renderConstantPool( */ export function renderDefinitions( sourceFile: ts.SourceFile, compiledClass: CompiledClass, imports: ImportManager): string { - const printer = ts.createPrinter(); + const printer = createPrinter(); const name = compiledClass.declaration.name; const translate = (stmt: Statement) => translateStatement(stmt, imports, NOOP_DEFAULT_IMPORT_RECORDER); @@ -529,3 +529,7 @@ function getImportString( const importAs = importPath ? importManager.generateNamedImport(importPath, importName) : null; return importAs ? `${importAs.moduleImport}.${importAs.symbol}` : `${importName}`; } + +function createPrinter(): ts.Printer { + return ts.createPrinter({newLine: ts.NewLineKind.LineFeed}); +} \ No newline at end of file diff --git a/packages/compiler-cli/ngcc/test/dependencies/esm_dependency_host_spec.ts b/packages/compiler-cli/ngcc/test/dependencies/esm_dependency_host_spec.ts index bea7dc250f..0d10e82da0 100644 --- a/packages/compiler-cli/ngcc/test/dependencies/esm_dependency_host_spec.ts +++ b/packages/compiler-cli/ngcc/test/dependencies/esm_dependency_host_spec.ts @@ -70,7 +70,7 @@ describe('DependencyHost', () => { expect(dependencies.size).toBe(0); expect(missing.size).toBe(0); expect(deepImports.size).toBe(1); - expect(deepImports.has('/node_modules/lib-1/deep/import')).toBe(true); + expect(deepImports.has(_('/node_modules/lib-1/deep/import'))).toBe(true); }); it('should recurse into internal dependencies', () => { diff --git a/packages/compiler-cli/ngcc/test/packages/entry_point_spec.ts b/packages/compiler-cli/ngcc/test/packages/entry_point_spec.ts index 375fa013ac..c921fb38c2 100644 --- a/packages/compiler-cli/ngcc/test/packages/entry_point_spec.ts +++ b/packages/compiler-cli/ngcc/test/packages/entry_point_spec.ts @@ -12,7 +12,7 @@ import {getEntryPointInfo} from '../../src/packages/entry_point'; import {MockFileSystem} from '../helpers/mock_file_system'; import {MockLogger} from '../helpers/mock_logger'; -const _ = AbsoluteFsPath.fromUnchecked; +const _ = AbsoluteFsPath.from; describe('getEntryPointInfo()', () => { const SOME_PACKAGE = _('/some_package'); diff --git a/packages/compiler-cli/ngcc/test/writing/in_place_file_writer_spec.ts b/packages/compiler-cli/ngcc/test/writing/in_place_file_writer_spec.ts index f3c13a01db..7e4ba0619a 100644 --- a/packages/compiler-cli/ngcc/test/writing/in_place_file_writer_spec.ts +++ b/packages/compiler-cli/ngcc/test/writing/in_place_file_writer_spec.ts @@ -11,7 +11,7 @@ import {EntryPointBundle} from '../../src/packages/entry_point_bundle'; import {InPlaceFileWriter} from '../../src/writing/in_place_file_writer'; import {MockFileSystem} from '../helpers/mock_file_system'; -const _ = AbsoluteFsPath.fromUnchecked; +const _ = AbsoluteFsPath.from; function createMockFileSystem() { return new MockFileSystem({ @@ -71,13 +71,14 @@ describe('InPlaceFileWriter', () => { it('should error if the backup file already exists', () => { const fs = createMockFileSystem(); const fileWriter = new InPlaceFileWriter(fs); + const absoluteBackupPath = _('/package/path/already-backed-up.js'); expect( () => fileWriter.writeBundle( {} as EntryPoint, {} as EntryPointBundle, [ - {path: _('/package/path/already-backed-up.js'), contents: 'MODIFIED BACKED UP'}, + {path: absoluteBackupPath, contents: 'MODIFIED BACKED UP'}, ])) .toThrowError( - 'Tried to overwrite /package/path/already-backed-up.js.__ivy_ngcc_bak with an ngcc back up file, which is disallowed.'); + `Tried to overwrite ${absoluteBackupPath}.__ivy_ngcc_bak with an ngcc back up file, which is disallowed.`); }); });