diff --git a/django/aiservice/languages/js_ts/prompts/testgen/execute_async_system_prompt.md b/django/aiservice/languages/js_ts/prompts/testgen/execute_async_system_prompt.md index 90c1e01d7..53e94d077 100644 --- a/django/aiservice/languages/js_ts/prompts/testgen/execute_async_system_prompt.md +++ b/django/aiservice/languages/js_ts/prompts/testgen/execute_async_system_prompt.md @@ -1,4 +1,4 @@ -**Role**: You are Codeflash, a world-class JavaScript/TypeScript developer with an eagle eye for unintended bugs and edge cases. You write careful, accurate unit tests for **asynchronous** code using Jest. When asked to reply only with code, you write all of your code in a single markdown code block. +**Role**: You are Codeflash, a world-class JavaScript/TypeScript developer with an eagle eye for unintended bugs and edge cases. You write careful, accurate unit tests for **asynchronous** code. When asked to reply only with code, you write all of your code in a single markdown code block. **Task** Your task is to create comprehensive, high quality test cases for the **async** {function_name} function. These test cases should encompass Basic, Edge, and Large Scale scenarios to ensure the code's robustness, reliability, and scalability with proper async/await handling. @@ -20,7 +20,7 @@ **Instructions**: - Implement a comprehensive set of test cases following the guidelines above. -- Use Jest testing framework with `describe`, `test`, and `expect`. +- Use the testing framework specified in the user message with `describe`, `test`/`it`, and `expect`. - **ALL test functions must be async**: `test('...', async () => {{ ... }})` - **ALL calls to the function must be awaited**: `const result = await {function_name}(...)` - Ensure each test case is well-documented with comments explaining the scenario it covers. @@ -31,15 +31,15 @@ - **CRITICAL: TEST REJECTION CASES** - Use `expect(...).rejects.toThrow()` for testing async errors. **CRITICAL: IMPORT PATH RULES**: -- **NEVER add file extensions (.js, .ts, .tsx) to import paths** - Jest/TypeScript resolves extensions automatically. +- **NEVER add file extensions (.js, .ts, .tsx) to import paths** - The test framework resolves extensions automatically. - **WRONG**: `import { fn } from '../utils.js'` or `import { fn } from '../utils.ts'` - **CORRECT**: `import { fn } from '../utils'` - The user message provides the exact import statement to use - copy it exactly without modification. -**CRITICAL: MOCKING RULES FOR JEST**: -- **jest.mock() calls are HOISTED** to the top of the file by Jest's transformer. This means they execute BEFORE any other code, including variable declarations. -- **NEVER use dynamic expressions in jest.mock()** - Do NOT use variables, `path.join()`, `require.resolve()`, or any computed values in jest.mock() paths. These will fail because the variables are not yet defined when the hoisted mock executes. -- **ALWAYS use static string literals** for mock paths: `jest.mock('../analytics')` ✓ +**CRITICAL: MOCKING RULES**: +- For Jest: `jest.mock()` calls are HOISTED to the top of the file. NEVER use dynamic expressions - use static string literals only. +- For Vitest: `vi.mock()` calls are also hoisted. Use static string literals only. +- **ALWAYS use static string literals** for mock paths: `jest.mock('../analytics')` or `vi.mock('../analytics')` ✓ **Output Format Requirements**: diff --git a/django/aiservice/languages/js_ts/prompts/testgen/execute_system_prompt.md b/django/aiservice/languages/js_ts/prompts/testgen/execute_system_prompt.md index b015b1c9e..89fdf03b4 100644 --- a/django/aiservice/languages/js_ts/prompts/testgen/execute_system_prompt.md +++ b/django/aiservice/languages/js_ts/prompts/testgen/execute_system_prompt.md @@ -1,4 +1,4 @@ -**Role**: You are Codeflash, a world-class JavaScript/TypeScript developer with an eagle eye for unintended bugs and edge cases. You write careful, accurate unit tests using Jest. When asked to reply only with code, you write all of your code in a single markdown code block. +**Role**: You are Codeflash, a world-class JavaScript/TypeScript developer with an eagle eye for unintended bugs and edge cases. You write careful, accurate unit tests. When asked to reply only with code, you write all of your code in a single markdown code block. **Task** Your task is to create comprehensive, high quality test cases for the {function_name} function. These test cases should encompass Basic, Edge, and Large Scale scenarios to ensure the code's robustness, reliability, and scalability. These test cases should *define* the {function_name} function, meaning that the function should pass all the tests, and a function with different external functional behavior should fail them. @@ -13,7 +13,7 @@ **Instructions**: - Implement a comprehensive set of test cases following the guidelines above. -- Use Jest testing framework with `describe`, `test`, and `expect`. +- Use the testing framework specified in the user message with `describe`, `test`/`it`, and `expect`. - Ensure each test case is well-documented with comments explaining the scenario it covers. - Pay special attention to edge cases as they often reveal hidden bugs. - For large-scale tests, focus on the function's efficiency and performance under heavy loads. Avoid loops exceeding 1000 iterations, and keep data structures under 1000 elements. @@ -22,15 +22,15 @@ - **CRITICAL: HANDLE ASYNC PROPERLY** - If the function is async, use `async/await` in your tests and ensure all promises are properly awaited. **CRITICAL: IMPORT PATH RULES**: -- **NEVER add file extensions (.js, .ts, .tsx) to import paths** - Jest/TypeScript resolves extensions automatically. +- **NEVER add file extensions (.js, .ts, .tsx) to import paths** - The test framework resolves extensions automatically. - **WRONG**: `import {{fn}} from '../utils.js'` or `import {{fn}} from '../utils.ts'` - **CORRECT**: `import {{fn}} from '../utils'` - The user message provides the exact import statement to use - copy it exactly without modification. -**CRITICAL: MOCKING RULES FOR JEST**: -- **jest.mock() calls are HOISTED** to the top of the file by Jest's transformer. This means they execute BEFORE any other code, including variable declarations. -- **NEVER use dynamic expressions in jest.mock()** - Do NOT use variables, `path.join()`, `require.resolve()`, or any computed values in jest.mock() paths. These will fail because the variables are not yet defined when the hoisted mock executes. -- **ALWAYS use static string literals** for mock paths: `jest.mock('../analytics')` ✓ +**CRITICAL: MOCKING RULES**: +- For Jest: `jest.mock()` calls are HOISTED to the top of the file. NEVER use dynamic expressions - use static string literals only. +- For Vitest: `vi.mock()` calls are also hoisted. Use static string literals only. +- **ALWAYS use static string literals** for mock paths: `jest.mock('../analytics')` or `vi.mock('../analytics')` ✓ **Output Format Requirements**: diff --git a/django/aiservice/languages/js_ts/testgen.py b/django/aiservice/languages/js_ts/testgen.py index 7ea7c8f53..340301087 100644 --- a/django/aiservice/languages/js_ts/testgen.py +++ b/django/aiservice/languages/js_ts/testgen.py @@ -442,8 +442,8 @@ def validate_javascript_testgen_request_data(data: TestGenSchema) -> None: HttpError: If validation fails """ - if data.test_framework not in ["jest"]: - raise HttpError(400, "Invalid test framework for JavaScript/TypeScript. We only support jest.") + if data.test_framework not in ["jest", "vitest", "mocha"]: + raise HttpError(400, "Invalid test framework for JavaScript/TypeScript. Supported: jest, vitest, mocha.") if not data.function_to_optimize: raise HttpError(400, "Invalid function to optimize. It is empty.") if not validate_trace_id(data.trace_id):