Skip to content

Commit 90c839c

Browse files
authored
test(examples-plugins): convert integration tests to e2e (code-pushup#512)
1 parent ec7ee5e commit 90c839c

File tree

4 files changed

+38
-73
lines changed

4 files changed

+38
-73
lines changed

examples/plugins/src/lighthouse/mock/constants.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/plugins/src/lighthouse/src/lighthouse.plugin.integration.test.ts

Lines changed: 18 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
import { vol } from 'memfs';
2-
import { beforeEach, describe, expect, it } from 'vitest';
3-
import { executePlugin } from '@code-pushup/core';
1+
import { join } from 'node:path';
2+
import { describe, expect, it } from 'vitest';
43
import {
54
auditSchema,
65
categoryRefSchema,
76
pluginConfigSchema,
87
} from '@code-pushup/models';
9-
import { MEMFS_VOLUME } from '@code-pushup/test-utils';
10-
import { LIGHTHOUSE_URL } from '../mock/constants';
11-
import { lhr } from '../mock/fixtures/lhr';
12-
import { LIGHTHOUSE_OUTPUT_FILE_DEFAULT, corePerfGroupRefs } from './constants';
8+
import { corePerfGroupRefs } from './constants';
139
import { audits, PLUGIN_SLUG as slug } from './index';
1410
import { create } from './lighthouse.plugin';
1511

1612
describe('lighthouse-create-export-config', () => {
1713
it('should return valid PluginConfig if create is called', async () => {
18-
const pluginConfig = await create({ url: LIGHTHOUSE_URL });
14+
const pluginConfig = await create({ url: 'http://localhost:8080' });
1915
expect(() => pluginConfigSchema.parse(pluginConfig)).not.toThrow();
2016
expect(pluginConfig).toEqual({
2117
slug,
@@ -51,7 +47,7 @@ describe('lighthouse-create-export-config', () => {
5147

5248
it('should parse options for headless by default to "new" in runner args', async () => {
5349
const pluginConfig = await create({
54-
url: LIGHTHOUSE_URL,
50+
url: 'http://localhost:8080',
5551
});
5652
expect(pluginConfig.runner.args).toEqual(
5753
expect.arrayContaining(['--chrome-flags="--headless=new"']),
@@ -60,7 +56,7 @@ describe('lighthouse-create-export-config', () => {
6056

6157
it('should parse options for headless to new if true is given in runner args', async () => {
6258
const pluginConfig = await create({
63-
url: LIGHTHOUSE_URL,
59+
url: 'http://localhost:8080',
6460
headless: true,
6561
});
6662
expect(pluginConfig.runner.args).toEqual(
@@ -70,7 +66,7 @@ describe('lighthouse-create-export-config', () => {
7066

7167
it('should parse options for headless to new if false is given in runner args', async () => {
7268
const pluginConfig = await create({
73-
url: LIGHTHOUSE_URL,
69+
url: 'http://localhost:8080',
7470
headless: false,
7571
});
7672
expect(pluginConfig.runner.args).toEqual(
@@ -80,7 +76,7 @@ describe('lighthouse-create-export-config', () => {
8076

8177
it('should override userDataDir option when given in runner args', async () => {
8278
const pluginConfig = await create({
83-
url: LIGHTHOUSE_URL,
79+
url: 'http://localhost:8080',
8480
userDataDir: 'test',
8581
});
8682
expect(pluginConfig.runner.args).toEqual(
@@ -89,49 +85,24 @@ describe('lighthouse-create-export-config', () => {
8985
]),
9086
);
9187
});
92-
});
93-
94-
describe('lighthouse-create-export-execution', () => {
95-
beforeEach(() => {
96-
vol.fromJSON(
97-
{
98-
[LIGHTHOUSE_OUTPUT_FILE_DEFAULT]: JSON.stringify(lhr),
99-
},
100-
MEMFS_VOLUME,
101-
);
102-
});
10388

104-
// TODO: Convert to E2E test or reduce scope, it takes too long to run these tests
105-
/* eslint-disable vitest/no-disabled-tests */
106-
it.skip('should return PluginConfig that executes correctly', async () => {
107-
const pluginConfig = await create({ url: LIGHTHOUSE_URL });
108-
await expect(executePlugin(pluginConfig)).resolves.toMatchObject(
109-
expect.objectContaining({
110-
slug,
111-
title: 'Lighthouse',
112-
description: 'Chrome lighthouse CLI as code-pushup plugin',
113-
duration: expect.any(Number),
114-
date: expect.any(String),
115-
audits: expect.any(Array),
116-
groups: expect.any(Array),
117-
}),
118-
);
119-
});
120-
121-
it.skip('should use onlyAudits', async () => {
89+
it('should use onlyAudits', async () => {
12290
const pluginConfig = await create({
123-
url: LIGHTHOUSE_URL,
91+
url: 'http://localhost:8080',
92+
outputPath: `${join('tmp', 'lighthouse-report.json')}`,
12493
onlyAudits: 'largest-contentful-paint',
12594
});
12695
expect(pluginConfig.runner.args).toEqual(
12796
expect.arrayContaining(['--onlyAudits="largest-contentful-paint"']),
12897
);
129-
const { audits: auditOutputs } = await executePlugin(pluginConfig);
130-
131-
expect(auditOutputs).toHaveLength(1);
132-
expect(auditOutputs[0]?.slug).toBe('largest-contentful-paint');
98+
expect(pluginConfig).toStrictEqual(
99+
expect.objectContaining({
100+
audits: expect.arrayContaining([
101+
expect.objectContaining({ slug: 'largest-contentful-paint' }),
102+
]),
103+
}),
104+
);
133105
});
134-
/* eslint-enable vitest/no-disabled-tests */
135106
});
136107

137108
describe('lighthouse-audits-export', () => {

examples/plugins/src/lighthouse/src/lighthouse.plugin.unit.test.ts

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,28 @@
11
import { describe, expect, it } from 'vitest';
2-
import { LIGHTHOUSE_URL } from '../mock/constants';
32
import { LIGHTHOUSE_OUTPUT_FILE_DEFAULT } from './constants';
43
import { runnerConfig } from './lighthouse.plugin';
5-
import type { LighthouseCliOptions } from './types';
64

75
describe('lighthouse-runnerConfig', () => {
8-
const baseOptions: LighthouseCliOptions = {
9-
url: LIGHTHOUSE_URL,
10-
};
11-
const lcpAuditOutputBase = {
12-
displayValue: expect.stringContaining('sec'),
13-
score: 1,
14-
slug: 'largest-contentful-paint',
15-
value: 0,
16-
};
17-
186
it('should execute if url is given', () => {
19-
expect(runnerConfig(baseOptions)).toEqual(
7+
expect(
8+
runnerConfig({
9+
url: 'http://localhost:8080',
10+
}),
11+
).toEqual(
2012
expect.objectContaining({
21-
args: expect.arrayContaining(['lighthouse', LIGHTHOUSE_URL]),
13+
args: expect.arrayContaining(['lighthouse', 'http://localhost:8080']),
2214
command: 'npx',
2315
outputFile: LIGHTHOUSE_OUTPUT_FILE_DEFAULT,
2416
}),
2517
);
2618
});
2719

2820
it('should execute with output "json" and output-path "lighthouse-report.json" by default', () => {
29-
expect(runnerConfig(baseOptions)).toEqual(
21+
expect(
22+
runnerConfig({
23+
url: 'http://localhost:8080',
24+
}),
25+
).toEqual(
3026
expect.objectContaining({
3127
args: expect.arrayContaining([
3228
'--output="json"',
@@ -42,21 +38,21 @@ describe('lighthouse-runnerConfig', () => {
4238
it('should run only audits included in given onlyAudits', () => {
4339
expect(
4440
runnerConfig({
45-
...baseOptions,
46-
onlyAudits: [lcpAuditOutputBase.slug],
41+
url: 'http://localhost:8080',
42+
onlyAudits: ['largest-contentful-paint'],
4743
}),
4844
).toEqual(
4945
expect.objectContaining({
5046
args: expect.arrayContaining([
51-
`--onlyAudits="${lcpAuditOutputBase.slug}"`,
47+
'--onlyAudits="largest-contentful-paint"',
5248
]),
5349
}),
5450
);
5551
});
5652

5753
it('should parse options for headless by default to false', () => {
5854
const args = runnerConfig({
59-
url: LIGHTHOUSE_URL,
55+
url: 'http://localhost:8080',
6056
});
6157
expect(args).toEqual(
6258
expect.not.arrayContaining(['--chrome-flags="--headless=new"']),
@@ -66,12 +62,12 @@ describe('lighthouse-runnerConfig', () => {
6662
it('should run headless "new" if set to true', () => {
6763
expect(
6864
runnerConfig({
69-
...baseOptions,
65+
url: 'http://localhost:8080',
7066
headless: 'new',
7167
}),
7268
).toEqual(
7369
expect.objectContaining({
74-
args: expect.arrayContaining([`--chrome-flags="--headless=new"`]),
70+
args: expect.arrayContaining(['--chrome-flags="--headless=new"']),
7571
}),
7672
);
7773
});

examples/plugins/src/lighthouse/src/utils.unit.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { describe, expect, it } from 'vitest';
2-
import { LIGHTHOUSE_URL } from '../mock/constants';
32
import { getLighthouseCliArguments } from './utils';
43

54
describe('getLighthouseCliArguments', () => {
@@ -13,7 +12,7 @@ describe('getLighthouseCliArguments', () => {
1312

1413
it('should parse options for headless to new if true is given', () => {
1514
const args = getLighthouseCliArguments({
16-
url: LIGHTHOUSE_URL,
15+
url: 'http://localhost:8080',
1716
headless: 'new',
1817
});
1918
expect(args).toEqual(
@@ -23,7 +22,7 @@ describe('getLighthouseCliArguments', () => {
2322

2423
it('should not include options for headless if false is given', () => {
2524
const args = getLighthouseCliArguments({
26-
url: LIGHTHOUSE_URL,
25+
url: 'http://localhost:8080',
2726
headless: false,
2827
});
2928
expect(args).toEqual(
@@ -33,7 +32,7 @@ describe('getLighthouseCliArguments', () => {
3332

3433
it('should use userDataDir option in chrome flags when given', () => {
3534
const args = getLighthouseCliArguments({
36-
url: LIGHTHOUSE_URL,
35+
url: 'http://localhost:8080',
3736
userDataDir: 'test',
3837
});
3938
expect(args).toEqual(

0 commit comments

Comments
 (0)