Skip to content

Commit c4c500f

Browse files
authored
tests: add missing await on promise assertions (#14437)
1 parent ba425cd commit c4c500f

File tree

5 files changed

+30
-36
lines changed

5 files changed

+30
-36
lines changed

core/test/computed/metrics/cumulative-layout-shift-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('Metrics: CLS', () => {
3131
});
3232

3333
it('throws if layout shift events are found without weighted_score_delta', async () => {
34-
expect(_ => CumulativeLayoutShift.request(oldMetricsTrace, context)).rejects
34+
await expect(CumulativeLayoutShift.request(oldMetricsTrace, context)).rejects
3535
.toThrow('CLS missing weighted_score_delta');
3636
});
3737

core/test/computed/metrics/largest-contentful-paint-all-frames-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('Metrics: LCP from all frames', () => {
2525
const resultPromise = LargestContentfulPaintAllFrames.request({gatherContext, trace: traceAllFrames, devtoolsLog: devtoolsLogAllFrames, settings}, context); // eslint-disable-line max-len
2626

2727
// TODO: Implement lantern solution for LCP all frames.
28-
expect(resultPromise).rejects.toThrow();
28+
await expect(resultPromise).rejects.toThrow();
2929
});
3030

3131
it('should compute an observed value', async () => {

core/test/config/config-helpers-test.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -232,22 +232,23 @@ describe('.mergePlugins', () => {
232232
expect(config.categories).toHaveProperty('lighthouse-plugin-no-groups');
233233
});
234234

235-
it('validate plugin name', () => {
235+
it('validate plugin name', async () => {
236236
const configJson = {audits: ['installable-manifest', 'metrics']};
237237
const flags = {plugins: ['not-a-plugin']};
238-
expect(mergePlugins(configJson, configDir, flags)).rejects.toThrow(/does not start/);
238+
await expect(mergePlugins(configJson, configDir, flags)).rejects.toThrow(/does not start/);
239239
});
240240

241-
it('validate plugin existence', () => {
241+
it('validate plugin existence', async () => {
242242
const configJson = {audits: ['installable-manifest', 'metrics']};
243243
const flags = {plugins: ['lighthouse-plugin-missing']};
244-
expect(mergePlugins(configJson, configDir, flags)).rejects.toThrow(/Unable to locate plugin/);
244+
await expect(mergePlugins(configJson, configDir, flags)).rejects
245+
.toThrow(/Unable to locate plugin/);
245246
});
246247

247-
it('validate plugin structure', () => {
248+
it('validate plugin structure', async () => {
248249
const configJson = {audits: ['installable-manifest', 'metrics']};
249250
const flags = {plugins: ['lighthouse-plugin-no-category']};
250-
expect(mergePlugins(configJson, configDir, flags)).rejects.toThrow(/no valid category/);
251+
await expect(mergePlugins(configJson, configDir, flags)).rejects.toThrow(/no valid category/);
251252
});
252253
});
253254

@@ -367,8 +368,8 @@ describe('.resolveGathererToDefn', () => {
367368
});
368369
});
369370

370-
it('throws for invalid gathererDefn', () => {
371-
expect(resolveGathererToDefn({})).rejects.toThrow(/Invalid Gatherer type/);
371+
it('throws for invalid gathererDefn', async () => {
372+
await expect(resolveGathererToDefn({})).rejects.toThrow(/Invalid Gatherer type/);
372373
});
373374
});
374375

@@ -407,8 +408,8 @@ describe('.resolveAuditsToDefns', () => {
407408
]);
408409
});
409410

410-
it('throws for invalid auditDefns', () => {
411-
expect(resolveAuditsToDefns([new Gatherer()])).rejects.toThrow(/Invalid Audit type/);
411+
it('throws for invalid auditDefns', async () => {
412+
await expect(resolveAuditsToDefns([new Gatherer()])).rejects.toThrow(/Invalid Audit type/);
412413
});
413414
});
414415

core/test/config/config-test.js

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('Fraggle Rock Config', () => {
2525
});
2626

2727
it('should throw if the config path is not absolute', async () => {
28-
expect(initializeConfig(gatherMode, undefined, {configPath: '../relative/path'}))
28+
await expect(initializeConfig(gatherMode, undefined, {configPath: '../relative/path'}))
2929
.rejects.toThrow(/must be an absolute path/);
3030
});
3131

@@ -85,11 +85,11 @@ describe('Fraggle Rock Config', () => {
8585
});
8686
});
8787

88-
it('should throw on invalid artifact definitions', () => {
88+
it('should throw on invalid artifact definitions', async () => {
8989
const nonFRGatherer = new BaseGatherer();
9090
nonFRGatherer.getArtifact = jestMock.fn();
9191
const configJson = {artifacts: [{id: 'LegacyGather', gatherer: {instance: nonFRGatherer}}]};
92-
expect(initializeConfig(gatherMode, configJson)).rejects.toThrow(/FRGatherer gatherer/);
92+
await expect(initializeConfig(gatherMode, configJson)).rejects.toThrow(/FRGatherer gatherer/);
9393
});
9494

9595
it('should filter configuration by gatherMode', async () => {
@@ -206,24 +206,24 @@ describe('Fraggle Rock Config', () => {
206206
});
207207
});
208208

209-
it('should throw when dependencies are out of order in artifacts', () => {
209+
it('should throw when dependencies are out of order in artifacts', async () => {
210210
if (!configJson.artifacts) throw new Error('Failed to run beforeEach');
211211
configJson.artifacts = [configJson.artifacts[1], configJson.artifacts[0]];
212-
expect(initializeConfig('snapshot', configJson))
212+
await expect(initializeConfig('snapshot', configJson))
213213
.rejects.toThrow(/Failed to find dependency/);
214214
});
215215

216-
it('should throw when timespan needs snapshot', () => {
216+
it('should throw when timespan needs snapshot', async () => {
217217
dependentGatherer.meta.supportedModes = ['timespan'];
218218
dependencyGatherer.meta.supportedModes = ['snapshot'];
219-
expect(initializeConfig('navigation', configJson))
219+
await expect(initializeConfig('navigation', configJson))
220220
.rejects.toThrow(/Dependency.*is invalid/);
221221
});
222222

223-
it('should throw when timespan needs navigation', () => {
223+
it('should throw when timespan needs navigation', async () => {
224224
dependentGatherer.meta.supportedModes = ['timespan'];
225225
dependencyGatherer.meta.supportedModes = ['navigation'];
226-
expect(initializeConfig('navigation', configJson))
226+
await expect(initializeConfig('navigation', configJson))
227227
.rejects.toThrow(/Dependency.*is invalid/);
228228
});
229229
});
@@ -431,15 +431,8 @@ describe('Fraggle Rock Config', () => {
431431
artifacts: [{id: 'artifact', gatherer: {instance: new BaseGatherer()}}],
432432
};
433433

434-
// https://github.com/facebook/jest/issues/11438
435-
// expect(initializeConfig(extensionConfig, {gatherMode: 'navigation'}))
436-
// .rejects.toThrow(/did not support any gather modes/);
437-
try {
438-
await initializeConfig('navigation', extensionConfig);
439-
throw new Error('did not throw');
440-
} catch (err) {
441-
expect(err.message).toMatch(/did not support any gather modes/);
442-
}
434+
await expect(initializeConfig('navigation', extensionConfig)).rejects
435+
.toThrow(/did not support any gather modes/);
443436
});
444437
});
445438

core/test/legacy/config/config-test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ describe('Config', () => {
132132
);
133133
});
134134

135-
it('throws when an audit requires an artifact with no gatherer supplying it', () => {
135+
it('throws when an audit requires an artifact with no gatherer supplying it', async () => {
136136
class NeedsWhatYouCantGive extends Audit {
137137
static get meta() {
138138
return {
@@ -153,7 +153,7 @@ describe('Config', () => {
153153
static audit() {}
154154
}
155155

156-
expect(Config.fromJson({
156+
await expect(Config.fromJson({
157157
extends: 'lighthouse:default',
158158
audits: [NeedsWhatYouCantGive],
159159
// eslint-disable-next-line max-len
@@ -805,12 +805,12 @@ describe('Config', () => {
805805
assert.equal(config.passes[0].networkQuietThresholdMs, 10003);
806806
});
807807

808-
it('only supports `lighthouse:default` extension', () => {
808+
it('only supports `lighthouse:default` extension', async () => {
809809
const createConfig = extendsValue => Config.fromJson({extends: extendsValue});
810810

811-
expect(createConfig(true)).rejects.toThrow(/default` is the only valid extension/);
812-
expect(createConfig('lighthouse')).rejects.toThrow(/default` is the only valid/);
813-
expect(createConfig('lighthouse:full')).rejects.toThrow(/default` is the only valid/);
811+
await expect(createConfig(true)).rejects.toThrow(/default` is the only valid extension/);
812+
await expect(createConfig('lighthouse')).rejects.toThrow(/default` is the only valid/);
813+
await expect(createConfig('lighthouse:full')).rejects.toThrow(/default` is the only valid/);
814814
});
815815

816816
it('merges settings with correct priority', async () => {

0 commit comments

Comments
 (0)