Skip to content

Commit 68bf75c

Browse files
committed
fix mocks and tests
1 parent 04ebd2c commit 68bf75c

File tree

6 files changed

+23
-13
lines changed

6 files changed

+23
-13
lines changed

src/e2e/fail-threshold-onpostbuild.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ describe('lighthousePlugin with failed threshold run (onPostBuild)', () => {
3434

3535
it('should output expected log content', async () => {
3636
const logs = [
37+
"Persisting Lighthouse cache...",
38+
"Lighthouse cache persisted",
3739
'Generating Lighthouse report. This may take a minute…',
3840
'Running Lighthouse on example/',
3941
'Serving and scanning site from directory example',

src/e2e/fixture/utils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ const mockUtils = {
66
status: {
77
show: jest.fn(),
88
},
9+
cache: {
10+
save: jest.fn(),
11+
restore: jest.fn(),
12+
}
913
};
1014

1115
export default mockUtils;

src/e2e/mocks/puppeteer.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@ const puppeteer = () =>
22
jest.unstable_mockModule('puppeteer', () => {
33
return {
44
default: {
5-
launch: () => {
6-
return { browserPath: 'path' }
7-
},
8-
createBrowserFetcher: () => ({
9-
localRevisions: () => Promise.resolve(['123']),
10-
revisionInfo: () => Promise.resolve({ executablePath: 'path' }),
11-
}),
5+
launch: () => ({
6+
process: () => ({ spawnfile: 'path' }),
7+
close: () => Promise.resolve()
8+
})
129
},
1310
};
1411
});

src/e2e/not-found-onpostbuild.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ describe('lighthousePlugin with single not-found run (onPostBuild)', () => {
2525

2626
it('should output expected log content', async () => {
2727
const logs = [
28+
"Persisting Lighthouse cache...",
29+
"Lighthouse cache persisted",
2830
'Generating Lighthouse report. This may take a minute…',
2931
'Running Lighthouse on example/this-page-does-not-exist',
3032
'Serving and scanning site from directory example',

src/e2e/success-onpostbuild.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ describe('lighthousePlugin with single report per run (onPostBuild)', () => {
2424

2525
it('should output expected log content', async () => {
2626
const logs = [
27+
"Persisting Lighthouse cache...",
28+
"Lighthouse cache persisted",
2729
'Generating Lighthouse report. This may take a minute…',
2830
'Running Lighthouse on example/',
2931
'Serving and scanning site from directory example',

src/index.test.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
import lighthousePlugin from './index.js';
22

33
describe('lighthousePlugin plugin events', () => {
4-
describe('onPostBuild', () => {
5-
it('should return only the expected event function', async () => {
4+
describe('when fail_deploy_on_score_thresholds is true', () => {
5+
it('should return onPreBuild and onPostBuild events', async () => {
66
const events = lighthousePlugin({
77
fail_deploy_on_score_thresholds: 'true',
88
});
99
expect(events).toEqual({
10-
onPostBuild: expect.any(Function),
10+
onPreBuild: expect.any(Function),
11+
onPostBuild: expect.any(Function)
1112
});
1213
});
1314
});
1415

15-
describe('onSuccess', () => {
16-
it('should return only the expected event function', async () => {
16+
describe('default behavior', () => {
17+
it('should return onPreBuild, onPostBuild and onSuccess events', async () => {
1718
const events = lighthousePlugin();
1819
expect(events).toEqual({
19-
onSuccess: expect.any(Function),
20+
onPreBuild: expect.any(Function),
21+
onPostBuild: expect.any(Function),
22+
onSuccess: expect.any(Function)
2023
});
2124
});
2225
});

0 commit comments

Comments
 (0)