Skip to content

Export the functions to run tests in browser #50

@abourget

Description

@abourget

Hi there,

I'm using scripterio as such:

import {
  runParsedBlocks,
  testFiles,
} from "https://cdn.jsdelivr.net/npm/scripterio@1.8.0/src/core/context.mjs";

export async function runTests() {
  const urlParams = new URLSearchParams(window.location.search);
  const tagsParam = urlParams.get("tags");
  const tags = tagsParam ? tagsParam.split(",").map((tag) => tag.trim()) : null;

  // To simulate what the CLI runner does
  testFiles.push("ALO");

  const { successes, failures } = await runParsedBlocks(tags);

  console.log(
    "Done\n------------------------- FAILURE REPORT --------------------------------"
  );
  if (failures.length > 0) {
    failures.forEach((failure) => {
      const describeSection = failure.describeStack
        .map((d) => d.name)
        .join(" > ");
      const tags =
        failure.tags.length > 0
          ? "(" + failure.tags.map((tag) => `#${tag}`).join(", ") + ")"
          : "";
      console.log(
        `- %c✗%c Failed: ${describeSection} > ${failure.name} ${tags}`,
        "color: red",
        "color: inherit"
      );
      failure.errors.forEach((error, errorIndex) => {
        console.log(` ${errorIndex + 1}.   ${error.message}`);
        if (error.stack) {
          console.log(`      Stack: ${error.stack}`);
        }
      });
    });

    console.log(`❌ Failures: ${failures.length}`);
  } else {
    console.log(`✅ No failures`);
  }
  console.log(`✅ Successes: ${successes}`);
  if (tags) {
    console.log(`Ran only tags: ${tags.join(", ")}`);
  }
  console.log("TESTS COMPLETE");
}

with the goal of running tests direclty in the browser, through files that use import { describe, test, expect } from "scripterio"; .. and define tests.

I'm using chromedp to run a headless browser to capture the logs on the CLI.

The fact that /src/core/context.mjs isn't exported means I need to go load it by its full path, and make sure I'm loading the exact same CDN version as the scripterio import I use in tests. If it were exposed, I'd be sure scripterio means the same in both, because the importmap would resolve them both to the same thing.

Would it be possible to export some of the runner interfaces ? Even if it's a tiny export.. just enough to run the registered tests.

thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions