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' ;
43import {
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' ;
139import { audits , PLUGIN_SLUG as slug } from './index' ;
1410import { create } from './lighthouse.plugin' ;
1511
1612describe ( '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
137108describe ( 'lighthouse-audits-export' , ( ) => {
0 commit comments