test(aio): fix testing of `NgPackagesInstaller` (#19655)
PR Close #19655
This commit is contained in:
parent
97969a85cd
commit
62c7b7842b
|
@ -43,7 +43,7 @@
|
||||||
"docs-watch": "node tools/transforms/authors-package/watchr.js",
|
"docs-watch": "node tools/transforms/authors-package/watchr.js",
|
||||||
"docs-lint": "eslint --ignore-path=\"tools/transforms/.eslintignore\" tools/transforms",
|
"docs-lint": "eslint --ignore-path=\"tools/transforms/.eslintignore\" tools/transforms",
|
||||||
"docs-test": "node tools/transforms/test.js",
|
"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\"",
|
"serve-and-sync": "concurrently --kill-others \"yarn docs-watch\" \"yarn start\"",
|
||||||
"boilerplate:add": "node ./tools/examples/example-boilerplate add",
|
"boilerplate:add": "node ./tools/examples/example-boilerplate add",
|
||||||
"boilerplate:remove": "node ./tools/examples/example-boilerplate remove",
|
"boilerplate:remove": "node ./tools/examples/example-boilerplate remove",
|
||||||
|
|
|
@ -7,7 +7,6 @@ const shelljs = require('shelljs');
|
||||||
const yargs = require('yargs');
|
const yargs = require('yargs');
|
||||||
|
|
||||||
const PACKAGE_JSON = 'package.json';
|
const PACKAGE_JSON = 'package.json';
|
||||||
const LOCKFILE = 'yarn.lock';
|
|
||||||
const LOCAL_MARKER_PATH = 'node_modules/_local_.json';
|
const LOCAL_MARKER_PATH = 'node_modules/_local_.json';
|
||||||
const PACKAGE_JSON_REGEX = /^[^/]+\/package\.json$/;
|
const PACKAGE_JSON_REGEX = /^[^/]+\/package\.json$/;
|
||||||
|
|
||||||
|
@ -122,13 +121,14 @@ class NgPackagesInstaller {
|
||||||
const sourcePackage = packages[key];
|
const sourcePackage = packages[key];
|
||||||
if (sourcePackage) {
|
if (sourcePackage) {
|
||||||
// point the core Angular packages at the distributable folder
|
// 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]}`);
|
this._log(`Overriding dependency with local package: ${key}: ${mergedDependencies[key]}`);
|
||||||
// grab peer dependencies
|
// grab peer dependencies
|
||||||
Object.keys(sourcePackage.peerDependencies || {})
|
const sourcePackagePeerDeps = sourcePackage.config.peerDependencies || {};
|
||||||
|
Object.keys(sourcePackagePeerDeps)
|
||||||
// ignore peerDependencies which are already core Angular packages
|
// ignore peerDependencies which are already core Angular packages
|
||||||
.filter(key => !packages[key])
|
.filter(key => !packages[key])
|
||||||
.forEach(key => peerDependencies[key] = sourcePackage.peerDependencies[key]);
|
.forEach(key => peerDependencies[key] = sourcePackagePeerDeps[key]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return [mergedDependencies, peerDependencies];
|
return [mergedDependencies, peerDependencies];
|
||||||
|
@ -140,20 +140,25 @@ class NgPackagesInstaller {
|
||||||
*/
|
*/
|
||||||
_getDistPackages() {
|
_getDistPackages() {
|
||||||
const packageConfigs = Object.create(null);
|
const packageConfigs = Object.create(null);
|
||||||
this._log(`Angular distributable directory: ${ANGULAR_DIST_PACKAGES}.`);
|
|
||||||
shelljs
|
[ANGULAR_DIST_PACKAGES].forEach(distDir => {
|
||||||
.find(ANGULAR_DIST_PACKAGES)
|
this._log(`Angular distributable directory: ${distDir}.`);
|
||||||
.map(filePath => filePath.slice(ANGULAR_DIST_PACKAGES.length + 1))
|
shelljs
|
||||||
.filter(filePath => PACKAGE_JSON_REGEX.test(filePath))
|
.find(distDir)
|
||||||
.forEach(packagePath => {
|
.map(filePath => filePath.slice(distDir.length + 1))
|
||||||
const packageName = `@angular/${packagePath.slice(0, -PACKAGE_JSON.length -1)}`;
|
.filter(filePath => PACKAGE_JSON_REGEX.test(filePath))
|
||||||
if (this.ignorePackages.indexOf(packageName) === -1) {
|
.forEach(packagePath => {
|
||||||
const packageConfig = require(path.resolve(ANGULAR_DIST_PACKAGES, packagePath));
|
const packageName = `@angular/${packagePath.slice(0, -PACKAGE_JSON.length -1)}`;
|
||||||
packageConfigs[packageName] = packageConfig;
|
if (this.ignorePackages.indexOf(packageName) === -1) {
|
||||||
} else {
|
const packageConfig = require(path.resolve(distDir, packagePath));
|
||||||
this._log('Ignoring package', packageName);
|
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}`));
|
this._log('Found the following Angular distributables:', Object.keys(packageConfigs).map(key => `\n - ${key}`));
|
||||||
return packageConfigs;
|
return packageConfigs;
|
||||||
}
|
}
|
||||||
|
@ -244,4 +249,4 @@ function main() {
|
||||||
module.exports = NgPackagesInstaller;
|
module.exports = NgPackagesInstaller;
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
main();
|
main();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ describe('NgPackagesInstaller', () => {
|
||||||
const nodeModulesDir = path.resolve(absoluteRootDir, 'node_modules');
|
const nodeModulesDir = path.resolve(absoluteRootDir, 'node_modules');
|
||||||
const packageJsonPath = path.resolve(absoluteRootDir, 'package.json');
|
const packageJsonPath = path.resolve(absoluteRootDir, 'package.json');
|
||||||
const packagesDir = path.resolve(path.resolve(__dirname, '../../../dist/packages-dist'));
|
const packagesDir = path.resolve(path.resolve(__dirname, '../../../dist/packages-dist'));
|
||||||
|
const toolsDir = path.resolve(path.resolve(__dirname, '../../../dist/tools/@angular'));
|
||||||
let installer;
|
let installer;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -53,10 +54,10 @@ describe('NgPackagesInstaller', () => {
|
||||||
|
|
||||||
// These are the packages that are "found" in the dist directory
|
// These are the packages that are "found" in the dist directory
|
||||||
dummyNgPackages = {
|
dummyNgPackages = {
|
||||||
'@angular/core': { peerDependencies: { rxjs: '5.0.1' } },
|
'@angular/core': { parentDir: packagesDir, config: { peerDependencies: { rxjs: '5.0.1' } } },
|
||||||
'@angular/common': { peerDependencies: { '@angular/core': '4.4.1' } },
|
'@angular/common': { parentDir: packagesDir, config: { peerDependencies: { '@angular/core': '4.4.1' } } },
|
||||||
'@angular/compiler': { },
|
'@angular/compiler': { parentDir: packagesDir, config: { } },
|
||||||
'@angular/compiler-cli': { peerDependencies: { typescript: '^2.4.2', '@angular/compiler': '4.3.2' } }
|
'@angular/compiler-cli': { parentDir: toolsDir, config: { peerDependencies: { typescript: '^2.4.2', '@angular/compiler': '4.3.2' } } }
|
||||||
};
|
};
|
||||||
spyOn(installer, '_getDistPackages').and.returnValue(dummyNgPackages);
|
spyOn(installer, '_getDistPackages').and.returnValue(dummyNgPackages);
|
||||||
|
|
||||||
|
@ -82,7 +83,7 @@ describe('NgPackagesInstaller', () => {
|
||||||
'@angular/common': `file:${packagesDir}/common`
|
'@angular/common': `file:${packagesDir}/common`
|
||||||
},
|
},
|
||||||
devDependencies: {
|
devDependencies: {
|
||||||
'@angular/compiler-cli': `file:${packagesDir}/compiler-cli`,
|
'@angular/compiler-cli': `file:${toolsDir}/compiler-cli`,
|
||||||
rxjs: '5.0.1',
|
rxjs: '5.0.1',
|
||||||
typescript: '^2.4.2'
|
typescript: '^2.4.2'
|
||||||
},
|
},
|
||||||
|
@ -154,22 +155,34 @@ describe('NgPackagesInstaller', () => {
|
||||||
describe('_getDistPackages', () => {
|
describe('_getDistPackages', () => {
|
||||||
it('should include top level Angular packages', () => {
|
it('should include top level Angular packages', () => {
|
||||||
const ngPackages = installer._getDistPackages();
|
const ngPackages = installer._getDistPackages();
|
||||||
|
const expectedValue = jasmine.objectContaining({
|
||||||
|
parentDir: jasmine.any(String),
|
||||||
|
config: jasmine.any(Object),
|
||||||
|
});
|
||||||
|
|
||||||
// For example...
|
// For example...
|
||||||
expect(ngPackages['@angular/common']).toBeDefined();
|
expect(ngPackages['@angular/common']).toEqual(expectedValue);
|
||||||
expect(ngPackages['@angular/core']).toBeDefined();
|
expect(ngPackages['@angular/core']).toEqual(expectedValue);
|
||||||
expect(ngPackages['@angular/router']).toBeDefined();
|
expect(ngPackages['@angular/router']).toEqual(expectedValue);
|
||||||
expect(ngPackages['@angular/upgrade']).toBeDefined();
|
expect(ngPackages['@angular/upgrade']).toEqual(expectedValue);
|
||||||
|
|
||||||
expect(ngPackages['@angular/upgrade/static']).not.toBeDefined();
|
expect(ngPackages['@angular/upgrade/static']).not.toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
it('should not include packages that have been ignored', () => {
|
it('should store each package\'s parent directory', () => {
|
||||||
installer = new NgPackagesInstaller(rootDir, { ignorePackages: ['@angular/router'] });
|
const ngPackages = installer._getDistPackages();
|
||||||
const ngPackages = installer._getDistPackages();
|
|
||||||
|
|
||||||
expect(ngPackages['@angular/common']).toBeDefined();
|
// For example...
|
||||||
expect(ngPackages['@angular/router']).toBeUndefined();
|
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'] });
|
||||||
|
const ngPackages = installer._getDistPackages();
|
||||||
|
|
||||||
|
expect(ngPackages['@angular/common']).toBeDefined();
|
||||||
|
expect(ngPackages['@angular/router']).toBeUndefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -41,12 +41,12 @@ if [[ ${CI_MODE:-} == "aio" ]]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Build the Angular packages then exit (no further build required)
|
# Build the Angular packages then exit (no further build required)
|
||||||
if [[ ${CI_MODE:-} == "aio_e2e" ]]; then
|
if [[ ${CI_MODE:-} == "aio_e2e" || ${CI_MODE:-} == "aio_tools_test" ]]; then
|
||||||
travisFoldStart "build.aio_e2e"
|
travisFoldStart "build.$CI_MODE"
|
||||||
(
|
(
|
||||||
./build.sh
|
./build.sh
|
||||||
)
|
)
|
||||||
travisFoldEnd "build.aio_e2e"
|
travisFoldEnd "build.$CI_MODE"
|
||||||
exit 0;
|
exit 0;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue