Skip to content

Commit 9034319

Browse files
committed
refactor(b2c-dx-mcp): migrate page-designer-decorator tests from custom runner to Mocha
Remove custom test runner (index.test.mjs) and consolidate all test cases into the standard Mocha test suite (index.test.ts) for consistency with the monorepo's test framework.
1 parent 63f5f8b commit 9034319

4 files changed

Lines changed: 255 additions & 660 deletions

File tree

packages/b2c-dx-mcp/src/tools/page-designer-decorator/README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,20 +227,22 @@ pnpm test
227227

228228
Comprehensive test suite covers all workflow modes, component discovery, and error handling.
229229

230-
### Manual Test Runner
230+
### Running Tests
231231

232-
For quick manual verification, use the test runner script:
232+
Run the comprehensive Mocha test suite:
233233

234234
```bash
235235
cd packages/b2c-dx-mcp
236-
pnpm build
237-
node test/tools/page-designer-decorator/index.test.mjs all
236+
pnpm run test:agent -- test/tools/page-designer-decorator/index.test.ts
238237
```
239238

240-
Run a specific test case:
241-
```bash
242-
node test/tools/page-designer-decorator/index.test.mjs TC-1.1
243-
```
239+
The test suite covers:
240+
- Component discovery (name-based, kebab-case, nested, path-based, custom paths, name collisions)
241+
- Auto mode (basic, type inference, complex props exclusion, UI-only props exclusion, edge cases)
242+
- Interactive mode (all steps: analyze, select_props, configure_attrs, configure_regions, confirm_generation)
243+
- Error handling (invalid input, invalid step name, missing parameters)
244+
- Edge cases (no props, only complex props, optional props, union types, already decorated components)
245+
- Environment variables (SFCC_WORKING_DIRECTORY)
244246

245247
See [`test/tools/page-designer-decorator/README.md`](../../../test/tools/page-designer-decorator/README.md) for detailed testing instructions.
246248

packages/b2c-dx-mcp/test/tools/page-designer-decorator/README.md

Lines changed: 13 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@
55
The page-designer-decorator tool has comprehensive unit tests covering:
66
- ✅ Tool metadata (name, description, toolsets, isGA)
77
- ✅ Mode selection flow
8-
- ✅ Error handling
8+
- ✅ Auto mode (basic, type inference, complex/UI props exclusion, edge cases)
9+
- ✅ Interactive mode (all steps: analyze, select_props, configure_attrs, configure_regions, confirm_generation)
10+
- ✅ Component resolution (name-based, kebab-case, nested, path-based, custom searchPaths, name collisions)
11+
- ✅ Error handling (invalid input, invalid step name, missing parameters)
912
- ✅ Input validation
13+
- ✅ Edge cases (no props, only complex props, optional props, union types, already decorated components)
14+
- ✅ Environment variables (SFCC_WORKING_DIRECTORY)
1015

11-
Some integration tests may require actual component files in a real workspace to fully validate component resolution.
16+
All tests use the standard Mocha test framework and run with `pnpm test`.
1217

1318
## Testing Approaches
1419

@@ -50,68 +55,28 @@ npx mcp-inspector --cli node bin/dev.js --toolsets STOREFRONTNEXT --allow-non-ga
5055
--args '{"component": "MyComponent"}'
5156
```
5257

53-
### 4. Automated Manual Test Runner
58+
### 4. Running Tests Against a Local Storefront Next Installation
5459

55-
A test runner script is available to quickly verify the tool with various test scenarios:
60+
The Mocha test suite supports testing against a real Storefront Next installation by setting `SFCC_WORKING_DIRECTORY`:
5661

5762
```bash
5863
cd packages/b2c-dx-mcp
59-
pnpm build # Build the package first
60-
node test/tools/page-designer-decorator/index.test.mjs all
61-
```
62-
63-
Run a specific test case:
64-
```bash
65-
node test/tools/page-designer-decorator/index.test.mjs TC-1.1
66-
```
67-
68-
The script covers 24 automated test cases including:
69-
- Component discovery (name-based, path-based, nested, custom paths)
70-
- Auto mode (basic, type inference, complex props exclusion)
71-
- Interactive mode (mode selection, analyze step)
72-
- Error handling (invalid input, missing parameters)
73-
- Edge cases (no props, optional props, union types, collisions)
74-
- Environment variables (SFCC_WORKING_DIRECTORY)
75-
76-
See the script's JSDoc header for a complete list of available test cases.
77-
78-
#### Running Tests Against a Local Storefront Next Installation
79-
80-
The test runner script supports two modes:
81-
82-
**1. Temporary Directory Mode (Default)**
83-
Creates isolated test environments with temporary directories. Ideal for CI/CD and regression testing.
84-
85-
```bash
86-
cd packages/b2c-dx-mcp
87-
pnpm build
88-
node test/tools/page-designer-decorator/index.test.mjs all
89-
```
90-
91-
**2. Real Storefront Next Project Mode**
92-
Test against an existing Storefront Next installation by setting `SFCC_WORKING_DIRECTORY`:
93-
94-
```bash
95-
cd packages/b2c-dx-mcp
96-
pnpm build
9764
SFCC_WORKING_DIRECTORY=/path/to/storefront-next \
98-
node test/tools/page-designer-decorator/index.test.mjs all
65+
pnpm run test:agent -- test/tools/page-designer-decorator/index.test.ts
9966
```
10067

10168
Or set it as an environment variable:
10269
```bash
10370
export SFCC_WORKING_DIRECTORY=/path/to/storefront-next
10471
cd packages/b2c-dx-mcp
105-
pnpm build
106-
node test/tools/page-designer-decorator/index.test.mjs TC-1.1
72+
pnpm run test:agent -- test/tools/page-designer-decorator/index.test.ts
10773
```
10874

10975
**Important Notes for Real Project Mode**:
11076
- Component discovery searches in your real Storefront Next project (`SFCC_WORKING_DIRECTORY`)
111-
- Test components created by the script are placed in a temporary directory (not in your real project)
112-
- The script will **not** modify your real project files (read-only)
77+
- Tests create temporary directories for test components (not in your real project)
78+
- Tests will **not** modify your real project files (read-only)
11379
- Tests will use existing components from your real project if they exist
114-
- If a test component doesn't exist in your real project, the test will show a "component not found" result (this is expected)
11580
- The real project directory is preserved after testing
11681
- To test with specific components, ensure they exist in your real project's `src/components/` directory
11782

0 commit comments

Comments
 (0)