|
| 1 | +"""JavaScript runtime files for codeflash test instrumentation. |
| 2 | +
|
| 3 | +This module provides paths to JavaScript files that are injected into |
| 4 | +user projects during test instrumentation and execution. |
| 5 | +""" |
| 6 | + |
| 7 | +from pathlib import Path |
| 8 | + |
| 9 | +# Directory containing the JavaScript runtime files |
| 10 | +RUNTIME_DIR = Path(__file__).parent |
| 11 | + |
| 12 | + |
| 13 | +def get_jest_helper_path() -> Path: |
| 14 | + """Get the path to the Jest helper file. |
| 15 | +
|
| 16 | + This file provides capture/capturePerf/capturePerfLooped functions |
| 17 | + for instrumenting Jest tests to record function inputs, outputs, and timing. |
| 18 | + """ |
| 19 | + return RUNTIME_DIR / "codeflash-jest-helper.js" |
| 20 | + |
| 21 | + |
| 22 | +def get_comparator_path() -> Path: |
| 23 | + """Get the path to the comparator module. |
| 24 | +
|
| 25 | + This file provides deep comparison logic for JavaScript values, |
| 26 | + handling special cases like NaN, Infinity, circular references, etc. |
| 27 | + """ |
| 28 | + return RUNTIME_DIR / "codeflash-comparator.js" |
| 29 | + |
| 30 | + |
| 31 | +def get_compare_results_path() -> Path: |
| 32 | + """Get the path to the compare-results script. |
| 33 | +
|
| 34 | + This file provides the entry point for comparing test results |
| 35 | + between original and optimized code. |
| 36 | + """ |
| 37 | + return RUNTIME_DIR / "codeflash-compare-results.js" |
| 38 | + |
| 39 | + |
| 40 | +def get_serializer_path() -> Path: |
| 41 | + """Get the path to the serializer module. |
| 42 | +
|
| 43 | + This file provides serialization utilities for JavaScript values, |
| 44 | + handling complex types that JSON.stringify cannot handle. |
| 45 | + """ |
| 46 | + return RUNTIME_DIR / "codeflash-serializer.js" |
| 47 | + |
| 48 | + |
| 49 | +def get_all_runtime_files() -> list[Path]: |
| 50 | + """Get paths to all JavaScript runtime files. |
| 51 | +
|
| 52 | + Returns a list of all JS files that should be copied to the user's project. |
| 53 | + """ |
| 54 | + return [ |
| 55 | + get_jest_helper_path(), |
| 56 | + get_comparator_path(), |
| 57 | + get_compare_results_path(), |
| 58 | + get_serializer_path(), |
| 59 | + ] |
0 commit comments