test(aio): fix testing of `NgPackagesInstaller` (#19655)

PR Close #19655
This commit is contained in:
George Kalpakas 2017-10-07 00:25:27 +03:00 committed by Tobias Bosch
parent 97969a85cd
commit 62c7b7842b
4 changed files with 56 additions and 38 deletions

View File

@ -43,7 +43,7 @@
"docs-watch": "node tools/transforms/authors-package/watchr.js",
"docs-lint": "eslint --ignore-path=\"tools/transforms/.eslintignore\" tools/transforms",
"docs-test": "node tools/transforms/test.js",
"tools-test": "./scripts/deploy-to-firebase.test.sh && yarn docs-test && yarn boilerplate:test && jasmine tools/ng-packages-installer.spec.js",
"tools-test": "./scripts/deploy-to-firebase.test.sh && yarn docs-test && yarn boilerplate:test && jasmine tools/ng-packages-installer/index.spec.js",
"serve-and-sync": "concurrently --kill-others \"yarn docs-watch\" \"yarn start\"",
"boilerplate:add": "node ./tools/examples/example-boilerplate add",
"boilerplate:remove": "node ./tools/examples/example-boilerplate remove",

View File

@ -7,7 +7,6 @@ const shelljs = require('shelljs');
const yargs = require('yargs');
const PACKAGE_JSON = 'package.json';
const LOCKFILE = 'yarn.lock';
const LOCAL_MARKER_PATH = 'node_modules/_local_.json';
const PACKAGE_JSON_REGEX = /^[^/]+\/package\.json$/;
@ -122,13 +121,14 @@ class NgPackagesInstaller {
const sourcePackage = packages[key];
if (sourcePackage) {
// point the core Angular packages at the distributable folder
mergedDependencies[key] = `file:${ANGULAR_DIST_PACKAGES}/${key.replace('@angular/', '')}`;
mergedDependencies[key] = `file:${sourcePackage.parentDir}/${key.replace('@angular/', '')}`;
this._log(`Overriding dependency with local package: ${key}: ${mergedDependencies[key]}`);
// grab peer dependencies
Object.keys(sourcePackage.peerDependencies || {})
const sourcePackagePeerDeps = sourcePackage.config.peerDependencies || {};
Object.keys(sourcePackagePeerDeps)
// ignore peerDependencies which are already core Angular packages
.filter(key => !packages[key])
.forEach(key => peerDependencies[key] = sourcePackage.peerDependencies[key]);
.forEach(key => peerDependencies[key] = sourcePackagePeerDeps[key]);
}
});
return [mergedDependencies, peerDependencies];
@ -140,20 +140,25 @@ class NgPackagesInstaller {
*/
_getDistPackages() {
const packageConfigs = Object.create(null);
this._log(`Angular distributable directory: ${ANGULAR_DIST_PACKAGES}.`);
[ANGULAR_DIST_PACKAGES].forEach(distDir => {
this._log(`Angular distributable directory: ${distDir}.`);
shelljs
.find(ANGULAR_DIST_PACKAGES)
.map(filePath => filePath.slice(ANGULAR_DIST_PACKAGES.length + 1))
.find(distDir)
.map(filePath => filePath.slice(distDir.length + 1))
.filter(filePath => PACKAGE_JSON_REGEX.test(filePath))
.forEach(packagePath => {
const packageName = `@angular/${packagePath.slice(0, -PACKAGE_JSON.length -1)}`;
if (this.ignorePackages.indexOf(packageName) === -1) {
const packageConfig = require(path.resolve(ANGULAR_DIST_PACKAGES, packagePath));
packageConfigs[packageName] = packageConfig;
const packageConfig = require(path.resolve(distDir, packagePath));
packageConfigs[packageName] = {parentDir: distDir, config: packageConfig};
} else {
this._log('Ignoring package', packageName);
}
});
});
this._log('Found the following Angular distributables:', Object.keys(packageConfigs).map(key => `\n - ${key}`));
return packageConfigs;
}

View File

@ -12,6 +12,7 @@ describe('NgPackagesInstaller', () => {
const nodeModulesDir = path.resolve(absoluteRootDir, 'node_modules');
const packageJsonPath = path.resolve(absoluteRootDir, 'package.json');
const packagesDir = path.resolve(path.resolve(__dirname, '../../../dist/packages-dist'));
const toolsDir = path.resolve(path.resolve(__dirname, '../../../dist/tools/@angular'));
let installer;
beforeEach(() => {
@ -53,10 +54,10 @@ describe('NgPackagesInstaller', () => {
// These are the packages that are "found" in the dist directory
dummyNgPackages = {
'@angular/core': { peerDependencies: { rxjs: '5.0.1' } },
'@angular/common': { peerDependencies: { '@angular/core': '4.4.1' } },
'@angular/compiler': { },
'@angular/compiler-cli': { peerDependencies: { typescript: '^2.4.2', '@angular/compiler': '4.3.2' } }
'@angular/core': { parentDir: packagesDir, config: { peerDependencies: { rxjs: '5.0.1' } } },
'@angular/common': { parentDir: packagesDir, config: { peerDependencies: { '@angular/core': '4.4.1' } } },
'@angular/compiler': { parentDir: packagesDir, config: { } },
'@angular/compiler-cli': { parentDir: toolsDir, config: { peerDependencies: { typescript: '^2.4.2', '@angular/compiler': '4.3.2' } } }
};
spyOn(installer, '_getDistPackages').and.returnValue(dummyNgPackages);
@ -82,7 +83,7 @@ describe('NgPackagesInstaller', () => {
'@angular/common': `file:${packagesDir}/common`
},
devDependencies: {
'@angular/compiler-cli': `file:${packagesDir}/compiler-cli`,
'@angular/compiler-cli': `file:${toolsDir}/compiler-cli`,
rxjs: '5.0.1',
typescript: '^2.4.2'
},
@ -154,14 +155,27 @@ describe('NgPackagesInstaller', () => {
describe('_getDistPackages', () => {
it('should include top level Angular packages', () => {
const ngPackages = installer._getDistPackages();
const expectedValue = jasmine.objectContaining({
parentDir: jasmine.any(String),
config: jasmine.any(Object),
});
// For example...
expect(ngPackages['@angular/common']).toBeDefined();
expect(ngPackages['@angular/core']).toBeDefined();
expect(ngPackages['@angular/router']).toBeDefined();
expect(ngPackages['@angular/upgrade']).toBeDefined();
expect(ngPackages['@angular/common']).toEqual(expectedValue);
expect(ngPackages['@angular/core']).toEqual(expectedValue);
expect(ngPackages['@angular/router']).toEqual(expectedValue);
expect(ngPackages['@angular/upgrade']).toEqual(expectedValue);
expect(ngPackages['@angular/upgrade/static']).not.toBeDefined();
});
it('should store each package\'s parent directory', () => {
const ngPackages = installer._getDistPackages();
// For example...
expect(ngPackages['@angular/core'].parentDir).toBe(packagesDir);
expect(ngPackages['@angular/router'].parentDir).toBeDefined(toolsDir);
});
it('should not include packages that have been ignored', () => {
installer = new NgPackagesInstaller(rootDir, { ignorePackages: ['@angular/router'] });
@ -171,7 +185,6 @@ describe('NgPackagesInstaller', () => {
expect(ngPackages['@angular/router']).toBeUndefined();
});
});
});
describe('_log()', () => {
beforeEach(() => {

View File

@ -41,12 +41,12 @@ if [[ ${CI_MODE:-} == "aio" ]]; then
fi
# Build the Angular packages then exit (no further build required)
if [[ ${CI_MODE:-} == "aio_e2e" ]]; then
travisFoldStart "build.aio_e2e"
if [[ ${CI_MODE:-} == "aio_e2e" || ${CI_MODE:-} == "aio_tools_test" ]]; then
travisFoldStart "build.$CI_MODE"
(
./build.sh
)
travisFoldEnd "build.aio_e2e"
travisFoldEnd "build.$CI_MODE"
exit 0;
fi