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
1 change: 1 addition & 0 deletions packages/rstack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
},
"devDependencies": {
"@rspress/core": "catalog:",
"@rstackjs/test-utils": "catalog:",
"@rstest/adapter-rsbuild": "catalog:",
"@rstest/adapter-rslib": "catalog:",
"@types/node": "catalog:",
Expand Down
11 changes: 5 additions & 6 deletions packages/rstack/test/cli/specify-config/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { rm } from 'node:fs/promises';
import path from 'node:path';
import { getDistFiles, getFileContent, test } from '#test-helpers';
import { getDistFiles, getFileContent } from '@rstackjs/test-utils';
import { test } from '#test-helpers';

test('should build with rstack --config', async ({ cwd, execCli, expect }) => {
await rm(path.join(cwd, 'dist'), { recursive: true, force: true });
test('should build with rstack --config', async ({ prepareDist, execCli, expect }) => {
const distPath = await prepareDist();

execCli('build --config ./custom.config.ts');

const files = await getDistFiles(path.join(cwd, 'dist'));
const files = await getDistFiles(distPath);
const output = getFileContent(files, 'static/js/index.js');

expect(output).toContain('specify config works');
Expand Down
9 changes: 4 additions & 5 deletions packages/rstack/test/config/define-app/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { rm } from 'node:fs/promises';
import path from 'node:path';
import { getDistFiles, getFileContent, test } from '#test-helpers';
import { getDistFiles, getFileContent } from '@rstackjs/test-utils';
import { test } from '#test-helpers';

const expectedText = 'define.app works';

test('should build app with define.app config', async ({ cwd, execCli, expect }) => {
const distPath = path.join(cwd, 'dist');
await rm(distPath, { recursive: true, force: true });
test('should build app with define.app config', async ({ prepareDist, execCli, expect }) => {
const distPath = await prepareDist();

try {
execCli('build');
Expand Down
10 changes: 4 additions & 6 deletions packages/rstack/test/config/define-doc/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { rm } from 'node:fs/promises';
import path from 'node:path';
import { getDistFiles, getFileContent, test } from '#test-helpers';
import { getDistFiles, getFileContent } from '@rstackjs/test-utils';
import { test } from '#test-helpers';

const expectedText = 'define.doc works';

test('should build docs with define.doc config', async ({ cwd, execCli, expect }) => {
const distPath = path.join(cwd, 'doc_build');
await rm(distPath, { recursive: true, force: true });
test('should build docs with define.doc config', async ({ prepareDist, execCli, expect }) => {
const distPath = await prepareDist('doc_build');

execCli('doc build');

Expand Down
10 changes: 4 additions & 6 deletions packages/rstack/test/config/define-lib/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { rm } from 'node:fs/promises';
import path from 'node:path';
import { getDistFiles, getFileContent, test } from '#test-helpers';
import { getDistFiles, getFileContent } from '@rstackjs/test-utils';
import { test } from '#test-helpers';

const expectedText = 'define.lib works';

test('should build lib with define.lib config', async ({ cwd, execCli, expect }) => {
const distPath = path.join(cwd, 'dist');
await rm(distPath, { recursive: true, force: true });
test('should build lib with define.lib config', async ({ prepareDist, execCli, expect }) => {
const distPath = await prepareDist();

execCli('lib');

Expand Down
14 changes: 7 additions & 7 deletions packages/rstack/test/config/reload-app-config/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { rm, writeFile } from 'node:fs/promises';
import path from 'node:path';
import { expectFile, getRandomPort, test } from '#test-helpers';
import { getRandomPort, waitForFile } from '@rstackjs/test-utils';
import { test } from '#test-helpers';

test('should restart dev server and reload config when Rstack config changes', async ({
prepareDist,
execCliAsync,
}) => {
const dist1 = path.join(import.meta.dirname, 'dist');
const dist2 = path.join(import.meta.dirname, 'dist-2');
const dist1 = await prepareDist();
const dist2 = await prepareDist('dist-2');
const configFile = path.join(import.meta.dirname, 'test-temp-rstack.config.ts');

await rm(dist1, { recursive: true, force: true });
await rm(dist2, { recursive: true, force: true });
await rm(configFile, { force: true });

await writeFile(
Expand All @@ -28,7 +28,7 @@ define.app({

execCliAsync('dev --config test-temp-rstack.config.ts');

await expectFile(dist1);
await waitForFile(dist1);

await writeFile(
configFile,
Expand All @@ -46,7 +46,7 @@ define.app({
`,
);

await expectFile(dist2);
await waitForFile(dist2);
}, 30_000);

test('should reload config when an imported file changes', async ({ execCliAsync, logHelper }) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/rstack/test/helpers/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type ExecSyncOptions, execSync } from 'node:child_process';
import path from 'node:path';
import type { LogHelper } from './logs.ts';
import type { LogHelper } from '@rstackjs/test-utils';

export const RSTACK_BIN_PATH: string = path.join(import.meta.dirname, '../../bin/rs.js');

Expand Down
9 changes: 9 additions & 0 deletions packages/rstack/test/helpers/cliTest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type ChildProcess, type SpawnOptions, spawn as nodeSpawn } from 'node:child_process';
import path from 'node:path';
import { prepareDist as basePrepareDist } from '@rstackjs/test-utils';
import { test as baseTest } from 'rstack/test';
import { execCli as baseExecCli, type ExecCli, RSTACK_BIN_PATH } from './cli.ts';
import { type ExtendedLogHelper, proxyConsole } from './logs.ts';
Expand All @@ -11,12 +12,15 @@ type Exec = (
childProcess: ChildProcess;
};

type PrepareDist = (distFolderName?: string) => Promise<string>;

export type CliTestFixtures = {
cwd: string;
exec: Exec;
execCli: ExecCli;
execCliAsync: Exec;
logHelper: ExtendedLogHelper;
prepareDist: PrepareDist;
};

type CliTest = ReturnType<typeof baseTest.extend<CliTestFixtures>>;
Expand Down Expand Up @@ -49,6 +53,11 @@ export const test: CliTest = baseTest.extend<CliTestFixtures>({

await use(path.dirname(testPath));
},
prepareDist: async ({ cwd }, use) => {
const prepareDist: PrepareDist = (distFolderName = 'dist') =>
basePrepareDist(path.join(cwd, distFolderName));
await use(prepareDist);
},
logHelper: [
async ({ onTestFailed, task }, use) => {
const logHelper = proxyConsole();
Expand Down
78 changes: 0 additions & 78 deletions packages/rstack/test/helpers/file.ts

This file was deleted.

3 changes: 0 additions & 3 deletions packages/rstack/test/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
export * from './cli.ts';
export * from './cliTest.ts';
export * from './constants.ts';
export * from './file.ts';
export * from './logs.ts';
export * from './utils.ts';
Loading