/
autorun-static-dir.test.js
69 lines (55 loc) · 2.66 KB
/
autorun-static-dir.test.js
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
/**
* @license Copyright 2019 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
'use strict';
/* eslint-env jest */
const path = require('path');
const {runCLI} = require('./test-utils.js');
describe('Lighthouse CI autorun CLI', () => {
const autorunDir = path.join(__dirname, 'fixtures/autorun-static-dir');
const rcFile = path.join(autorunDir, 'lighthouserc-autorun.json');
it('should run all three steps', () => {
const {stdout, stderr, status} = runCLI(
['autorun', `--rc-file=${rcFile}`, '--rc-overrides.collect.numberOfRuns=2'],
{cwd: autorunDir}
);
const stdoutClean = stdout
.replace(/:\d{4,6}/g, ':XXXX')
.replace(/port \d{4,6}/, 'port XXXX')
.replace(/Open the report at.*\n/, 'Open the report at <link>\n');
const stderrClean = stderr.replace(/:\d{4,6}/g, ':XXXX').replace(/port \d{4,6}/, 'port XXXX');
expect(stdoutClean).toMatchInlineSnapshot(`
"✅ .lighthouseci/ directory writable
✅ Ancestor hash determinable
⚠️ GitHub token set
Healthcheck passed!
Automatically determined ./build as \`staticDistDir\`.
Set it explicitly in lighthouserc.json if incorrect.
Started a web server on port XXXX...
Running Lighthouse 2 time(s) on http://localhost:XXXX/good.html
Run #1...done.
Run #2...done.
Done running Lighthouse!
Uploading median LHR of http://localhost:XXXX/good.html...success!
Open the report at <link>
No GitHub token set, skipping.
"
`);
expect(stderrClean).toMatchInlineSnapshot(`
"Checking assertions against 1 URL(s), 2 total run(s)
1 result(s) for [1mhttp://localhost:XXXX/good.html[0m
[31m✘[0m [1mviewport[0m failure for [1mminScore[0m assertion
Does not have a \`<meta name=\\"viewport\\">\` tag with \`width\` or \`initial-scale\`
Documentation: https://web.dev/viewport
expected: >=[32m1[0m
found: [31m0[0m
[2mall values: 0, 0[0m
Assertion failed. Exiting with status code 1.
assert command failed. Exiting with status code 1.
"
`);
expect(status).toEqual(1);
}, 180000);
});