Skip to content

Commit 7ac108b

Browse files
committed
test: add testing for CLI execution
1 parent ade0af9 commit 7ac108b

7 files changed

Lines changed: 62 additions & 2 deletions

File tree

packages/rstack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"scripts": {
4242
"build": "rslib",
4343
"dev": "rslib -w",
44-
"test": "echo 'pass'"
44+
"test": "rs test"
4545
},
4646
"dependencies": {
4747
"@rsbuild/core": "catalog:",
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { define } from 'rstack';
2+
3+
define.app({
4+
output: {
5+
filenameHash: false,
6+
},
7+
source: {
8+
entry: {
9+
index: './src/index.js',
10+
},
11+
},
12+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { readFile, rm } from 'node:fs/promises';
2+
import path from 'node:path';
3+
import { expect, test } from 'rstack/test';
4+
import { execCli } from '../helpers/cli.ts';
5+
6+
const cwd = import.meta.dirname;
7+
8+
test('should build with rstack --config', async () => {
9+
await rm(path.join(cwd, 'dist'), { recursive: true, force: true });
10+
11+
execCli(['--config', './custom.config.ts', 'build'], {
12+
cwd,
13+
});
14+
15+
const output = await readFile(path.join(cwd, 'dist/static/js/index.js'), 'utf-8');
16+
expect(output).toContain('rstack config works');
17+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('rstack config works');
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { type ExecFileSyncOptions, execFileSync } from 'node:child_process';
2+
import path from 'node:path';
3+
4+
const RSTACK_BIN_PATH = path.join(import.meta.dirname, '../../bin/rs.js');
5+
6+
export const execCli = (args: string[], options: ExecFileSyncOptions = {}): string => {
7+
const output = execFileSync(process.execPath, [RSTACK_BIN_PATH, ...args], {
8+
...options,
9+
env: {
10+
...process.env,
11+
...options.env,
12+
},
13+
});
14+
15+
return output.toString();
16+
};

packages/rstack/test/tsconfig.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"allowImportingTsExtensions": true,
5+
"noEmit": true,
6+
"rootDir": "..",
7+
"types": ["node", "@rstest/core/globals"]
8+
},
9+
"include": ["./**/*.ts"]
10+
}

rslint.config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ export default defineConfig([
66
{
77
languageOptions: {
88
parserOptions: {
9-
project: ['./packages/*/tsconfig.json', './examples/*/tsconfig.json'],
9+
project: [
10+
'./packages/*/tsconfig.json',
11+
'./packages/*/test/tsconfig.json',
12+
'./examples/*/tsconfig.json',
13+
],
1014
},
1115
},
1216
},

0 commit comments

Comments
 (0)