Skip to main content

js_ts_generate_tests

Function js_ts_generate_tests 

Source
pub fn js_ts_generate_tests<'a, F, M>(
    modules: &'a [(&'a AIRModule, &'a Path)],
    framework: &str,
    file_ext: &str,
    import_ext: &str,
    output_path: F,
    make_emitter: M,
) -> Result<TestArtifacts, CodegenError>
where F: Fn(&'a AIRModule, &'a Path, bool) -> PathBuf, M: for<'b> FnOnce(&'b [(&'b AIRModule, &'b Path)]) -> Box<dyn JsTsExprEmitter>,
Expand description

Build the Vitest/Jest test file for the project’s @test functions (S7), shared by the JS and TS backends (identical apart from the file extension and the concrete emit context, both injected by the caller).

  • framework: "jest" → Jest globals; anything else → Vitest import.
  • file_ext: the test file’s own extension ("js" / "ts").
  • import_ext: the extension to use in import specifiers. For JS this is "js"; for TS it is also "js" — TS/ESM specifiers reference the emitted .js, which tsc’s .js.ts resolution follows (and a strict tsc --noEmit rejects a .ts specifier without allowImportingTsExtensions).
  • output_path: maps a module to its emitted file path (entry → main.<ext>).
  • make_emitter: builds the per-program expression emitter (with the same cross-module registries the runtime tree uses).

Imports each module’s public functions by name and lowers expect(actual).<assertion>(expected) chains to the framework’s matcher API. Returns a single bock.test.<file_ext> file (no entry wiring).

§Errors

Propagates CodegenError from expression lowering.