Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Oct 23, 2024
1 parent 1280610 commit 8dfacb9
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
46 changes: 46 additions & 0 deletions e2e/cases/assets/addtional-assets/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { build } from '@e2e/helper';
import { expect, test } from '@playwright/test';

function isIncludeFile(filenames: string[], includeFilename: string) {
return filenames.some((filename) => filename.includes(includeFilename));
}

test('should allow to configure additional assets', async () => {
const rsbuild = await build({
cwd: __dirname,
});

const files = await rsbuild.unwrapOutputJSON();
const filenames = Object.keys(files);

const indexJs = await rsbuild.getIndexFile();
expect(indexJs.content).toContain('data:application/json5;base64,');

expect(
isIncludeFile(filenames, 'dist/static/assets/test-temp-large.json5'),
).toBeTruthy();
expect(
isIncludeFile(filenames, 'dist/static/assets/test-temp-small.json5'),
).toBeFalsy();
});

test('should allow to disable emit for additional assets', async () => {
const rsbuild = await build({
cwd: __dirname,
rsbuildConfig: {
output: {
emitAssets: false,
},
},
});

const files = await rsbuild.unwrapOutputJSON();
const filenames = Object.keys(files);

expect(
isIncludeFile(filenames, 'dist/static/assets/test-temp-large.json5'),
).toBeFalsy();
expect(
isIncludeFile(filenames, 'dist/static/assets/test-temp-small.json5'),
).toBeFalsy();
});
21 changes: 21 additions & 0 deletions e2e/cases/assets/addtional-assets/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { defineConfig } from '@rsbuild/core';

writeFileSync(
join(__dirname, 'src/test-temp-small.json5'),
JSON.stringify({ a: 1 }),
);
writeFileSync(
join(__dirname, 'src/test-temp-large.json5'),
JSON.stringify({ a: '1'.repeat(10000) }),
);

export default defineConfig({
source: {
assetsInclude: /\.json5$/,
},
output: {
filenameHash: false,
},
});
5 changes: 5 additions & 0 deletions e2e/cases/assets/addtional-assets/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import large from './test-temp-large.json5';
import small from './test-temp-small.json5';

console.log(large);
console.log(small);

0 comments on commit 8dfacb9

Please sign in to comment.