|
| 1 | +# Spec Command Testing Implementation Summary |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This implementation adds comprehensive testing for the `nebula spec` command through a new TypeScript template and integration with the existing `nebula create` test infrastructure. |
| 6 | + |
| 7 | +## Files Created |
| 8 | + |
| 9 | +### 1. TypeScript Template (`commands/create/templates/sn/typescript/`) |
| 10 | + |
| 11 | +A complete project template that demonstrates TypeScript property definitions with spec command support: |
| 12 | + |
| 13 | +- **`src/PropertyDef.ts`** - Sample TypeScript interface with JSDoc `@default` annotations |
| 14 | +- **`src/index.js`** - Chart entry point |
| 15 | +- **`src/object-properties.js`** - Initial property defaults (to be replaced by generated file) |
| 16 | +- **`src/meta.json`** - Chart metadata |
| 17 | +- **`_package.json`** - Package config with TypeScript and spec dependencies |
| 18 | +- **`tsconfig.json`** - TypeScript compiler configuration |
| 19 | +- **`nebula.config.js`** - Spec command configuration |
| 20 | +- **`_eslintrc.json`** - ESLint configuration |
| 21 | +- **`_gitignore`** - Git ignore patterns including generated files |
| 22 | +- **`README.md`** - Documentation on using the spec command |
| 23 | +- **`test/integration/example.spec.js`** - Placeholder integration test |
| 24 | +- **`test/integration/playwright.config.js`** - Playwright configuration |
| 25 | + |
| 26 | +### 2. Documentation |
| 27 | + |
| 28 | +- **`docs/spec-command-testing.md`** - Comprehensive testing documentation |
| 29 | + |
| 30 | +## Files Modified |
| 31 | + |
| 32 | +### 1. `commands/create/command.js` |
| 33 | + |
| 34 | +Added `--typescript` option: |
| 35 | + |
| 36 | +```javascript |
| 37 | +yargs.option('typescript', { |
| 38 | + type: 'boolean', |
| 39 | + description: 'Use TypeScript template with spec command support', |
| 40 | + default: false, |
| 41 | +}); |
| 42 | +``` |
| 43 | + |
| 44 | +### 2. `commands/create/lib/create.js` |
| 45 | + |
| 46 | +- Added TypeScript template prompt |
| 47 | +- Added logic to use `sn/typescript` folder when `--typescript` flag is set |
| 48 | +- Updated template selection to prioritize TypeScript over Picasso when both options are available |
| 49 | + |
| 50 | +### 3. `.github/scripts/nebula_create.sh` |
| 51 | + |
| 52 | +Added spec command testing capability: |
| 53 | + |
| 54 | +- New parameters: `TYPESCRIPT` and `TEST_SPEC` |
| 55 | +- Logic to create TypeScript projects with `--typescript` flag |
| 56 | +- Spec command execution and validation: |
| 57 | + - Verifies `generated-default-properties.ts` is created |
| 58 | + - Verifies JSON schema file is created |
| 59 | + - Validates schema structure (`$id`, `definitions`) |
| 60 | + - Validates defaults file structure |
| 61 | + - Comprehensive error messages |
| 62 | + |
| 63 | +### 4. `.github/workflows/ci.yml` |
| 64 | + |
| 65 | +- Added new test step: "Create Nebula TypeScript project with spec command test" |
| 66 | +- Added artifact upload for generated spec files |
| 67 | +- Test runs alongside existing Picasso and mashup template tests |
| 68 | + |
| 69 | +## Test Flow |
| 70 | + |
| 71 | +``` |
| 72 | +1. CI Job: test-create |
| 73 | + ↓ |
| 74 | +2. Create TypeScript project |
| 75 | + ./commands/cli/lib/index.js create typescript-chart --typescript |
| 76 | + ↓ |
| 77 | +3. Link local packages |
| 78 | + (stardust, cli, build, serve) |
| 79 | + ↓ |
| 80 | +4. Run spec command |
| 81 | + yarn run spec |
| 82 | + ↓ |
| 83 | +5. Validate generated files |
| 84 | + - generated-default-properties.ts |
| 85 | + - <name>-properties.schema.json |
| 86 | + ↓ |
| 87 | +6. Validate file structure |
| 88 | + - Schema has $id and definitions |
| 89 | + - Defaults has proper TypeScript structure |
| 90 | + ↓ |
| 91 | +7. Build project |
| 92 | + yarn run build |
| 93 | + ↓ |
| 94 | +8. Run e2e tests |
| 95 | + yarn run test:e2e |
| 96 | + ↓ |
| 97 | +9. Upload artifacts |
| 98 | + (generated files for inspection) |
| 99 | +``` |
| 100 | + |
| 101 | +## Usage Examples |
| 102 | + |
| 103 | +### Create TypeScript Project Locally |
| 104 | + |
| 105 | +```bash |
| 106 | +# Using CLI directly |
| 107 | +./commands/cli/lib/index.js create my-chart --typescript |
| 108 | + |
| 109 | +# Using create command interactively |
| 110 | +./commands/cli/lib/index.js create my-chart |
| 111 | +# Will prompt for TypeScript option |
| 112 | +``` |
| 113 | + |
| 114 | +### Run Tests Locally |
| 115 | + |
| 116 | +```bash |
| 117 | +# Build monorepo |
| 118 | +yarn build |
| 119 | + |
| 120 | +# Run create test with spec validation |
| 121 | +.github/scripts/nebula_create.sh test-chart none false false true true true true |
| 122 | +# ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ |
| 123 | +# name pic mash inst bld tst ts spec |
| 124 | + |
| 125 | +# Check generated files |
| 126 | +ls -la test-chart/generated/ |
| 127 | +cat test-chart/generated/generated-default-properties.ts |
| 128 | +``` |
| 129 | + |
| 130 | +### CI Testing |
| 131 | + |
| 132 | +The TypeScript template test runs automatically in the `test-create` job: |
| 133 | + |
| 134 | +```yaml |
| 135 | +- name: Create Nebula TypeScript project with spec command test |
| 136 | + run: .github/scripts/nebula_create.sh generated/typescript-chart none false false true true true true |
| 137 | +``` |
| 138 | +
|
| 139 | +## Validation Checks |
| 140 | +
|
| 141 | +The test validates: |
| 142 | +
|
| 143 | +### 1. File Creation |
| 144 | +
|
| 145 | +✓ `generated/generated-default-properties.ts` exists |
| 146 | +✓ `generated/*-properties.schema.json` exists |
| 147 | + |
| 148 | +### 2. Schema Structure |
| 149 | + |
| 150 | +✓ Contains `"$id"` field |
| 151 | +✓ Contains `"definitions"` object |
| 152 | +✓ Valid JSON format |
| 153 | + |
| 154 | +### 3. Defaults Structure |
| 155 | + |
| 156 | +✓ Contains TypeScript const declaration |
| 157 | +✓ Proper syntax: `const <Name>Defaults: ...` |
| 158 | + |
| 159 | +### 4. Build Success |
| 160 | + |
| 161 | +✓ Project builds without errors |
| 162 | +✓ E2E tests pass |
| 163 | + |
| 164 | +## Integration with Existing Tests |
| 165 | + |
| 166 | +The spec command test is integrated into the existing `test-create` CI job, which already tests: |
| 167 | + |
| 168 | +- Picasso template (none) |
| 169 | +- Picasso template (barchart) |
| 170 | +- Mashup template |
| 171 | + |
| 172 | +Now also includes: |
| 173 | + |
| 174 | +- **TypeScript template with spec command** |
| 175 | + |
| 176 | +All tests run in parallel as part of the same job, sharing the built workspace artifact. |
| 177 | + |
| 178 | +## Benefits |
| 179 | + |
| 180 | +1. **Comprehensive Coverage**: Tests the entire spec command workflow end-to-end |
| 181 | +2. **Real-World Usage**: Uses actual template generation and package linking |
| 182 | +3. **Validation**: Ensures generated files have correct structure |
| 183 | +4. **CI Integration**: Runs automatically on every PR and push |
| 184 | +5. **Artifacts**: Generated files uploaded for manual inspection |
| 185 | +6. **Documentation**: Complete docs for future maintenance |
| 186 | + |
| 187 | +## Future Enhancements |
| 188 | + |
| 189 | +Potential improvements: |
| 190 | + |
| 191 | +- Add unit tests for spec command logic |
| 192 | +- Test with more complex TypeScript interfaces |
| 193 | +- Validate JSON schema compliance with standards |
| 194 | +- Test defaults file type-checking |
| 195 | +- Add snapshot testing for generated content |
| 196 | +- Test error cases (invalid TypeScript, missing annotations, etc.) |
| 197 | + |
| 198 | +## Commands for Testing |
| 199 | + |
| 200 | +```bash |
| 201 | +# Local development |
| 202 | +yarn build |
| 203 | +.github/scripts/nebula_create.sh test-ts none false false true true true true |
| 204 | +
|
| 205 | +# CI (automatic) |
| 206 | +# Runs as part of test-create job on every PR |
| 207 | +
|
| 208 | +# Manual spec command in generated project |
| 209 | +cd generated/typescript-chart |
| 210 | +yarn run spec |
| 211 | +ls -la generated/ |
| 212 | +
|
| 213 | +# View generated defaults |
| 214 | +cat generated/generated-default-properties.ts |
| 215 | +
|
| 216 | +# View generated schema |
| 217 | +cat generated/*-properties.schema.json | jq '.' |
| 218 | +``` |
| 219 | + |
| 220 | +## Notes |
| 221 | + |
| 222 | +- Template uses JSDoc `@default` annotations for default value extraction |
| 223 | +- Generated files are gitignored by default |
| 224 | +- TypeScript is a devDependency only (runtime uses JavaScript) |
| 225 | +- Spec command is optional - charts can still use manual property definitions |
| 226 | +- Compatible with all existing nebula.js workflows (serve, build, sense) |
0 commit comments