From 1660b34e2d40b7f546c704137011f7cf247d0292 Mon Sep 17 00:00:00 2001 From: Alan Date: Tue, 30 Apr 2019 10:18:20 +0200 Subject: [PATCH] test: fix several bazel compiler-cli tests in windows (#30189) ``` //packages/compiler-cli/integrationtest:integrationtest //packages/compiler-cli/test/compliance:compliance ``` Partially addresses #29785 PR Close #30189 --- .codefresh/codefresh.yml | 1 + .../integrationtest/test_helpers.js | 11 +++------- packages/compiler/test/aot/test_util.ts | 21 ++++++++++++------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/.codefresh/codefresh.yml b/.codefresh/codefresh.yml index 67e3648bc6..7316835c66 100644 --- a/.codefresh/codefresh.yml +++ b/.codefresh/codefresh.yml @@ -23,3 +23,4 @@ steps: - yarn bazel test //tools/ts-api-guardian:all //packages/language-service/test - 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 diff --git a/packages/compiler-cli/integrationtest/test_helpers.js b/packages/compiler-cli/integrationtest/test_helpers.js index 3e8123211b..295c94633c 100644 --- a/packages/compiler-cli/integrationtest/test_helpers.js +++ b/packages/compiler-cli/integrationtest/test_helpers.js @@ -98,13 +98,8 @@ function symlinkNodeModules() { Object.keys(requiredNodeModules).forEach(importName => { const outputPath = path.join(tmpDir, 'node_modules', importName); const moduleDir = requiredNodeModules[importName]; - - findFilesWithinDirectory(moduleDir).forEach(filePath => { - const outputFilePath = path.join(outputPath, path.relative(moduleDir, filePath)); - - shx.mkdir('-p', path.dirname(outputFilePath)); - fs.symlinkSync(filePath, outputFilePath); - }); + shx.mkdir('-p', path.dirname(outputPath)); + fs.symlinkSync(moduleDir, outputPath, 'junction'); }); } @@ -162,5 +157,5 @@ function resolveNpmTreeArtifact(manifestPath, resolveFile = 'package.json') { /** Finds all files within a specified directory. */ function findFilesWithinDirectory(directoryPath) { - return shx.find(directoryPath).filter(filePath => !fs.statSync(filePath).isDirectory()); + return shx.find(directoryPath).filter(filePath => !fs.lstatSync(filePath).isDirectory()); } diff --git a/packages/compiler/test/aot/test_util.ts b/packages/compiler/test/aot/test_util.ts index bd1b416821..dad5d13b67 100644 --- a/packages/compiler/test/aot/test_util.ts +++ b/packages/compiler/test/aot/test_util.ts @@ -576,8 +576,8 @@ function readBazelWrittenFilesFrom( function processDirectory(dir: string, dest: string) { const entries = fs.readdirSync(dir); for (const name of entries) { - const fullName = path.join(dir, name); - const destName = path.join(dest, name); + const fullName = path.posix.join(dir, name); + const destName = path.posix.join(dest, name); const stat = fs.statSync(fullName); if (!skip(name, fullName)) { if (stat.isDirectory()) { @@ -590,11 +590,11 @@ function readBazelWrittenFilesFrom( } } try { - processDirectory(bazelPackageRoot, path.join('/node_modules/@angular', packageName)); + processDirectory(bazelPackageRoot, path.posix.join('/node_modules/@angular', packageName)); // todo: check why we always need an index.d.ts if (fs.existsSync(path.join(bazelPackageRoot, `${packageName}.d.ts`))) { const content = fs.readFileSync(path.join(bazelPackageRoot, `${packageName}.d.ts`), 'utf8'); - map.set(path.join('/node_modules/@angular', packageName, 'index.d.ts'), content); + map.set(path.posix.join('/node_modules/@angular', packageName, 'index.d.ts'), content); } } catch (e) { console.error( @@ -632,24 +632,25 @@ export function setup(options: { if (options.compileAngular) { // If this fails please add //packages/core:npm_package as a test data dependency. readBazelWrittenFilesFrom( - path.join(sources, 'angular/packages/core/npm_package'), 'core', angularFiles, + resolveNpmTreeArtifact('angular/packages/core/npm_package'), 'core', angularFiles, skipDirs); } if (options.compileFakeCore) { readBazelWrittenFilesFrom( - path.join(sources, 'angular/packages/compiler-cli/test/ngtsc/fake_core/npm_package'), + resolveNpmTreeArtifact( + 'angular/packages/compiler-cli/test/ngtsc/fake_core/npm_package'), 'core', angularFiles, skipDirs); } if (options.compileAnimations) { // If this fails please add //packages/animations:npm_package as a test data dependency. readBazelWrittenFilesFrom( - path.join(sources, 'angular/packages/animations/npm_package'), 'animations', + resolveNpmTreeArtifact('angular/packages/animations/npm_package'), 'animations', angularFiles, skipDirs); } if (options.compileCommon) { // If this fails please add //packages/common:npm_package as a test data dependency. readBazelWrittenFilesFrom( - path.join(sources, 'angular/packages/common/npm_package'), 'common', angularFiles, + resolveNpmTreeArtifact('angular/packages/common/npm_package'), 'common', angularFiles, skipDirs); } return; @@ -750,6 +751,10 @@ function isSourceOrDts(fileName: string): boolean { return /\.ts$/.test(fileName); } +function resolveNpmTreeArtifact(manifestPath: string, resolveFile = 'package.json') { + return path.dirname(require.resolve(path.posix.join(manifestPath, resolveFile))); +} + export function compile( rootDirs: MockData, options: { emit?: boolean,