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
10 changes: 9 additions & 1 deletion packages/core/tests/exe.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, test } from '@rstest/core';
import { describe, expect, onTestFinished, test } from '@rstest/core';
import path from 'node:path';
import { composeCreateRsbuildConfig } from '../src/config';
import { resolveExeTargets } from '../src/exe';
Expand All @@ -13,6 +13,7 @@ import {
assertSupportedExeRuntime,
isExeSupportedNodeVersion,
} from '../src/exe/version';
import { logger } from '../src/utils/logger';

const packageRoot = path.resolve(import.meta.dirname, '..');

Expand Down Expand Up @@ -192,6 +193,13 @@ describe('experiments.exe', () => {
});

test('should force disable deprecated lib.autoExternal for executables', async () => {
// Suppress the expected warning from exercising the deprecated option.
const originalLogLevel = logger.level;
onTestFinished(() => {
logger.level = originalLogLevel;
});
logger.level = 'error';

const [config] = await withSupportedNodeRuntime(() =>
composeTestRslibConfig({
format: 'esm',
Expand Down
5 changes: 4 additions & 1 deletion packages/create-rslib/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ describe('node', () => {
const { content, filePath } = await loadConfig({ cwd: dir });
expect(filePath).toBe(join(dir, `rslib.config.${c.lang}`));

const rslib = await createRslib({ cwd: dir, config: content });
const rslib = await createRslib({
cwd: dir,
config: { ...content, logLevel: 'warn' },
});
await rslib.build();

const distPath = join(dir, 'dist');
Expand Down
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions tests/integration/auto-external/false/rslib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ import { generateBundleCjsConfig, generateBundleEsmConfig } from 'test-helper';
export default defineConfig({
lib: [
generateBundleEsmConfig({
autoExternal: false,
dts: {
bundle: true,
},
}),
generateBundleCjsConfig({
autoExternal: false,
dts: {
bundle: true,
},
}),
],
output: {
autoExternal: false,
},
source: {
entry: {
index: './src/index.ts',
Expand Down
33 changes: 16 additions & 17 deletions tests/integration/dts-api-new/bundle-false/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { createRslib, loadConfig } from '@rslib/core';
import { describe, expect, onTestFinished, test } from '@rstest/core';
import { describe, expect, test } from '@rstest/core';
import { existsSync, writeFileSync } from 'node:fs';
import { basename, join } from 'node:path';
import { readFile, rm, writeFile } from 'node:fs/promises';
import { setImmediate } from 'node:timers/promises';
import { stripVTControlCharacters } from 'node:util';
import {
buildAndGetResults,
createTempFiles,
getFileBySuffix,
globContentJSON,
proxyConsole,
queryContent,
rslibBuild,
} from 'test-helper';
Expand All @@ -36,24 +34,21 @@ describe('dts with JavaScript API when bundle: false', () => {

test('rebuilds declarations in watch mode', async () => {
const loadedConfig = await loadConfig({ cwd: basicPath });
const { content } = loadedConfig;
content.logLevel = 'info';
loadedConfig.content.logLevel = 'warn';
const rslib = await createRslib({ cwd: basicPath, config: loadedConfig });
let buildFinished = false;
rslib.onAfterCreateRsbuild(({ rsbuild }) => {
rsbuild.onAfterBuild(() => {
buildFinished = true;
});
});
const sourceFile = join(basicPath, 'src/utils.ts');
const original = await readFile(sourceFile, 'utf8');
const configFile = join(basicPath, 'tsconfig.json');
const originalConfig = await readFile(configFile, 'utf8');
const declarationFile = join(basicPath, 'dist/esm/utils.d.ts');
const { logs, restore } = proxyConsole('log');
onTestFinished(restore);
const waitForBuildEnd = async () => {
// The new API backend has no independent watcher. Rspack's afterCompile
// awaits its DTS task before the done hook prints this log.
await expect
.poll(() => stripVTControlCharacters(logs.join('\n')), {
timeout: 10_000,
})
.toContain('built in');
await expect.poll(() => buildFinished, { timeout: 10_000 }).toBe(true);
// Rspack installs its watcher on the next tick after the done hooks.
await setImmediate();
};
Expand All @@ -71,16 +66,16 @@ describe('dts with JavaScript API when bundle: false', () => {
try {
await waitForBuildEnd();
await waitForDeclaration('=> number');
logs.length = 0;
buildFinished = false;
writeFileSync(
sourceFile,
'export const add = (a: number, b: number): string => String(a + b);',
);
await waitForBuildEnd();
await waitForDeclaration('=> string');
logs.length = 0;
const config = JSON.parse(originalConfig);
config.compilerOptions.declarationMap = true;
buildFinished = false;
writeFileSync(configFile, JSON.stringify(config));
await waitForBuildEnd();
await waitForDeclaration('sourceMappingURL=utils.d.ts.map');
Expand Down Expand Up @@ -125,8 +120,9 @@ describe('dts with JavaScript API when bundle: false', () => {
config.compilerOptions.target = 'invalid';
try {
await writeFile(configFile, JSON.stringify(config));
// The DTS subprocess inherits stdio and bypasses Rstest's console capture.
await expect(
rslibBuild({ cwd: basicPath, lib: ['esm'] }),
rslibBuild({ cwd: basicPath, lib: ['esm'], logLevel: 'silent' }),
).rejects.toThrow('declaration files generation');
} finally {
await writeFile(configFile, original);
Expand All @@ -152,6 +148,7 @@ describe('dts with JavaScript API when bundle: false', () => {
await expect(
rslibBuild({
cwd: fixturePath,
logLevel: 'silent',
modifyConfig(config) {
for (const lib of config.lib!) {
lib.dts = { ...(lib.dts as object), abortOnError: undefined };
Expand All @@ -163,6 +160,7 @@ describe('dts with JavaScript API when bundle: false', () => {
const { js, dts } = await buildAndGetResults({
fixturePath,
type: 'all',
logLevel: 'silent',
});
expect(js.isSuccess).toBe(true);
expect(getFileBySuffix(js.contents.esm, 'index.js')).toContain('getA');
Expand Down Expand Up @@ -350,6 +348,7 @@ describe('dts with JavaScript API when bundle: false', () => {
const fixturePath = join(__dirname, 'no-emit-on-error');
const { buildResult } = await rslibBuild({
cwd: fixturePath,
logLevel: 'silent',
modifyConfig(config) {
config.source = {
...config.source,
Expand Down
21 changes: 12 additions & 9 deletions tests/integration/dts-api-new/bundle/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { describe, expect, test } from '@rstest/core';
import { existsSync } from 'node:fs';
import { readdir } from 'node:fs/promises';
import { join } from 'node:path';
import { buildAndGetResults, createTempFiles, queryContent } from 'test-helper';
import {
buildAndGetResults,
createTempFiles,
queryContent,
runCliSync,
} from 'test-helper';

describe('dts with JavaScript API when bundle: true', () => {
test('basic', async () => {
Expand Down Expand Up @@ -47,15 +53,12 @@ describe('dts with JavaScript API when bundle: true', () => {
});

test('abortOnError: false preserves JavaScript output but skips declaration bundling', async () => {
const { js, dts } = await buildAndGetResults({
fixturePath: join(__dirname, 'abort-on-error'),
type: 'all',
});
const fixturePath = join(__dirname, 'abort-on-error');
const { status, stderr } = runCliSync('build', { cwd: fixturePath });

expect(js.isSuccess).toBe(true);
expect(js.files.esm).toHaveLength(1);
expect(js.entries.esm).toContain('getA');
expect(dts.files).toEqual({});
expect(status).toBe(0);
expect(stderr).toContain('TS2322');
expect(await readdir(join(fixturePath, 'dist/esm'))).toEqual(['index.js']);
});

test('autoExtension: true', async () => {
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/exports/build-error/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "exports-build-error-test",
"version": "1.0.0",
"private": true
"private": true,
"type": "module"
}
3 changes: 2 additions & 1 deletion tests/integration/exports/bundleless/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "exports-bundleless-test",
"version": "1.0.0",
"private": true
"private": true,
"type": "module"
}
3 changes: 2 additions & 1 deletion tests/integration/exports/css/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "exports-css-test",
"version": "1.0.0",
"private": true
"private": true,
"type": "module"
}
3 changes: 2 additions & 1 deletion tests/integration/exports/dts/matched/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "exports-dts-matched-test",
"version": "1.0.0",
"private": true
"private": true,
"type": "module"
}
3 changes: 2 additions & 1 deletion tests/integration/exports/dual-format/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "exports-dual-format-test",
"version": "1.0.0",
"private": true
"private": true,
"type": "module"
}
3 changes: 2 additions & 1 deletion tests/integration/exports/esm-only/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "exports-esm-only-test",
"version": "1.0.0",
"private": true
"private": true,
"type": "module"
}
3 changes: 2 additions & 1 deletion tests/integration/exports/include/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "exports-include-test",
"version": "1.0.0",
"private": true
"private": true,
"type": "module"
}
Loading