Skip to content

Commit 70efec1

Browse files
committed
feat: add vitest for testing and implement tests for CLI commands and create command templates
1 parent 8281670 commit 70efec1

File tree

5 files changed

+79
-10
lines changed

5 files changed

+79
-10
lines changed

packages/cli/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"scripts": {
1111
"build": "tsup",
1212
"dev": "tsup --watch",
13+
"test": "vitest run",
1314
"lint": "eslint src"
1415
},
1516
"keywords": [
@@ -40,6 +41,7 @@
4041
"devDependencies": {
4142
"@types/node": "^25.1.0",
4243
"tsup": "^8.0.2",
43-
"typescript": "^5.3.3"
44+
"typescript": "^5.3.3",
45+
"vitest": "^4.0.18"
4446
}
4547
}

packages/cli/src/commands/create.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import fs from 'fs';
44
import path from 'path';
55
import { execSync } from 'child_process';
66

7-
const templates = {
7+
export const templates = {
88
plugin: {
99
description: 'Create a new ObjectStack plugin',
1010
files: {
@@ -102,7 +102,7 @@ MIT
102102
description: `ObjectStack Example: ${name}`,
103103
scripts: {
104104
build: 'objectstack compile',
105-
dev: 'tsx watch objectstack.config.ts',
105+
dev: 'objectstack dev',
106106
test: 'vitest',
107107
},
108108
dependencies: {
@@ -120,20 +120,20 @@ MIT
120120
'objectstack.config.ts': (name: string) => `import { defineStack } from '@objectstack/spec';
121121
122122
export default defineStack({
123-
metadata: {
123+
manifest: {
124124
name: '${name}',
125125
version: '0.1.0',
126126
description: '${name} example application',
127127
},
128128
129-
objects: {
129+
objects: [
130130
// Define your data objects here
131-
},
131+
// { name: 'my_object', fields: { ... } }
132+
],
132133
133-
ui: {
134-
apps: [],
135-
views: [],
136-
},
134+
apps: [
135+
// Define your apps here
136+
],
137137
});
138138
`,
139139
'README.md': (name: string) => `# ${name} Example

packages/cli/test/commands.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { compileCommand } from '../src/commands/compile';
3+
import { serveCommand } from '../src/commands/serve';
4+
import { devCommand } from '../src/commands/dev';
5+
import { doctorCommand } from '../src/commands/doctor';
6+
import { createCommand } from '../src/commands/create';
7+
import { testCommand } from '../src/commands/test';
8+
9+
describe('CLI Commands', () => {
10+
it('should have compile command', () => {
11+
expect(compileCommand.name()).toBe('compile');
12+
expect(compileCommand.description()).toContain('Compile');
13+
});
14+
15+
it('should have serve command', () => {
16+
expect(serveCommand.name()).toBe('serve');
17+
expect(serveCommand.description()).toContain('server');
18+
});
19+
20+
it('should have dev command', () => {
21+
expect(devCommand.name()).toBe('dev');
22+
expect(devCommand.description()).toContain('development mode');
23+
});
24+
25+
it('should have doctor command', () => {
26+
expect(doctorCommand.name()).toBe('doctor');
27+
expect(doctorCommand.description()).toContain('health');
28+
});
29+
30+
it('should have create command', () => {
31+
expect(createCommand.name()).toBe('create');
32+
expect(createCommand.description()).toContain('Create');
33+
});
34+
35+
it('should have test command', () => {
36+
expect(testCommand.name()).toBe('test:run');
37+
expect(testCommand.description()).toContain('Quality Protocol');
38+
});
39+
});

packages/cli/test/create.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { templates } from '../src/commands/create';
3+
4+
describe('Create Command Templates', () => {
5+
describe('Example Template', () => {
6+
it('should generate correct package.json scripts', () => {
7+
const packageJsonFn = templates.example.files['package.json'];
8+
const packageJson = packageJsonFn('test-app');
9+
10+
expect(packageJson.scripts.dev).toBe('objectstack dev');
11+
expect(packageJson.scripts.build).toBe('objectstack compile');
12+
expect(packageJson.dependencies['@objectstack/cli']).toBe('workspace:*');
13+
});
14+
});
15+
16+
describe('Plugin Template', () => {
17+
it('should generate correct dependencies', () => {
18+
const packageJsonFn = templates.plugin.files['package.json'];
19+
const packageJson = packageJsonFn('test-plugin');
20+
21+
expect(packageJson.dependencies).toHaveProperty('@objectstack/spec');
22+
expect(packageJson.keywords).toContain('test-plugin');
23+
});
24+
});
25+
});

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)