/
browsers.ts
57 lines (48 loc) · 1.63 KB
/
browsers.ts
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
import express from 'express';
import * as path from 'path';
import { copyProjectAsset } from '../../utils/assets';
import { replaceInFile } from '../../utils/fs';
import { ng } from '../../utils/process';
export default async function () {
if (!process.env['E2E_BROWSERS']) {
return;
}
// Ensure SauceLabs configuration
if (!process.env['SAUCE_USERNAME'] || !process.env['SAUCE_ACCESS_KEY']) {
throw new Error('SauceLabs is not configured.');
}
// Workaround for https://github.com/angular/angular/issues/32192
await replaceInFile('src/app/app.component.html', /class="material-icons"/g, '');
await ng('build');
// Add Protractor configuration
await copyProjectAsset('protractor-saucelabs.conf.js', 'e2e/protractor-saucelabs.conf.js');
// Remove browser log checks as they are only supported with the chrome webdriver
await replaceInFile(
'e2e/src/app.e2e-spec.ts',
'await browser.manage().logs().get(logging.Type.BROWSER)',
'[] as any',
);
// Workaround defect in getText WebDriver implementation for Safari/Edge
// Leading and trailing space is not removed
await replaceInFile(
'e2e/src/app.e2e-spec.ts',
'await page.getTitleText()',
'(await page.getTitleText()).trim()',
);
// Setup server
const app = express();
app.use(express.static(path.resolve('dist/test-project')));
const server = app.listen(2000, 'localhost');
try {
// Execute application's E2E tests with SauceLabs
await ng(
'e2e',
'--port=0',
'test-project',
'--protractor-config=e2e/protractor-saucelabs.conf.js',
'--dev-server-target=',
);
} finally {
server.close();
}
}