Skip to content
Merged
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
76 changes: 41 additions & 35 deletions tests/integration/dts/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { spawnSync } from 'node:child_process';
import { existsSync } from 'node:fs';
import { join, normalize } from 'node:path';
import stripAnsi from 'strip-ansi';
Expand Down Expand Up @@ -75,15 +76,16 @@ describe('dts when bundle: false', () => {
});

test('abortOnError: false', async () => {
const { restore } = proxyConsole();
const fixturePath = join(__dirname, 'bundle-false', 'abort-on-error');
const { isSuccess } = await buildAndGetResults({
fixturePath,
type: 'dts',

const result = spawnSync('npx', ['rslib', 'build'], {
cwd: fixturePath,
// do not show output in test console
stdio: 'ignore',
shell: true,
});
restore();

expect(isSuccess).toBe(true);
expect(result.status).toBe(0);
});

test('autoExtension: true', async () => {
Expand Down Expand Up @@ -249,14 +251,15 @@ describe('dts when bundle: true', () => {

test('abortOnError: false', async () => {
const fixturePath = join(__dirname, 'bundle', 'abort-on-error');
const { restore } = proxyConsole();
const { isSuccess } = await buildAndGetResults({
fixturePath,
type: 'dts',

const result = spawnSync('npx', ['rslib', 'build'], {
cwd: fixturePath,
// do not show output in test console
stdio: 'ignore',
shell: true,
});
restore();

expect(isSuccess).toBe(true);
expect(result.status).toBe(0);
});

test('autoExtension: true', async () => {
Expand Down Expand Up @@ -513,32 +516,34 @@ describe('dts when build: true', () => {

test('abortOnError: false', async () => {
const fixturePath = join(__dirname, 'build', 'abort-on-error');
const { restore } = proxyConsole();
const { isSuccess } = await buildAndGetResults({
fixturePath,
type: 'dts',

const result = spawnSync('npx', ['rslib', 'build'], {
cwd: fixturePath,
// do not show output in test console
stdio: 'ignore',
shell: true,
});
restore();

expect(isSuccess).toBe(true);
expect(result.status).toBe(0);

const buildInfoPath = join(fixturePath, 'tsconfig.tsbuildinfo');
expect(existsSync(buildInfoPath)).toBeTruthy();
});

test('tsconfig missing some fields - declarationDir or outDir', async () => {
const fixturePath = join(__dirname, 'build', 'tsconfig');
try {
await buildAndGetResults({
fixturePath,
type: 'dts',
});
} catch (err: any) {
// not easy to proxy child process stdout
expect(err.message).toBe(
'Error occurred in esm declaration files generation.',
);
}

const result = spawnSync('npx', ['rslib', 'build'], {
cwd: fixturePath,
// do not show output in test console
stdio: 'pipe',
shell: true,
});

const stdoutOutput = result.stdout ? result.stdout.toString() : '';

expect(result.status).toBe(1);
expect(stdoutOutput).toContain('Please set declarationDir: "./dist/esm"');
});

test('should clean dts dist files', async () => {
Expand Down Expand Up @@ -603,14 +608,15 @@ describe('dts when composite: true', () => {

test('abortOnError: false', async () => {
const fixturePath = join(__dirname, 'composite', 'abort-on-error');
const { restore } = proxyConsole();
const { isSuccess } = await buildAndGetResults({
fixturePath,
type: 'dts',

const result = spawnSync('npx', ['rslib', 'build'], {
cwd: fixturePath,
// do not show output in test console
stdio: 'ignore',
shell: true,
});
restore();

expect(isSuccess).toBe(true);
expect(result.status).toBe(0);

const buildInfoPath = join(fixturePath, 'tsconfig.tsbuildinfo');
expect(existsSync(buildInfoPath)).toBeTruthy();
Expand Down
Loading