Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: reorganize assets e2e cases #3841

Merged
merged 1 commit into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
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();
});
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();
});
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
Loading