npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@moocfi/exercise-service-test-utils

v0.0.4

Published

Testing utilities that play the host/parent side of the moocfi exercise-plugin iframe protocol: a browser host emulator and Playwright helpers to drive a plugin's views and assert its messages.

Readme

@moocfi/exercise-service-test-utils

Testing utilities that play the parent/host side of the exercise-plugin iframe protocol, so you can drive a plugin's views and observe the messages it emits without a real host.

An exercise service is an iframe app: it posts "ready", the host transfers a MessagePort, and all typed protocol messages (set-state, current-state, height-changed, file-upload, open-dialog, …) flow over that port. To render any view you need a parent to hand over a port and push a set-state; to assert behaviour you need to read the current-state the plugin emits (buried among frequent height-changed messages) and answer file-upload/open-dialog round-trips. This package packages exactly that host.

What's here

  • src/browser/hostEmulator.js — the emulator as a single self-contained arrow-function expression. Inject it as-is with playwright-cli:

    playwright-cli open http://localhost:<port>/iframe          # open the iframe page FIRST
    playwright-cli eval "$(cat src/browser/hostEmulator.js)"     # installs window.__host + hands over the port
    playwright-cli eval "() => window.__host.setState('answer-exercise', { public_spec: [], previous_submission: null })"
    playwright-cli eval "() => window.__host.last('current-state')"

    Once installed, window.__host exposes: setState(viewType, data, overrides?), setStateRaw(state), setLanguage(code), last(type), messages(type?), waitFor(type, predicate?, timeoutMs?), sendUploadResult(requestId, {urls}|{error}), respondToDialog(requestId, confirmed), sendRepositoryExercises(list), sendTestResults(result), and reset(). By default it auto-answers file-upload (with fake stored URLs) and open-dialog (confirm); pass { autoUpload: false } / { autoDialog: false } to drive those responses yourself.

  • src/playwright/createHostEmulator.ts — a typed @playwright/test wrapper. It injects the same emulator source (via page.evaluate) and returns an async handle: setState, setLanguage, lastMessage, waitForMessage(type, predicate?), waitForCurrentState(), waitForViewType(vt), waitForFileUpload(), fileUploadCount(), sendUploadResult, respondToDialog, and driveFileUpload(files, target?). It also exports createNestedHostEmulator() for sandboxed, distinct-origin iframe coverage. See services/example-exercise/playwright/plugin-contract/protocol.spec.ts and services/example-exercise/playwright/iframe-boundary/nested-host.spec.ts for examples.

  • src/protocol/stateBuilders.ts — typed builders for the set-state payloads (answerExerciseState, exerciseEditorState, viewSubmissionState, customViewState) with sane defaults, so specs don't hand-roll the envelope.

How it connects

createHostEmulator() injects into the iframe's own top-level page (where window === window.parent) for fast plugin-contract tests. createNestedHostEmulator() instead creates a sandboxed iframe on a distinct origin and transfers the real MessagePort across that boundary. The nested helper covers cross-realm transport and exact upload bytes; the real @moocfi/exercise-iframe-host remains covered by its own package tests.

Testing

pnpm test runs jest unit tests (state builders + the emulator driven through a mock MessageChannel, no browser). The Playwright wrapper is exercised by package-local playwright/plugin-contract/ and playwright/iframe-boundary/ specs. Run the complete browser suite with pnpm run test:playwright, a single level with pnpm run test:playwright:plugin-contract or pnpm run test:playwright:iframe-boundary, and inspect a failing test with pnpm run test:playwright:debug. CI runs Chromium and Firefox for pull requests and adds WebKit in the full contract job. Failed runs retain Playwright traces, full-page screenshots, and video in test-results/.