-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Expand file tree
/
Copy pathbrowsers.ts
More file actions
93 lines (81 loc) · 2.44 KB
/
browsers.ts
File metadata and controls
93 lines (81 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import express from 'express';
import * as path from 'node:path';
import { copyProjectAsset } from '../../utils/assets';
import { appendToFile, createDir, replaceInFile, writeFile } from '../../utils/fs';
import { exec, ng } from '../../utils/process';
import { installPackage } from '../../utils/packages';
/**
* The list of development dependencies used by the E2E protractor-based builder.
*/
const E2E_DEV_DEPENDENCIES = [
'protractor@~7.0.0',
'jasmine-spec-reporter@~7.0.0',
'ts-node@~10.9.0',
'@types/node@^20.17.19',
];
export default async function () {
// Ensure SauceLabs configuration
if (!process.env['SAUCE_USERNAME'] || !process.env['SAUCE_ACCESS_KEY']) {
throw new Error('SauceLabs is not configured.');
}
for (const e2eDep of E2E_DEV_DEPENDENCIES) {
await installPackage(e2eDep);
}
await appendToFile(
'src/app/app.config.ts',
"import { provideProtractorTestingSupport } from '@angular/platform-browser';\n",
);
await replaceInFile(
'src/app/app.config.ts',
'providers: [',
'providers: [\n provideProtractorTestingSupport(),\n',
);
// Workaround for https://github.com/angular/angular/issues/32192
await replaceInFile('src/app/app.html', /class="material-icons"/g, '');
await ng('build');
// Add Protractor configuration
await copyProjectAsset('protractor-saucelabs.conf.js', 'e2e/protractor-saucelabs.conf.js');
// Add App E2E test file
await createDir('e2e/src');
await writeFile(
'e2e/src/app.e2e-spec.ts',
`
import { browser, by, element, logging } from 'protractor';
describe('workspace-project App', () => {
it('should display welcome message', async () => {
await browser.get(browser.baseUrl);
expect((await element(by.css('h1')).getText()).trim()).toEqual('Hello, test-project');
});
});
`,
);
// Add App E2E tsconfig file
await writeFile(
'e2e/tsconfig.json',
`
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "out-tsc/e2e",
"module": "commonjs",
"target": "es2019",
"types": [
"jasmine",
"node"
]
}
}
`,
);
// Setup server
const app = express();
app.use(express.static(path.resolve('dist/test-project/browser')));
const server = app.listen(2000, 'localhost');
try {
// Execute application's E2E tests with SauceLabs
const binPath = path.join('node_modules', '.bin', 'protractor');
await exec(binPath, 'e2e/protractor-saucelabs.conf.js');
} finally {
server.close();
}
}