Skip to content

test: use locally published version in E2E project setup #15052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions tests/legacy-cli/e2e/setup/015-build.ts

This file was deleted.

9 changes: 6 additions & 3 deletions tests/legacy-cli/e2e/setup/100-global-cli.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { getGlobalVariable } from '../utils/env';
import { exec, silentNpm } from '../utils/process';

const packages = require('../../../../lib/packages').packages;

export default async function() {
const argv = getGlobalVariable('argv');
if (argv.noglobal) {
return;
}

// Install global Angular CLI.
await silentNpm('install', '-g', packages['@angular/cli'].tar);
await silentNpm(
'install',
'--global',
'@angular/cli',
'--registry=http://localhost:4873',
);

try {
await exec(process.platform.startsWith('win') ? 'where' : 'which', 'ng');
Expand Down
230 changes: 11 additions & 219 deletions tests/legacy-cli/e2e/utils/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { execAndWaitForOutputToMatch, npm, silentNpm, ng, git } from './process'
import { getGlobalVariable } from './env';
import { gitCommit } from './git';
import { prerelease } from 'semver';

const packages = require('../../../../lib/packages').packages;
import { packages } from '../../../../lib/packages';


const tsConfigPath = 'tsconfig.json';
Expand Down Expand Up @@ -35,7 +34,7 @@ export function ngServe(...args: string[]) {


export async function createProject(name: string, ...args: string[]) {
const argv: any = getGlobalVariable('argv');
const argv: string[] = getGlobalVariable('argv');
const extraArgs = [];

if (argv['ivy']) {
Expand All @@ -49,9 +48,7 @@ export async function createProject(name: string, ...args: string[]) {
}

export async function prepareProjectForE2e(name) {
const argv: string[] = getGlobalVariable(
'argv',
);
const argv: string[] = getGlobalVariable('argv');

await git(
'config',
Expand All @@ -68,7 +65,7 @@ export async function prepareProjectForE2e(name) {
'commit.gpgSign',
'false',
);
await useBuiltPackages();

await useCIChrome(
'e2e',
);
Expand All @@ -81,26 +78,13 @@ export async function prepareProjectForE2e(name) {
'src',
);

await useDevKitSnapshots();
(await argv[
'ng2'
])
? useNg2()
: Promise.resolve();
(await argv[
'ng4'
])
? useNg4()
: Promise.resolve();
(await argv[
'ng-snapshots'
]) ||
argv[
'ng-tag'
]
? useSha()
: Promise.resolve();
await console.log(
if (argv['ng-snapshots'] || argv['ng-tag']) {
await useSha();
} else {
await writeFile('.npmrc', 'registry=http://localhost:4873');
}

console.log(
`Project ${name} created... Installing npm.`,
);
await silentNpm(
Expand All @@ -126,44 +110,6 @@ export async function prepareProjectForE2e(name) {
);
}


export function useDevKit(devkitRoot: string) {
return Promise.resolve()
.then(() => {
// Load the packages info for devkit.
const devkitPackages = require(devkitRoot + '/lib/packages').packages;

return updateJsonFile('package.json', json => {
if (!json['dependencies']) {
json['dependencies'] = {};
}
if (!json['devDependencies']) {
json['devDependencies'] = {};
}

for (const packageName of Object.keys(devkitPackages)) {
if (json['dependencies'].hasOwnProperty(packageName)) {
json['dependencies'][packageName] = devkitPackages[packageName].tar;
} else if (json['devDependencies'].hasOwnProperty(packageName)) {
json['devDependencies'][packageName] = devkitPackages[packageName].tar;
}
}
});
});
}

export function useDevKitSnapshots() {
return updateJsonFile('package.json', json => {
// TODO: actually add these.
// These were not working on any test that ran `npm i`.
// json['devDependencies']['@angular-devkit/build-angular'] =
// 'github:angular/angular-devkit-build-angular-builds';
// // By adding build-ng-packagr preemptively, adding a lib will not update it.
// json['devDependencies']['@angular-devkit/build-ng-packagr'] =
// 'github:angular/angular-devkit-build-ng-packagr-builds';
});
}

export function useBuiltPackages() {
return Promise.resolve()
.then(() => updateJsonFile('package.json', json => {
Expand Down Expand Up @@ -344,160 +290,6 @@ export function useCIChrome(projectDir: string) {
});
}

// Convert a Angular 5 project to Angular 2.
export function useNg2() {
const ng2Deps: any = {
'dependencies': {
'@angular/common': '^2.4.0',
'@angular/compiler': '^2.4.0',
'@angular/core': '^2.4.0',
'@angular/forms': '^2.4.0',
'@angular/http': '^2.4.0',
'@angular/platform-browser': '^2.4.0',
'@angular/platform-browser-dynamic': '^2.4.0',
'@angular/router': '^3.4.0',
'zone.js': '^0.7.4'
},
'devDependencies': {
'@angular/compiler-cli': '^2.4.0',
'@types/jasmine': '~2.2.0',
'@types/jasminewd2': undefined,
'typescript': '~2.0.0'
}
};

const tsconfigAppJson: any = {
'compilerOptions': {
'sourceMap': true,
'declaration': false,
'moduleResolution': 'node',
'emitDecoratorMetadata': true,
'experimentalDecorators': true,
'target': 'es5',
'lib': [
'es2017',
'dom'
],
'outDir': '../out-tsc/app',
'module': 'es2015',
'baseUrl': '',
'types': []
},
'exclude': [
'test.ts',
'**/*.spec.ts'
]
};

const tsconfigSpecJson: any = {
'compilerOptions': {
'sourceMap': true,
'declaration': false,
'moduleResolution': 'node',
'emitDecoratorMetadata': true,
'experimentalDecorators': true,
'lib': [
'es2017',
'dom'
],
'outDir': '../out-tsc/spec',
'module': 'commonjs',
'target': 'es5',
'baseUrl': '',
'types': [
'jasmine',
'node'
]
},
'files': [
'test.ts'
],
'include': [
'**/*.spec.ts',
'**/*.d.ts'
]
};

const tsconfigE2eJson: any = {
'compilerOptions': {
'sourceMap': true,
'declaration': false,
'moduleResolution': 'node',
'emitDecoratorMetadata': true,
'experimentalDecorators': true,
'lib': [
'es2017'
],
'outDir': '../out-tsc/e2e',
'module': 'commonjs',
'target': 'es5',
'types': [
'jasmine',
'node'
]
}
};


return Promise.resolve()
.then(() => updateJsonFile('package.json', json => {
Object.keys(ng2Deps['dependencies']).forEach(pkgName => {
json['dependencies'][pkgName] = ng2Deps['dependencies'][pkgName];
});
Object.keys(ng2Deps['devDependencies']).forEach(pkgName => {
json['devDependencies'][pkgName] = ng2Deps['devDependencies'][pkgName];
});
console.log(JSON.stringify(json));
}))
.then(() => updateJsonFile('src/tsconfig.app.json', json =>
Object.assign(json, tsconfigAppJson)))
.then(() => updateJsonFile('src/tsconfig.spec.json', json =>
Object.assign(json, tsconfigSpecJson)))
.then(() => updateJsonFile('e2e/tsconfig.e2e.json', json =>
Object.assign(json, tsconfigE2eJson)))
.then(() => replaceInFile('src/test.ts', 'import \'zone.js/dist/zone-testing\';', `
import 'zone.js/dist/long-stack-trace-zone';
import 'zone.js/dist/proxy.js';
import 'zone.js/dist/sync-test';
import 'zone.js/dist/jasmine-patch';
import 'zone.js/dist/async-test';
import 'zone.js/dist/fake-async-test';
`));
}

// Convert a Angular 5 project to Angular 4.
export function useNg4() {
const ng4Deps: any = {
'dependencies': {
'@angular/common': '^4.4.6',
'@angular/compiler': '^4.4.6',
'@angular/core': '^4.4.6',
'@angular/forms': '^4.4.6',
'@angular/http': '^4.4.6',
'@angular/platform-browser': '^4.4.6',
'@angular/platform-browser-dynamic': '^4.4.6',
'@angular/router': '^4.4.6',
'zone.js': '^0.8.14'
},
'devDependencies': {
'@angular/compiler-cli': '^4.4.6',
'typescript': '~2.3.3'
}
};


return Promise.resolve()
.then(() => updateJsonFile('package.json', json => {
Object.keys(ng4Deps['dependencies']).forEach(pkgName => {
json['dependencies'][pkgName] = ng4Deps['dependencies'][pkgName];
});
Object.keys(ng4Deps['devDependencies']).forEach(pkgName => {
json['devDependencies'][pkgName] = ng4Deps['devDependencies'][pkgName];
});
console.log(JSON.stringify(json));
}));
}

export async function isPrereleaseCli() {
const angularCliPkgJson = JSON.parse(await readFile('node_modules/@angular/cli/package.json'));
const pre = prerelease(angularCliPkgJson.version);
Expand Down
2 changes: 1 addition & 1 deletion tests/legacy-cli/verdaccio.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ packages:
access: $all
publish: $all

'@ngtools/*':
'@ngtools/webpack':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this change necessary or was it just cleanup? Just wondering, because @angular-devkit/* still has the star above.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“@ngtools/json-schema” is used by ng-packgr. Since it no longer exists, it’s not published locally which causes the installation of ng-packgr to fail within the E2E tests.

access: $all
publish: $all

Expand Down