Skip to content

Commit c7884d7

Browse files
committed
Add extra assertions on the state of debugString
1 parent 12bfb3a commit c7884d7

File tree

7 files changed

+77
-34
lines changed

7 files changed

+77
-34
lines changed

lighthouse-core/audits/manifest-background-color.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
const Audit = require('./audit');
2121
const Formatter = require('../formatters/formatter');
2222

23-
2423
class ManifestBackgroundColor extends Audit {
2524
/**
2625
* @return {!AuditMeta}

lighthouse-core/test/audits/background-color.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const manifestSrc = JSON.stringify(require('../fixtures/manifest.json'));
1919
const manifestParser = require('../../lib/manifest-parser');
2020
const exampleManifest = manifestParser(manifestSrc);
2121

22-
2322
/* global describe, it*/
2423

2524
// Need to disable camelcase check for dealing with background_color.
@@ -44,7 +43,9 @@ describe('Manifest: background color audit', () => {
4443
start_url: '/'
4544
}))
4645
};
47-
return assert.equal(Audit.audit(artifacts).rawValue, false);
46+
const output = Audit.audit(artifacts);
47+
assert.equal(output.rawValue, false);
48+
assert.equal(output.debugString, undefined);
4849
});
4950

5051
it('fails when a minimal manifest contains an invalid background_color', () => {
@@ -53,7 +54,9 @@ describe('Manifest: background color audit', () => {
5354
background_color: 'no'
5455
}))
5556
};
56-
return assert.equal(Audit.audit(artifacts).rawValue, false);
57+
const output = Audit.audit(artifacts);
58+
assert.equal(output.rawValue, false);
59+
assert.equal(output.debugString, undefined);
5760
});
5861

5962
it('succeeds when a minimal manifest contains a valid background_color', () => {

lighthouse-core/test/audits/cache-start-url.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,17 @@ describe('Cache: start_url audit', () => {
3030
});
3131

3232
it('fails when no cache contents given', () => {
33-
return assert.equal(Audit.audit({Manifest: exampleManifest, URL}).rawValue, false);
33+
const artifacts = {Manifest: exampleManifest, URL};
34+
const output = Audit.audit(artifacts);
35+
assert.equal(output.rawValue, false);
36+
assert.equal(output.debugString, 'No cache or URL detected');
3437
});
3538

3639
it('fails when no URL given', () => {
37-
return assert.equal(Audit.audit({Manifest: exampleManifest, CacheContents}).rawValue, false);
40+
const artifacts = {Manifest: exampleManifest, CacheContents};
41+
const output = Audit.audit(artifacts);
42+
assert.equal(output.rawValue, false);
43+
assert.equal(output.debugString, 'No cache or URL detected');
3844
});
3945

4046
// Need to disable camelcase check for dealing with start_url.
@@ -43,23 +49,18 @@ describe('Cache: start_url audit', () => {
4349
const artifacts = {
4450
Manifest: { }
4551
};
46-
return assert.equal(Audit.audit(artifacts).rawValue, false);
47-
});
48-
49-
it('fails when a manifest artifact contains a null start_url', () => {
50-
const artifacts = {
51-
Manifest: {
52-
start_url: null
53-
}
54-
};
55-
return assert.equal(Audit.audit(artifacts).rawValue, false);
52+
const output = Audit.audit(artifacts);
53+
assert.equal(output.rawValue, false);
54+
assert.equal(output.debugString, 'start_url not present in Manifest');
5655
});
5756

5857
it('fails when a manifest contains no start_url', () => {
5958
const artifacts = {
6059
Manifest: manifestParser('{}')
6160
};
62-
return assert.equal(Audit.audit(artifacts).rawValue, false);
61+
const output = Audit.audit(artifacts);
62+
assert.equal(output.rawValue, false);
63+
assert.equal(output.debugString, 'start_url not present in Manifest');
6364
});
6465
/* eslint-enable camelcase */
6566

lighthouse-core/test/audits/exists.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,24 @@ describe('Manifest: exists audit', () => {
3535
}}).rawValue, true);
3636
});
3737

38-
it('succeeds when a minimal manifest contains a valid background_color', () => {
38+
it('succeeds with a valid minimal manifest', () => {
39+
const artifacts = {
40+
Manifest: manifestParser('{}')
41+
};
42+
const output = Audit.audit(artifacts);
43+
assert.equal(output.rawValue, true);
44+
assert.equal(output.debugString, undefined);
45+
});
46+
47+
it('succeeds with a valid minimal manifest', () => {
3948
const artifacts = {
4049
Manifest: manifestParser(JSON.stringify({
4150
name: 'Lighthouse PWA'
4251
}))
4352
};
44-
return assert.equal(Audit.audit(artifacts).rawValue, true);
53+
const output = Audit.audit(artifacts);
54+
assert.equal(output.rawValue, true);
55+
assert.equal(output.debugString, undefined);
4556
});
4657

4758
it('correctly passes through debug strings', () => {
@@ -55,6 +66,15 @@ describe('Manifest: exists audit', () => {
5566
}).debugString, debugString);
5667
});
5768

69+
it('correctly passes through a JSON parsing failure', () => {
70+
const artifacts = {
71+
Manifest: manifestParser('{ \name: Definitely not valid JSON }')
72+
};
73+
const output = Audit.audit(artifacts);
74+
assert.equal(output.rawValue, false);
75+
assert.ok(output.debugString.includes('Unexpected token'), 'No JSON error message');
76+
});
77+
5878
it('succeeds with a complete manifest', () => {
5979
return assert.equal(Audit.audit({Manifest: exampleManifest}).rawValue, true);
6080
});

lighthouse-core/test/audits/short-name.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,34 @@ describe('Manifest: short_name audit', () => {
3939
/* eslint-disable camelcase */
4040
it('fails when a manifest contains no short_name and no name', () => {
4141
const artifacts = {
42-
name: null,
43-
short_name: null
42+
Manifest: manifestParser(JSON.stringify({
43+
name: undefined,
44+
short_name: undefined
45+
}))
4446
};
45-
const Manifest = manifestParser(JSON.stringify(artifacts));
4647

47-
return assert.equal(Audit.audit({Manifest}).rawValue, false);
48+
const output = Audit.audit(artifacts);
49+
assert.equal(output.rawValue, false);
50+
assert.equal(output.debugString, undefined);
4851
});
4952

5053
it('succeeds when a manifest contains no short_name but a name', () => {
5154
const artifacts = {
52-
short_name: undefined,
53-
name: 'Example App'
55+
Manifest: manifestParser(JSON.stringify({
56+
short_name: undefined,
57+
name: 'Example App'
58+
}))
5459
};
55-
const Manifest = manifestParser(JSON.stringify(artifacts));
5660

57-
return assert.equal(Audit.audit({Manifest}).rawValue, true);
61+
const output = Audit.audit(artifacts);
62+
assert.equal(output.rawValue, true);
63+
assert.equal(output.debugString, undefined);
5864
});
5965
/* eslint-enable camelcase */
6066

6167
it('succeeds when a manifest contains a short_name', () => {
62-
return assert.equal(Audit.audit({Manifest: exampleManifest}).rawValue, true);
68+
const output = Audit.audit({Manifest: exampleManifest});
69+
assert.equal(output.rawValue, true);
70+
assert.equal(output.debugString, undefined);
6371
});
6472
});

lighthouse-core/test/audits/start-url.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ describe('Manifest: start_url audit', () => {
3232
const artifacts = {
3333
Manifest: manifestParser('{}')
3434
};
35-
return assert.equal(Audit.audit(artifacts).rawValue, false);
35+
const output = Audit.audit(artifacts);
36+
assert.equal(output.rawValue, false);
37+
assert.equal(output.debugString, undefined);
3638
});
3739

3840
// Need to disable camelcase check for dealing with short_name.
@@ -43,7 +45,9 @@ describe('Manifest: start_url audit', () => {
4345
start_url: undefined
4446
}))
4547
};
46-
return assert.equal(Audit.audit(artifacts).rawValue, false);
48+
const output = Audit.audit(artifacts);
49+
assert.equal(output.rawValue, false);
50+
assert.equal(output.debugString, undefined);
4751
});
4852

4953
it('succeeds when a minimal manifest contains a start_url', () => {
@@ -52,7 +56,9 @@ describe('Manifest: start_url audit', () => {
5256
start_url: '/'
5357
}))
5458
};
55-
return assert.equal(Audit.audit(artifacts).rawValue, true);
59+
const output = Audit.audit(artifacts);
60+
assert.equal(output.rawValue, true);
61+
assert.equal(output.debugString, undefined);
5662
});
5763
/* eslint-enable camelcase */
5864

lighthouse-core/test/audits/theme-color.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ describe('Manifest: theme_color audit', () => {
3232
const artifacts = {
3333
Manifest: manifestParser('{}')
3434
};
35-
return assert.equal(Audit.audit(artifacts).rawValue, false);
35+
const output = Audit.audit(artifacts);
36+
assert.equal(output.rawValue, false);
37+
assert.equal(output.debugString, undefined);
3638
});
3739

3840
// Need to disable camelcase check for dealing with theme_color.
@@ -43,7 +45,9 @@ describe('Manifest: theme_color audit', () => {
4345
start_url: '/'
4446
}))
4547
};
46-
return assert.equal(Audit.audit(artifacts).rawValue, false);
48+
const output = Audit.audit(artifacts);
49+
assert.equal(output.rawValue, false);
50+
assert.equal(output.debugString, undefined);
4751
});
4852

4953
it('succeeds when a minimal manifest contains a theme_color', () => {
@@ -52,7 +56,9 @@ describe('Manifest: theme_color audit', () => {
5256
theme_color: '#bada55'
5357
}))
5458
};
55-
return assert.equal(Audit.audit(artifacts).rawValue, true);
59+
const output = Audit.audit(artifacts);
60+
assert.equal(output.rawValue, true);
61+
assert.equal(output.debugString, undefined);
5662
});
5763

5864
/* eslint-enable camelcase */

0 commit comments

Comments
 (0)