From 744b0205e27b0c6e0645c244b524af59c5c0abac Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Fri, 25 Jan 2019 19:50:08 +0100 Subject: [PATCH] build: fix failing compiler-cli tests on windows (#28352) Note that this fixes `compiler-cli` tests within `compiler-cli/test`, but there seem to be remaining `ngcc` tests within `compiler-cli/src` which aren't working on Windows. This is out-of-scope for this commit. PR Close #28352 --- .../compiler-cli/test/diagnostics/mocks.ts | 6 +- packages/compiler-cli/test/ngc_spec.ts | 3 +- .../compiler-cli/test/ngtools_api_spec.ts | 4 +- .../compiler-cli/test/perform_watch_spec.ts | 7 +- .../test/transformers/program_spec.ts | 138 +++++++++++------- 5 files changed, 96 insertions(+), 62 deletions(-) diff --git a/packages/compiler-cli/test/diagnostics/mocks.ts b/packages/compiler-cli/test/diagnostics/mocks.ts index a81388d06d..64046cec2c 100644 --- a/packages/compiler-cli/test/diagnostics/mocks.ts +++ b/packages/compiler-cli/test/diagnostics/mocks.ts @@ -75,11 +75,11 @@ export class MockLanguageServiceHost implements ts.LanguageServiceHost { private internalReadFile(fileName: string): string|undefined { let basename = path.basename(fileName); if (/^lib.*\.d\.ts$/.test(basename)) { - let libPath = path.dirname(ts.getDefaultLibFilePath(this.getCompilationSettings())); - fileName = path.join(libPath, basename); + let libPath = path.posix.dirname(ts.getDefaultLibFilePath(this.getCompilationSettings())); + fileName = path.posix.join(libPath, basename); } if (fileName.startsWith('app/')) { - fileName = path.join(this.context.currentDirectory, fileName); + fileName = path.posix.join(this.context.currentDirectory, fileName); } if (this.context.fileExists(fileName)) { return this.context.readFile(fileName); diff --git a/packages/compiler-cli/test/ngc_spec.ts b/packages/compiler-cli/test/ngc_spec.ts index 98ae216d48..89d388cf0f 100644 --- a/packages/compiler-cli/test/ngc_spec.ts +++ b/packages/compiler-cli/test/ngc_spec.ts @@ -54,6 +54,7 @@ describe('ngc transformer command-line', () => { "baseUrl": ".", "declaration": true, "target": "es5", + "newLine": "lf", "module": "es2015", "moduleResolution": "node", "lib": ["es6", "dom"], @@ -102,7 +103,7 @@ describe('ngc transformer command-line', () => { const exitCode = main(['-p', basePath], errorSpy); expect(errorSpy).toHaveBeenCalledWith( - `error TS6053: File '` + path.join(basePath, 'test.ts') + `' not found.` + + `error TS6053: File '` + path.posix.join(basePath, 'test.ts') + `' not found.` + '\n'); expect(exitCode).toEqual(1); }); diff --git a/packages/compiler-cli/test/ngtools_api_spec.ts b/packages/compiler-cli/test/ngtools_api_spec.ts index 3fd3832659..63ce319c17 100644 --- a/packages/compiler-cli/test/ngtools_api_spec.ts +++ b/packages/compiler-cli/test/ngtools_api_spec.ts @@ -70,8 +70,8 @@ describe('ngtools_api (deprecated)', () => { entryModule: 'src/main#MainModule', }); expect(routes).toEqual({ - './child#ChildModule': path.resolve(testSupport.basePath, 'src/child.ts'), - './child2#ChildModule2': path.resolve(testSupport.basePath, 'src/child2.ts'), + './child#ChildModule': path.posix.join(testSupport.basePath, 'src/child.ts'), + './child2#ChildModule2': path.posix.join(testSupport.basePath, 'src/child2.ts'), }); }); diff --git a/packages/compiler-cli/test/perform_watch_spec.ts b/packages/compiler-cli/test/perform_watch_spec.ts index 76de99d25f..d40531418c 100644 --- a/packages/compiler-cli/test/perform_watch_spec.ts +++ b/packages/compiler-cli/test/perform_watch_spec.ts @@ -71,9 +71,10 @@ describe('perform watch', () => { `, }); - const mainTsPath = path.resolve(testSupport.basePath, 'src', 'main.ts'); - const utilTsPath = path.resolve(testSupport.basePath, 'src', 'util.ts'); - const mainNgFactory = path.resolve(outDir, 'src', 'main.ngfactory.js'); + const mainTsPath = path.posix.join(testSupport.basePath, 'src', 'main.ts'); + const utilTsPath = path.posix.join(testSupport.basePath, 'src', 'util.ts'); + const mainNgFactory = path.posix.join(outDir, 'src', 'main.ngfactory.js'); + performWatchCompilation(host); expect(fs.existsSync(mainNgFactory)).toBe(true); expect(fileExistsSpy !).toHaveBeenCalledWith(mainTsPath); diff --git a/packages/compiler-cli/test/transformers/program_spec.ts b/packages/compiler-cli/test/transformers/program_spec.ts index 951b1ffbd1..94db5e3542 100644 --- a/packages/compiler-cli/test/transformers/program_spec.ts +++ b/packages/compiler-cli/test/transformers/program_spec.ts @@ -14,8 +14,8 @@ import * as ts from 'typescript'; import {formatDiagnostics} from '../../src/perform_compile'; import {CompilerHost, EmitFlags, LazyRoute} from '../../src/transformers/api'; import {checkVersion, createSrcToOutPathMapper} from '../../src/transformers/program'; -import {GENERATED_FILES, StructureIsReused, tsStructureIsReused} from '../../src/transformers/util'; -import {TestSupport, expectNoDiagnosticsInProgram, isInBazel, setup} from '../test_support'; +import {StructureIsReused, tsStructureIsReused} from '../../src/transformers/util'; +import {TestSupport, expectNoDiagnosticsInProgram, setup} from '../test_support'; describe('ng program', () => { let testSupport: TestSupport; @@ -53,7 +53,7 @@ describe('ng program', () => { expectNoDiagnosticsInProgram(options, program); fs.symlinkSync( path.resolve(testSupport.basePath, 'built', `${libName}_src`), - path.resolve(testSupport.basePath, 'node_modules', libName)); + path.resolve(testSupport.basePath, 'node_modules', libName), 'dir'); program.emit({emitFlags: ng.EmitFlags.DTS | ng.EmitFlags.JS | ng.EmitFlags.Metadata}); } @@ -214,9 +214,9 @@ describe('ng program', () => { // compile without libraries const p2 = compile(p1, options, undefined, host).program; - expect(written.has(path.resolve(testSupport.basePath, 'built/src/index.js'))).toBe(true); + expect(written.has(path.posix.join(testSupport.basePath, 'built/src/index.js'))).toBe(true); let ngFactoryContent = - written.get(path.resolve(testSupport.basePath, 'built/src/index.ngfactory.js')); + written.get(path.posix.join(testSupport.basePath, 'built/src/index.ngfactory.js')); expect(ngFactoryContent).toMatch(/Start/); // no change -> no emit @@ -226,10 +226,10 @@ describe('ng program', () => { // change a user file written.clear(); - fileCache.delete(path.resolve(testSupport.basePath, 'src/index.ts')); + fileCache.delete(path.posix.join(testSupport.basePath, 'src/index.ts')); const p4 = compile(p3, options, undefined, host).program; expect(written.size).toBe(1); - expect(written.has(path.resolve(testSupport.basePath, 'built/src/index.js'))).toBe(true); + expect(written.has(path.posix.join(testSupport.basePath, 'built/src/index.js'))).toBe(true); // change a file that is input to generated files written.clear(); @@ -237,14 +237,14 @@ describe('ng program', () => { const p5 = compile(p4, options, undefined, host).program; expect(written.size).toBe(1); ngFactoryContent = - written.get(path.resolve(testSupport.basePath, 'built/src/index.ngfactory.js')); + written.get(path.posix.join(testSupport.basePath, 'built/src/index.ngfactory.js')); expect(ngFactoryContent).toMatch(/Hello/); // change a file and create an intermediate program that is not emitted written.clear(); - fileCache.delete(path.resolve(testSupport.basePath, 'src/index.ts')); + fileCache.delete(path.posix.join(testSupport.basePath, 'src/index.ts')); const p6 = ng.createProgram({ - rootNames: [path.resolve(testSupport.basePath, 'src/index.ts')], + rootNames: [path.posix.join(testSupport.basePath, 'src/index.ts')], options: testSupport.createCompilerOptions(options), host, oldProgram: p5 }); @@ -481,10 +481,11 @@ describe('ng program', () => { const enum ShouldBe { Empty, EmptyExport, NoneEmpty } function assertGenFile( fileName: string, checks: {originalFileName: string, shouldBe: ShouldBe}) { - const writeData = written.get(path.join(testSupport.basePath, fileName)); + const writeData = written.get(path.posix.join(testSupport.basePath, fileName)); expect(writeData).toBeTruthy(); - expect(writeData !.original !.some( - sf => sf.fileName === path.join(testSupport.basePath, checks.originalFileName))) + expect( + writeData !.original !.some( + sf => sf.fileName === path.posix.join(testSupport.basePath, checks.originalFileName))) .toBe(true); switch (checks.shouldBe) { case ShouldBe.Empty: @@ -575,29 +576,30 @@ describe('ng program', () => { describe('createSrcToOutPathMapper', () => { it('should return identity mapping if no outDir is present', () => { - const mapper = createSrcToOutPathMapper(undefined, undefined, undefined); + const mapper = createSrcToOutPathMapper(undefined, undefined, undefined, path.posix); expect(mapper('/tmp/b/y.js')).toBe('/tmp/b/y.js'); }); it('should return identity mapping if first src and out fileName have same dir', () => { - const mapper = createSrcToOutPathMapper('/tmp', '/tmp/a/x.ts', '/tmp/a/x.js'); + const mapper = createSrcToOutPathMapper('/tmp', '/tmp/a/x.ts', '/tmp/a/x.js', path.posix); expect(mapper('/tmp/b/y.js')).toBe('/tmp/b/y.js'); }); it('should adjust the filename if the outDir is inside of the rootDir', () => { - const mapper = createSrcToOutPathMapper('/tmp/out', '/tmp/a/x.ts', '/tmp/out/a/x.js'); + const mapper = + createSrcToOutPathMapper('/tmp/out', '/tmp/a/x.ts', '/tmp/out/a/x.js', path.posix); expect(mapper('/tmp/b/y.js')).toBe('/tmp/out/b/y.js'); }); it('should adjust the filename if the outDir is outside of the rootDir', () => { - const mapper = createSrcToOutPathMapper('/out', '/tmp/a/x.ts', '/out/a/x.js'); + const mapper = createSrcToOutPathMapper('/out', '/tmp/a/x.ts', '/out/a/x.js', path.posix); expect(mapper('/tmp/b/y.js')).toBe('/out/b/y.js'); }); it('should adjust the filename if the common prefix of sampleSrc and sampleOut is outside of outDir', () => { - const mapper = - createSrcToOutPathMapper('/dist/common', '/src/common/x.ts', '/dist/common/x.js'); + const mapper = createSrcToOutPathMapper( + '/dist/common', '/src/common/x.ts', '/dist/common/x.js', path.posix); expect(mapper('/src/common/y.js')).toBe('/dist/common/y.js'); }); @@ -668,16 +670,23 @@ describe('ng program', () => { expectNoDiagnosticsInProgram(options, program); expect(normalizeRoutes(program.listLazyRoutes())).toEqual([ { - module: {name: 'MainModule', filePath: path.resolve(testSupport.basePath, 'src/main.ts')}, - referencedModule: - {name: 'ChildModule', filePath: path.resolve(testSupport.basePath, 'src/child.ts')}, + module: + {name: 'MainModule', filePath: path.posix.join(testSupport.basePath, 'src/main.ts')}, + referencedModule: { + name: 'ChildModule', + filePath: path.posix.join(testSupport.basePath, 'src/child.ts') + }, route: './child#ChildModule' }, { - module: - {name: 'ChildModule', filePath: path.resolve(testSupport.basePath, 'src/child.ts')}, - referencedModule: - {name: 'ChildModule2', filePath: path.resolve(testSupport.basePath, 'src/child2.ts')}, + module: { + name: 'ChildModule', + filePath: path.posix.join(testSupport.basePath, 'src/child.ts') + }, + referencedModule: { + name: 'ChildModule2', + filePath: path.posix.join(testSupport.basePath, 'src/child2.ts') + }, route: './child2#ChildModule2' }, ]); @@ -718,26 +727,37 @@ describe('ng program', () => { expectNoDiagnosticsInProgram(options, program); expect(normalizeRoutes(program.listLazyRoutes('src/main#MainModule'))).toEqual([ { - module: {name: 'MainModule', filePath: path.resolve(testSupport.basePath, 'src/main.ts')}, - referencedModule: - {name: 'ChildModule', filePath: path.resolve(testSupport.basePath, 'src/child.ts')}, + module: + {name: 'MainModule', filePath: path.posix.join(testSupport.basePath, 'src/main.ts')}, + referencedModule: { + name: 'ChildModule', + filePath: path.posix.join(testSupport.basePath, 'src/child.ts') + }, route: './child#ChildModule' }, { - module: - {name: 'ChildModule', filePath: path.resolve(testSupport.basePath, 'src/child.ts')}, - referencedModule: - {name: 'ChildModule2', filePath: path.resolve(testSupport.basePath, 'src/child2.ts')}, + module: { + name: 'ChildModule', + filePath: path.posix.join(testSupport.basePath, 'src/child.ts') + }, + referencedModule: { + name: 'ChildModule2', + filePath: path.posix.join(testSupport.basePath, 'src/child2.ts') + }, route: './child2#ChildModule2' }, ]); expect(normalizeRoutes(program.listLazyRoutes('src/child#ChildModule'))).toEqual([ { - module: - {name: 'ChildModule', filePath: path.resolve(testSupport.basePath, 'src/child.ts')}, - referencedModule: - {name: 'ChildModule2', filePath: path.resolve(testSupport.basePath, 'src/child2.ts')}, + module: { + name: 'ChildModule', + filePath: path.posix.join(testSupport.basePath, 'src/child.ts') + }, + referencedModule: { + name: 'ChildModule2', + filePath: path.posix.join(testSupport.basePath, 'src/child2.ts') + }, route: './child2#ChildModule2' }, ]); @@ -764,10 +784,11 @@ describe('ng program', () => { const {program, options} = createProgram(['src/main.ts']); expect(normalizeRoutes(program.listLazyRoutes('src/main#MainModule'))).toEqual([ { - module: {name: 'MainModule', filePath: path.resolve(testSupport.basePath, 'src/main.ts')}, + module: + {name: 'MainModule', filePath: path.posix.join(testSupport.basePath, 'src/main.ts')}, referencedModule: { name: undefined as any as string, // TODO: Review use of `any` here (#19904) - filePath: path.resolve(testSupport.basePath, 'src/child.ts') + filePath: path.posix.join(testSupport.basePath, 'src/child.ts') }, route: './child' }, @@ -816,18 +837,21 @@ describe('ng program', () => { { module: { name: 'NestedMainModule', - filePath: path.resolve(testSupport.basePath, 'src/nested/main.ts') + filePath: path.posix.join(testSupport.basePath, 'src/nested/main.ts') }, referencedModule: { name: 'NestedChildModule', - filePath: path.resolve(testSupport.basePath, 'src/nested/child.ts') + filePath: path.posix.join(testSupport.basePath, 'src/nested/child.ts') }, route: './child#NestedChildModule' }, { - module: {name: 'MainModule', filePath: path.resolve(testSupport.basePath, 'src/main.ts')}, - referencedModule: - {name: 'ChildModule', filePath: path.resolve(testSupport.basePath, 'src/child.ts')}, + module: + {name: 'MainModule', filePath: path.posix.join(testSupport.basePath, 'src/main.ts')}, + referencedModule: { + name: 'ChildModule', + filePath: path.posix.join(testSupport.basePath, 'src/child.ts') + }, route: './child#ChildModule' }, ]); @@ -853,16 +877,23 @@ describe('ng program', () => { expectNoDiagnosticsInProgram(options, program); expect(normalizeRoutes(program.listLazyRoutes('src/main#MainModule'))).toEqual([ { - module: {name: 'MainModule', filePath: path.resolve(testSupport.basePath, 'src/main.ts')}, - referencedModule: - {name: 'ChildModule', filePath: path.resolve(testSupport.basePath, 'src/child.ts')}, + module: + {name: 'MainModule', filePath: path.posix.join(testSupport.basePath, 'src/main.ts')}, + referencedModule: { + name: 'ChildModule', + filePath: path.posix.join(testSupport.basePath, 'src/child.ts') + }, route: './child#ChildModule' }, { - module: - {name: 'ChildModule', filePath: path.resolve(testSupport.basePath, 'src/child.ts')}, - referencedModule: - {name: 'ChildModule2', filePath: path.resolve(testSupport.basePath, 'src/child2.ts')}, + module: { + name: 'ChildModule', + filePath: path.posix.join(testSupport.basePath, 'src/child.ts') + }, + referencedModule: { + name: 'ChildModule2', + filePath: path.posix.join(testSupport.basePath, 'src/child2.ts') + }, route: './child2#ChildModule2' }, ]); @@ -920,9 +951,10 @@ describe('ng program', () => { }); const program = createProgram(['src/main.ts'], {collectAllErrors: true}).program; expect(normalizeRoutes(program.listLazyRoutes('src/main#MainModule'))).toEqual([{ - module: {name: 'MainModule', filePath: path.resolve(testSupport.basePath, 'src/main.ts')}, + module: + {name: 'MainModule', filePath: path.posix.join(testSupport.basePath, 'src/main.ts')}, referencedModule: - {name: 'ChildModule', filePath: path.resolve(testSupport.basePath, 'src/child.ts')}, + {name: 'ChildModule', filePath: path.posix.join(testSupport.basePath, 'src/child.ts')}, route: './child#ChildModule' }]); });