Skip to content

Commit

Permalink
fix: ut
Browse files Browse the repository at this point in the history
  • Loading branch information
9aoy committed Aug 12, 2024
1 parent 43dcbe2 commit f494c82
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 56 deletions.
10 changes: 4 additions & 6 deletions e2e/cases/auto-external/default/rslib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ import { defineConfig } from '@rslib/core';

export default defineConfig({
lib: [
{
...generateBundleEsmConfig(__dirname),
generateBundleEsmConfig(__dirname, {
dts: {
bundle: true,
},
},
{
...generateBundleCjsConfig(__dirname),
}),
generateBundleCjsConfig(__dirname, {
dts: {
bundle: true,
},
},
}),
],
source: {
entry: {
Expand Down
10 changes: 4 additions & 6 deletions e2e/cases/auto-external/false/rslib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@ import { defineConfig } from '@rslib/core';

export default defineConfig({
lib: [
{
...generateBundleEsmConfig(__dirname),
generateBundleEsmConfig(__dirname, {
autoExternal: false,
dts: {
bundle: true,
},
},
{
...generateBundleCjsConfig(__dirname),
}),
generateBundleCjsConfig(__dirname, {
autoExternal: false,
dts: {
bundle: true,
},
},
}),
],
source: {
entry: {
Expand Down
6 changes: 3 additions & 3 deletions e2e/cases/auto-external/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { join } from 'node:path';
import { buildAndGetAllResults, buildAndGetResults } from '@e2e/helper';
import { buildAndGetResults } from '@e2e/helper';
import { expect, test } from 'vitest';

test('auto external default should works', async () => {
const fixturePath = join(__dirname, 'default');
const { js, dts } = await buildAndGetAllResults(fixturePath);
const { js, dts } = await buildAndGetResults(fixturePath, 'all');

expect(js.entries.esm).toContain(
'import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react"',
Expand Down Expand Up @@ -40,7 +40,7 @@ test('auto external sub path should works', async () => {

test('auto external false should works', async () => {
const fixturePath = join(__dirname, 'false');
const { js, dts } = await buildAndGetAllResults(fixturePath);
const { js, dts } = await buildAndGetResults(fixturePath, 'all');

expect(js.entries.esm).not.toContain(
'import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react"',
Expand Down
80 changes: 39 additions & 41 deletions e2e/scripts/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,51 @@ type BuildResult = {
isSuccess: boolean;
};

export const buildAndGetResults = async (
export async function buildAndGetResults(
fixturePath: string,
type: 'js' | 'dts' = 'js',
): Promise<BuildResult> => {
type: 'all',
): Promise<{
js: BuildResult;
dts: BuildResult;
}>;
export async function buildAndGetResults(
fixturePath: string,
type?: 'js' | 'dts',
): Promise<BuildResult>;
export async function buildAndGetResults(
fixturePath: string,
type: 'js' | 'dts' | 'all' = 'js',
) {
const rslibConfig = await loadConfig(join(fixturePath, 'rslib.config.ts'));
process.chdir(fixturePath);
const rsbuildInstance = await build(rslibConfig);
const {
origin: { bundlerConfigs, rsbuildConfig },
} = await rsbuildInstance.inspectConfig({ verbose: true });
if (type === 'all') {
const jsResults = await getResults(rslibConfig, fixturePath, 'js');
const dtsResults = await getResults(rslibConfig, fixturePath, 'dts');
return {
js: {
contents: jsResults.contents,
files: jsResults.files,
entries: jsResults.entries,
entryFiles: jsResults.entryFiles,
rspackConfig: bundlerConfigs,
rsbuildConfig: rsbuildConfig,
isSuccess: Boolean(rsbuildInstance),
},
dts: {
contents: dtsResults.contents,
files: dtsResults.files,
entries: dtsResults.entries,
entryFiles: dtsResults.entryFiles,
rspackConfig: bundlerConfigs,
rsbuildConfig: rsbuildConfig,
isSuccess: Boolean(rsbuildInstance),
},
};
}

const results = await getResults(rslibConfig, fixturePath, type);
return {
Expand All @@ -133,41 +168,4 @@ export const buildAndGetResults = async (
rsbuildConfig: rsbuildConfig,
isSuccess: Boolean(rsbuildInstance),
};
};

export const buildAndGetAllResults = async (
fixturePath: string,
): Promise<{
js: BuildResult;
dts: BuildResult;
}> => {
const rslibConfig = await loadConfig(join(fixturePath, 'rslib.config.ts'));
process.chdir(fixturePath);
const rsbuildInstance = await build(rslibConfig);
const {
origin: { bundlerConfigs, rsbuildConfig },
} = await rsbuildInstance.inspectConfig({ verbose: true });

const jsResults = await getResults(rslibConfig, fixturePath, 'js');
const dtsResults = await getResults(rslibConfig, fixturePath, 'dts');
return {
js: {
contents: jsResults.contents,
files: jsResults.files,
entries: jsResults.entries,
entryFiles: jsResults.entryFiles,
rspackConfig: bundlerConfigs,
rsbuildConfig: rsbuildConfig,
isSuccess: Boolean(rsbuildInstance),
},
dts: {
contents: dtsResults.contents,
files: dtsResults.files,
entries: dtsResults.entries,
entryFiles: dtsResults.entryFiles,
rspackConfig: bundlerConfigs,
rsbuildConfig: rsbuildConfig,
isSuccess: Boolean(rsbuildInstance),
},
};
};
}

0 comments on commit f494c82

Please sign in to comment.