Skip to content

Commit a30ca72

Browse files
Alanhansl
Alan
authored andcommitted
ci: add configuration for legacy projects
In some cases, there are still legacy projects, prior to migrations and we should not use `webdriverUpdate` and we should use headless chrome.
1 parent 0a4c86b commit a30ca72

File tree

1 file changed

+90
-26
lines changed

1 file changed

+90
-26
lines changed

tests/legacy-cli/e2e/utils/project.ts

Lines changed: 90 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,82 @@ export async function createProject(name: string, ...args: string[]) {
4848
}
4949

5050
export async function prepareProjectForE2e(name) {
51-
const argv: string[] = getGlobalVariable('argv');
52-
53-
await git('config', 'user.email', 'angular-core+e2e@google.com');
54-
await git('config', 'user.name', 'Angular CLI E2e');
55-
await git('config', 'commit.gpgSign', 'false');
56-
await useBuiltPackages();
57-
await useCIChrome('e2e');
58-
await useCIChrome('');
59-
await useDevKitSnapshots();
60-
await argv['ng2'] ? useNg2() : Promise.resolve();
61-
await argv['ng4'] ? useNg4() : Promise.resolve();
62-
await argv['ng-snapshots'] || argv['ng-tag'] ? useSha() : Promise.resolve();
63-
await console.log(`Project ${name} created... Installing npm.`);
64-
await silentNpm('install');
65-
await useCIDefaults(name);
66-
// Force sourcemaps to be from the root of the filesystem.
67-
await updateJsonFile('tsconfig.json', json => {
68-
json['compilerOptions']['sourceRoot'] = '/';
69-
});
70-
await gitCommit('prepare-project-for-e2e');
71-
}
51+
const argv: string[] = getGlobalVariable(
52+
'argv',
53+
);
54+
55+
await git(
56+
'config',
57+
'user.email',
58+
'angular-core+e2e@google.com',
59+
);
60+
await git(
61+
'config',
62+
'user.name',
63+
'Angular CLI E2e',
64+
);
65+
await git(
66+
'config',
67+
'commit.gpgSign',
68+
'false',
69+
);
70+
await useBuiltPackages();
71+
await useCIChrome(
72+
'e2e',
73+
);
74+
await useCIChrome(
75+
'',
76+
);
77+
78+
// legacy projects
79+
await useCIChrome(
80+
'src',
81+
);
82+
83+
await useDevKitSnapshots();
84+
(await argv[
85+
'ng2'
86+
])
87+
? useNg2()
88+
: Promise.resolve();
89+
(await argv[
90+
'ng4'
91+
])
92+
? useNg4()
93+
: Promise.resolve();
94+
(await argv[
95+
'ng-snapshots'
96+
]) ||
97+
argv[
98+
'ng-tag'
99+
]
100+
? useSha()
101+
: Promise.resolve();
102+
await console.log(
103+
`Project ${name} created... Installing npm.`,
104+
);
105+
await silentNpm(
106+
'install',
107+
);
108+
await useCIDefaults(
109+
name,
110+
);
111+
// Force sourcemaps to be from the root of the filesystem.
112+
await updateJsonFile(
113+
'tsconfig.json',
114+
json => {
115+
json[
116+
'compilerOptions'
117+
][
118+
'sourceRoot'
119+
] =
120+
'/';
121+
},
122+
);
123+
await gitCommit(
124+
'prepare-project-for-e2e',
125+
);
126+
}
72127

73128

74129
export function useDevKit(devkitRoot: string) {
@@ -99,7 +154,7 @@ export function useDevKit(devkitRoot: string) {
99154
export function useDevKitSnapshots() {
100155
return updateJsonFile('package.json', json => {
101156
// TODO: actually add these.
102-
// These were not working on any test that ran `npm i`.
157+
// These were not working on any test that ran `npm i`.
103158
// json['devDependencies']['@angular-devkit/build-angular'] =
104159
// 'github:angular/angular-devkit-build-angular-builds';
105160
// // By adding build-ng-packagr preemptively, adding a lib will not update it.
@@ -119,8 +174,9 @@ export function useBuiltPackages() {
119174
}
120175

121176
for (const packageName of Object.keys(packages)) {
122-
if (json['dependencies'].hasOwnProperty(packageName)) {
123-
json['dependencies'][packageName] = packages[packageName].tar;
177+
if (json['dependencies'].hasOwnProperty(packageName)
178+
) {
179+
json['dependencies'][packageName] = packages[packageName].tar;
124180
} else if (json['devDependencies'].hasOwnProperty(packageName)) {
125181
json['devDependencies'][packageName] = packages[packageName].tar;
126182
}
@@ -212,6 +268,13 @@ export function useCIDefaults(projectName = 'test-project') {
212268
if (appTargets.e2e) {
213269
appTargets.e2e.options.webdriverUpdate = false;
214270
}
271+
272+
// legacy project structure
273+
const e2eProject = workspaceJson.projects[projectName + '-e2e'];
274+
if (e2eProject){
275+
const e2eTargets = e2eProject.targets || e2eProject.architect;
276+
e2eTargets.e2e.options.webdriverUpdate = false;
277+
}
215278
})
216279
.then(() => updateJsonFile('package.json', json => {
217280
// Use matching versions of Chrome and Webdriver.
@@ -223,8 +286,9 @@ export function useCIDefaults(projectName = 'test-project') {
223286
}
224287

225288
export function useCIChrome(projectDir: string) {
226-
const protractorConf = `${projectDir}/protractor.conf.js`;
227-
const karmaConf = `${projectDir ? projectDir + '/' : ''}karma.conf.js`;
289+
const dir = projectDir ? projectDir + '/' : '';
290+
const protractorConf = `${dir}protractor.conf.js`;
291+
const karmaConf = `${dir}karma.conf.js`;
228292

229293
return Promise.resolve()
230294
.then(() => updateJsonFile('package.json', json => {

0 commit comments

Comments
 (0)