Skip to content
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
43 changes: 33 additions & 10 deletions e2e/cases/cli/function-config/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,42 @@
import path from 'node:path';
import { expect, readDirContents, rspackTest } from '@e2e/helper';
import {
expect,
getFileContent,
readDirContents,
rspackTest,
} from '@e2e/helper';
import { remove } from 'fs-extra';

const distDir = path.join(__dirname, 'dist');

rspackTest(
'should support exporting a function from the config file',
async ({ execCliSync }) => {
const targetDir = path.join(__dirname, 'dist-production-build');

await remove(targetDir);

await remove(distDir);
execCliSync('build');

const outputs = await readDirContents(targetDir);
const outputFiles = Object.keys(outputs);

expect(outputFiles.length > 1).toBeTruthy();
const files = await readDirContents(distDir);
const content = getFileContent(files, 'index.js');
expect(content.includes('production-production-build')).toBeTruthy();
},
);

rspackTest('should specify env as expected', async ({ execCliSync }) => {
await remove(distDir);
execCliSync('build', {
env: {
...process.env,
NODE_ENV: 'development',
},
});
const files = await readDirContents(distDir);
const content = getFileContent(files, 'index.js');
expect(content.includes('development-development-build')).toBeTruthy();
});

rspackTest('should specify env mode as expected', async ({ execCliSync }) => {
await remove(distDir);
execCliSync('build --env-mode staging');
const files = await readDirContents(distDir);
const content = getFileContent(files, 'index.js');
expect(content.includes('production-staging-build')).toBeTruthy();
});
8 changes: 5 additions & 3 deletions e2e/cases/cli/function-config/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { defineConfig } from '@rsbuild/core';

export default defineConfig(({ env, command }) => ({
output: {
distPath: `dist-${env}-${command}`,
export default defineConfig(({ env, command, envMode }) => ({
source: {
define: {
DEFINED_VALUE: JSON.stringify(`${env}-${envMode}-${command}`),
},
},
}));
2 changes: 1 addition & 1 deletion e2e/cases/cli/function-config/src/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
console.log('hello!');
console.log(DEFINED_VALUE);
Loading