mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-02 20:43:36 +00:00
style: fix formatting with Prettier
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,65 +1,59 @@
|
||||
import { describe, it, expect, beforeEach } from "vitest";
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import {
|
||||
setRunningState,
|
||||
getErrorMessage,
|
||||
getSpecRegenerationStatus,
|
||||
} from "@/routes/app-spec/common.js";
|
||||
} from '@/routes/app-spec/common.js';
|
||||
|
||||
describe("app-spec/common.ts", () => {
|
||||
describe('app-spec/common.ts', () => {
|
||||
beforeEach(() => {
|
||||
// Reset state before each test
|
||||
setRunningState(false, null);
|
||||
});
|
||||
|
||||
describe("setRunningState", () => {
|
||||
it("should set isRunning to true when running is true", () => {
|
||||
describe('setRunningState', () => {
|
||||
it('should set isRunning to true when running is true', () => {
|
||||
setRunningState(true);
|
||||
expect(getSpecRegenerationStatus().isRunning).toBe(true);
|
||||
});
|
||||
|
||||
it("should set isRunning to false when running is false", () => {
|
||||
it('should set isRunning to false when running is false', () => {
|
||||
setRunningState(true);
|
||||
setRunningState(false);
|
||||
expect(getSpecRegenerationStatus().isRunning).toBe(false);
|
||||
});
|
||||
|
||||
it("should set currentAbortController when provided", () => {
|
||||
it('should set currentAbortController when provided', () => {
|
||||
const controller = new AbortController();
|
||||
setRunningState(true, controller);
|
||||
expect(getSpecRegenerationStatus().currentAbortController).toBe(
|
||||
controller
|
||||
);
|
||||
expect(getSpecRegenerationStatus().currentAbortController).toBe(controller);
|
||||
});
|
||||
|
||||
it("should set currentAbortController to null when not provided", () => {
|
||||
it('should set currentAbortController to null when not provided', () => {
|
||||
const controller = new AbortController();
|
||||
setRunningState(true, controller);
|
||||
setRunningState(false);
|
||||
expect(getSpecRegenerationStatus().currentAbortController).toBe(null);
|
||||
});
|
||||
|
||||
it("should set currentAbortController to null when explicitly passed null", () => {
|
||||
it('should set currentAbortController to null when explicitly passed null', () => {
|
||||
const controller = new AbortController();
|
||||
setRunningState(true, controller);
|
||||
setRunningState(true, null);
|
||||
expect(getSpecRegenerationStatus().currentAbortController).toBe(null);
|
||||
});
|
||||
|
||||
it("should update state multiple times correctly", () => {
|
||||
it('should update state multiple times correctly', () => {
|
||||
const controller1 = new AbortController();
|
||||
const controller2 = new AbortController();
|
||||
|
||||
setRunningState(true, controller1);
|
||||
expect(getSpecRegenerationStatus().isRunning).toBe(true);
|
||||
expect(getSpecRegenerationStatus().currentAbortController).toBe(
|
||||
controller1
|
||||
);
|
||||
expect(getSpecRegenerationStatus().currentAbortController).toBe(controller1);
|
||||
|
||||
setRunningState(true, controller2);
|
||||
expect(getSpecRegenerationStatus().isRunning).toBe(true);
|
||||
expect(getSpecRegenerationStatus().currentAbortController).toBe(
|
||||
controller2
|
||||
);
|
||||
expect(getSpecRegenerationStatus().currentAbortController).toBe(controller2);
|
||||
|
||||
setRunningState(false, null);
|
||||
expect(getSpecRegenerationStatus().isRunning).toBe(false);
|
||||
@@ -67,42 +61,42 @@ describe("app-spec/common.ts", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("getErrorMessage", () => {
|
||||
it("should return message from Error instance", () => {
|
||||
const error = new Error("Test error message");
|
||||
expect(getErrorMessage(error)).toBe("Test error message");
|
||||
describe('getErrorMessage', () => {
|
||||
it('should return message from Error instance', () => {
|
||||
const error = new Error('Test error message');
|
||||
expect(getErrorMessage(error)).toBe('Test error message');
|
||||
});
|
||||
|
||||
it("should return 'Unknown error' for non-Error objects", () => {
|
||||
expect(getErrorMessage("string error")).toBe("Unknown error");
|
||||
expect(getErrorMessage(123)).toBe("Unknown error");
|
||||
expect(getErrorMessage(null)).toBe("Unknown error");
|
||||
expect(getErrorMessage(undefined)).toBe("Unknown error");
|
||||
expect(getErrorMessage({})).toBe("Unknown error");
|
||||
expect(getErrorMessage([])).toBe("Unknown error");
|
||||
expect(getErrorMessage('string error')).toBe('Unknown error');
|
||||
expect(getErrorMessage(123)).toBe('Unknown error');
|
||||
expect(getErrorMessage(null)).toBe('Unknown error');
|
||||
expect(getErrorMessage(undefined)).toBe('Unknown error');
|
||||
expect(getErrorMessage({})).toBe('Unknown error');
|
||||
expect(getErrorMessage([])).toBe('Unknown error');
|
||||
});
|
||||
|
||||
it("should return message from Error with empty message", () => {
|
||||
const error = new Error("");
|
||||
expect(getErrorMessage(error)).toBe("");
|
||||
it('should return message from Error with empty message', () => {
|
||||
const error = new Error('');
|
||||
expect(getErrorMessage(error)).toBe('');
|
||||
});
|
||||
|
||||
it("should handle Error objects with custom properties", () => {
|
||||
const error = new Error("Base message");
|
||||
(error as any).customProp = "custom value";
|
||||
expect(getErrorMessage(error)).toBe("Base message");
|
||||
it('should handle Error objects with custom properties', () => {
|
||||
const error = new Error('Base message');
|
||||
(error as any).customProp = 'custom value';
|
||||
expect(getErrorMessage(error)).toBe('Base message');
|
||||
});
|
||||
|
||||
it("should handle Error objects created with different constructors", () => {
|
||||
it('should handle Error objects created with different constructors', () => {
|
||||
class CustomError extends Error {
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
this.name = "CustomError";
|
||||
this.name = 'CustomError';
|
||||
}
|
||||
}
|
||||
|
||||
const customError = new CustomError("Custom error message");
|
||||
expect(getErrorMessage(customError)).toBe("Custom error message");
|
||||
const customError = new CustomError('Custom error message');
|
||||
expect(getErrorMessage(customError)).toBe('Custom error message');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { describe, it, expect } from 'vitest';
|
||||
|
||||
describe("app-spec/parse-and-create-features.ts - JSON extraction", () => {
|
||||
describe('app-spec/parse-and-create-features.ts - JSON extraction', () => {
|
||||
// Test the JSON extraction regex pattern used in parseAndCreateFeatures
|
||||
const jsonExtractionPattern = /\{[\s\S]*"features"[\s\S]*\}/;
|
||||
|
||||
describe("JSON extraction regex", () => {
|
||||
it("should extract JSON with features array", () => {
|
||||
describe('JSON extraction regex', () => {
|
||||
it('should extract JSON with features array', () => {
|
||||
const content = `Here is the response:
|
||||
{
|
||||
"features": [
|
||||
@@ -26,7 +26,7 @@ describe("app-spec/parse-and-create-features.ts - JSON extraction", () => {
|
||||
expect(match![0]).toContain('"id": "feature-1"');
|
||||
});
|
||||
|
||||
it("should extract JSON with multiple features", () => {
|
||||
it('should extract JSON with multiple features', () => {
|
||||
const content = `Some text before
|
||||
{
|
||||
"features": [
|
||||
@@ -49,7 +49,7 @@ Some text after`;
|
||||
expect(match![0]).toContain('"feature-2"');
|
||||
});
|
||||
|
||||
it("should extract JSON with nested objects and arrays", () => {
|
||||
it('should extract JSON with nested objects and arrays', () => {
|
||||
const content = `Response:
|
||||
{
|
||||
"features": [
|
||||
@@ -69,7 +69,7 @@ Some text after`;
|
||||
expect(match![0]).toContain('"dep-1"');
|
||||
});
|
||||
|
||||
it("should handle JSON with whitespace and newlines", () => {
|
||||
it('should handle JSON with whitespace and newlines', () => {
|
||||
const content = `Text before
|
||||
{
|
||||
"features": [
|
||||
@@ -87,7 +87,7 @@ Text after`;
|
||||
expect(match![0]).toContain('"features"');
|
||||
});
|
||||
|
||||
it("should extract JSON when features array is empty", () => {
|
||||
it('should extract JSON when features array is empty', () => {
|
||||
const content = `Response:
|
||||
{
|
||||
"features": []
|
||||
@@ -96,10 +96,10 @@ Text after`;
|
||||
const match = content.match(jsonExtractionPattern);
|
||||
expect(match).not.toBeNull();
|
||||
expect(match![0]).toContain('"features"');
|
||||
expect(match![0]).toContain("[]");
|
||||
expect(match![0]).toContain('[]');
|
||||
});
|
||||
|
||||
it("should not match content without features key", () => {
|
||||
it('should not match content without features key', () => {
|
||||
const content = `{
|
||||
"otherKey": "value"
|
||||
}`;
|
||||
@@ -108,13 +108,13 @@ Text after`;
|
||||
expect(match).toBeNull();
|
||||
});
|
||||
|
||||
it("should not match content without JSON structure", () => {
|
||||
const content = "Just plain text with features mentioned";
|
||||
it('should not match content without JSON structure', () => {
|
||||
const content = 'Just plain text with features mentioned';
|
||||
const match = content.match(jsonExtractionPattern);
|
||||
expect(match).toBeNull();
|
||||
});
|
||||
|
||||
it("should extract JSON when features key appears multiple times", () => {
|
||||
it('should extract JSON when features key appears multiple times', () => {
|
||||
const content = `Before:
|
||||
{
|
||||
"features": [
|
||||
@@ -132,7 +132,7 @@ After: The word "features" appears again`;
|
||||
expect(match![0]).toContain('"features"');
|
||||
});
|
||||
|
||||
it("should handle JSON with escaped quotes", () => {
|
||||
it('should handle JSON with escaped quotes', () => {
|
||||
const content = `{
|
||||
"features": [
|
||||
{
|
||||
@@ -147,7 +147,7 @@ After: The word "features" appears again`;
|
||||
expect(match![0]).toContain('"features"');
|
||||
});
|
||||
|
||||
it("should extract JSON with complex nested structure", () => {
|
||||
it('should extract JSON with complex nested structure', () => {
|
||||
const content = `Response:
|
||||
{
|
||||
"features": [
|
||||
@@ -177,8 +177,8 @@ After: The word "features" appears again`;
|
||||
});
|
||||
});
|
||||
|
||||
describe("JSON parsing validation", () => {
|
||||
it("should parse valid feature JSON structure", () => {
|
||||
describe('JSON parsing validation', () => {
|
||||
it('should parse valid feature JSON structure', () => {
|
||||
const validJson = `{
|
||||
"features": [
|
||||
{
|
||||
@@ -196,11 +196,11 @@ After: The word "features" appears again`;
|
||||
expect(parsed.features).toBeDefined();
|
||||
expect(Array.isArray(parsed.features)).toBe(true);
|
||||
expect(parsed.features.length).toBe(1);
|
||||
expect(parsed.features[0].id).toBe("feature-1");
|
||||
expect(parsed.features[0].title).toBe("Test Feature");
|
||||
expect(parsed.features[0].id).toBe('feature-1');
|
||||
expect(parsed.features[0].title).toBe('Test Feature');
|
||||
});
|
||||
|
||||
it("should handle features with optional fields", () => {
|
||||
it('should handle features with optional fields', () => {
|
||||
const jsonWithOptionalFields = `{
|
||||
"features": [
|
||||
{
|
||||
@@ -213,14 +213,14 @@ After: The word "features" appears again`;
|
||||
}`;
|
||||
|
||||
const parsed = JSON.parse(jsonWithOptionalFields);
|
||||
expect(parsed.features[0].id).toBe("feature-1");
|
||||
expect(parsed.features[0].id).toBe('feature-1');
|
||||
expect(parsed.features[0].priority).toBe(2);
|
||||
// description and dependencies are optional
|
||||
expect(parsed.features[0].description).toBeUndefined();
|
||||
expect(parsed.features[0].dependencies).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should handle features with dependencies", () => {
|
||||
it('should handle features with dependencies', () => {
|
||||
const jsonWithDeps = `{
|
||||
"features": [
|
||||
{
|
||||
@@ -238,7 +238,7 @@ After: The word "features" appears again`;
|
||||
|
||||
const parsed = JSON.parse(jsonWithDeps);
|
||||
expect(parsed.features[0].dependencies).toEqual([]);
|
||||
expect(parsed.features[1].dependencies).toEqual(["feature-1"]);
|
||||
expect(parsed.features[1].dependencies).toEqual(['feature-1']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user