build: support running compiler-cli tests on windows (#28550)

In order to support running "compiler-cli" tests that use the "test_support.ts"
utilities on Windows with Bazel, we need to imporve the logic that resolves NPM
packages and symlinks them into a temporary directory.

A more Bazel idiomatic and windows compatible way of resolving Bazel runfiles
is to use the "RUNFILES_MANIFEST" if present. This ensures that the NPM
packages can be also symlinked on Windows, and tests can execute properly
on Windows. Read more about why this is needed here:

* https://github.com/bazelbuild/bazel/issues/3726#issue-257062364

PR Close #28550
This commit is contained in:
Paul Gschwendtner
2019-01-25 19:48:27 +01:00
committed by Matias Niemelä
parent e88d5e0df2
commit 786be967fd
4 changed files with 90 additions and 45 deletions

View File

@ -12,6 +12,7 @@ import {join} from 'path';
const Module = require('module');
import {mainNgcc} from '../../src/ngcc/src/main';
import {getAngularPackagesFromRunfiles} from '../runfile_helpers';
describe('ngcc main()', () => {
beforeEach(createMockFileSystem);
@ -40,8 +41,7 @@ describe('ngcc main()', () => {
function createMockFileSystem() {
const packagesPath = join(process.env.TEST_SRCDIR !, 'angular/packages');
mockFs({'/node_modules/@angular': loadPackages(packagesPath)});
mockFs({'/node_modules/@angular': loadAngularPackages()});
spyOn(Module, '_resolveFilename').and.callFake(mockResolve);
}
@ -50,27 +50,16 @@ function restoreRealFileSystem() {
}
/**
* Load the built Angular packages into an in-memory structure.
* @param packagesPath the path to the folder containing the built packages.
*/
function loadPackages(packagesPath: string): Directory {
/** Load the built Angular packages into an in-memory structure. */
function loadAngularPackages(): Directory {
const packagesDirectory: Directory = {};
readdirSync(packagesPath).forEach(name => {
const packagePath = join(packagesPath, name);
if (!statSync(packagePath).isDirectory()) {
return;
}
const npmPackagePath = join(packagePath, 'npm_package');
if (!existsSync(npmPackagePath)) {
return;
}
packagesDirectory[name] = loadDirectory(npmPackagePath);
});
getAngularPackagesFromRunfiles().forEach(
({name, pkgPath}) => { packagesDirectory[name] = loadDirectory(pkgPath); });
return packagesDirectory;
}
/**
* Load real files from the filesystem into an "in-memory" structure,
* which can be used with `mock-fs`.