@@ -2,20 +2,17 @@ import { readFileSync } from 'node:fs';
22import { dirname , join } from 'node:path' ;
33import { fileURLToPath } from 'node:url' ;
44import { expect , test } from '@playwright/test' ;
5- import { createRsbuild } from '@rsbuild/core' ;
6- import { pluginImageCompress } from '../../src' ;
5+ import { createRsbuild , loadConfig } from '@rsbuild/core' ;
76
87const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
98
109test ( 'should compress image with use plugin-image-compress' , async ( ) => {
1110 const rsbuild = await createRsbuild ( {
1211 cwd : __dirname ,
13- rsbuildConfig : {
14- plugins : [ pluginImageCompress ( ) ] ,
15- } ,
12+ rsbuildConfig : ( await loadConfig ( { cwd : __dirname } ) ) . content ,
1613 } ) ;
1714
18- await expect ( rsbuild . build ( ) ) . resolves . toBeDefined ( ) ;
15+ await rsbuild . build ( ) ;
1916
2017 const jpeg = readFileSync (
2118 join ( __dirname , 'dist/static/image/image.jpeg' ) ,
@@ -26,7 +23,7 @@ test('should compress image with use plugin-image-compress', async () => {
2623 'utf-8' ,
2724 ) ;
2825 const svg = readFileSync (
29- join ( __dirname , 'dist/static/image /mobile.svg' ) ,
26+ join ( __dirname , 'dist/static/svg /mobile.svg' ) ,
3027 'utf-8' ,
3128 ) ;
3229 // const ico = names.find((item) => item.endsWith('.ico'))!;
@@ -37,9 +34,9 @@ test('should compress image with use plugin-image-compress', async () => {
3734 const originSvg = readFileSync ( join ( assetsDir , 'mobile.svg' ) , 'utf-8' ) ;
3835 // const originIco = readFileSync(join(assetsDir, 'image.ico'), 'utf-8');
3936
40- expect ( outputs [ jpeg ] . length ) . toBeLessThan ( originJpeg . length ) ;
41- expect ( outputs [ png ] . length ) . toBeLessThan ( originPng . length ) ;
42- expect ( outputs [ svg ] . length ) . toBeLessThan ( originSvg . length ) ;
37+ expect ( jpeg . length ) . toBeLessThan ( originJpeg . length ) ;
38+ expect ( png . length ) . toBeLessThan ( originPng . length ) ;
39+ expect ( svg . length ) . toBeLessThan ( originSvg . length ) ;
4340 // TODO ico file size is not less than origin
4441 // expect(outputs[ico].length).toBeLessThan(originIco.length);
4542} ) ;
0 commit comments