Skip to content

Commit 6ae5dab

Browse files
committed
test: fix the e2e case
1 parent ff6531d commit 6ae5dab

File tree

7 files changed

+20
-10
lines changed

7 files changed

+20
-10
lines changed

test/assets/icon.png

1.87 KB
Loading

test/assets/image.ico

119 KB
Binary file not shown.

test/assets/image.jpeg

179 KB
Loading

test/assets/image.png

120 KB
Loading

test/assets/mobile.svg

Lines changed: 1 addition & 0 deletions
Loading

test/basic/index.test.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@ import { readFileSync } from 'node:fs';
22
import { dirname, join } from 'node:path';
33
import { fileURLToPath } from 'node:url';
44
import { expect, test } from '@playwright/test';
5-
import { createRsbuild } from '@rsbuild/core';
6-
import { pluginImageCompress } from '../../src';
5+
import { createRsbuild, loadConfig } from '@rsbuild/core';
76

87
const __dirname = dirname(fileURLToPath(import.meta.url));
98

109
test('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
});

test/basic/rsbuild.config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineConfig } from '@rsbuild/core';
2+
import { pluginImageCompress } from '@rsbuild/plugin-image-compress';
3+
4+
export default defineConfig({
5+
plugins: [pluginImageCompress(['jpeg', 'png', 'ico', 'svg'])],
6+
output: {
7+
filename: {
8+
svg: '[name][ext]',
9+
image: '[name][ext]',
10+
},
11+
},
12+
});

0 commit comments

Comments
 (0)