Skip to content

Commit

Permalink
test: reorganize assets e2e cases (#3841)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Oct 27, 2024
1 parent 630f999 commit bd5f711
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 80 deletions.
19 changes: 19 additions & 0 deletions e2e/cases/assets/assets-inline-auto/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { build } from '@e2e/helper';
import { expect, test } from '@playwright/test';
import { pluginReact } from '@rsbuild/plugin-react';

test('should inline small assets automatically', async ({ page }) => {
const rsbuild = await build({
cwd: __dirname,
page,
plugins: [pluginReact()],
});

await expect(
page.evaluate(
`document.getElementById('test-img').src.startsWith('data:image/png')`,
),
).resolves.toBeTruthy();

await rsbuild.close();
});
File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions e2e/cases/assets/assets-inline-false/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { build } from '@e2e/helper';
import { expect, test } from '@playwright/test';
import { pluginReact } from '@rsbuild/plugin-react';

test('should allow to disable assets inline with `?__inline=false`', async ({
page,
}) => {
const rsbuild = await build({
cwd: __dirname,
page,
plugins: [pluginReact()],
});

await expect(
page.evaluate(
`document.getElementById('test-img').src.includes('static/image/icon')`,
),
).resolves.toBeTruthy();

await rsbuild.close();
});
19 changes: 19 additions & 0 deletions e2e/cases/assets/assets-inline/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { build } from '@e2e/helper';
import { expect, test } from '@playwright/test';
import { pluginReact } from '@rsbuild/plugin-react';

test('should allow to inline assets with `?inline`', async ({ page }) => {
const rsbuild = await build({
cwd: __dirname,
page,
plugins: [pluginReact()],
});

await expect(
page.evaluate(
`document.getElementById('test-img').src.startsWith('data:image/png')`,
),
).resolves.toBeTruthy();

await rsbuild.close();
});
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions e2e/cases/assets/assets-url/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { build } from '@e2e/helper';
import { expect, test } from '@playwright/test';
import { pluginReact } from '@rsbuild/plugin-react';

test('should allow to get assets URL with `?url`', async ({ page }) => {
const rsbuild = await build({
cwd: __dirname,
page,
plugins: [pluginReact()],
});

await expect(
page.evaluate(
`document.getElementById('test-img').src.includes('static/image/icon')`,
),
).resolves.toBeTruthy();

await rsbuild.close();
});
File renamed without changes.
File renamed without changes.
47 changes: 0 additions & 47 deletions e2e/cases/output/assets-retry/index.test.ts

This file was deleted.

1 change: 0 additions & 1 deletion e2e/cases/output/assets-retry/src/index.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import { join } from 'node:path';
import { build } from '@e2e/helper';
import { expect, test } from '@playwright/test';
import { pluginReact } from '@rsbuild/plugin-react';

const fixtures = __dirname;

const cases = [
{
name: 'assets(default)',
cwd: join(fixtures, 'assets'),
expected: 'inline',
},
{
name: 'assets(dataUriLimit 0)',
cwd: join(fixtures, 'assets'),
cwd: __dirname,
config: {
output: {
dataUriLimit: 0,
Expand All @@ -23,7 +15,7 @@ const cases = [
},
{
name: 'assets(dataUriLimit.image 0)',
cwd: join(fixtures, 'assets'),
cwd: __dirname,
config: {
output: {
dataUriLimit: {
Expand All @@ -35,7 +27,7 @@ const cases = [
},
{
name: 'assets(dataUriLimit max number)',
cwd: join(fixtures, 'assets'),
cwd: __dirname,
config: {
output: {
dataUriLimit: {
Expand All @@ -45,26 +37,6 @@ const cases = [
},
expected: 'inline',
},
{
name: 'assets-url',
cwd: join(fixtures, 'assets-url'),
expected: 'url',
},
{
name: 'assets-no-inline',
cwd: join(fixtures, 'assets-no-inline'),
expected: 'url',
},
{
name: 'assets__inline',
cwd: join(fixtures, 'assets__inline'),
expected: 'inline',
},
{
name: 'assets-inline',
cwd: join(fixtures, 'assets-inline'),
expected: 'inline',
},
];

for (const item of cases) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import img from '@assets/icon.png?inline';
import img from '@assets/icon.png';

function App() {
return (
Expand Down

1 comment on commit bd5f711

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs ✅ success
plugins ❌ failure
rspress ✅ success
rslib ✅ success
examples ✅ success

Please sign in to comment.