Skip to content

[2.x] Frontend testing setup from docs is unusable for standalone (Composer-installed) extensions — @flarum/jest-config depends on unpublished @flarum/core #4689

Description

@imorland

Summary

The frontend testing docs present a setup that works inside the flarum/framework monorepo but cannot run in a standalone, Composer-installed extension. The docs don't state this limitation; they imply the flow works for any extension (you're told to install only @flarum/jest-config, never @flarum/core).

Root cause

@flarum/jest-config resolves core from the @flarum/core npm package, which is not published to the registry (yarn add @flarum/core → 404). It only exists in the monorepo as a workspace symlink.

  • setup-env.js (runs for every test via setupFilesAfterEnv):
    import mixin from '@flarum/core/src/common/utils/mixin';
    import ExportRegistry from '@flarum/core/src/common/ExportRegistry';
  • src/boostrap/forum.js / common.js (the documented bootstrapForum()):
    import app from '@flarum/core/src/forum/app';
    import { makeUser } from '@flarum/core/tests/factory';
    // ...
    fs.readFileSync('../locale/core.yml', 'utf8')

Reproduction

In a standalone extension, follow the docs exactly (yarn add -D @flarum/jest-config, jest.config.cjs = require('@flarum/jest-config')(), add the test script + "type": "module"), write one trivial test, and run yarn test:

  1. @flarum/core can't be installed (404), so the bootstrap imports are unresolvable.
  2. Mapping @flarum/core/* → the Composer-vendored vendor/flarum/core/js lets resolution proceed, but Jest does not transform that TypeScript (it's outside the js/ rootDir), so setup-env fails before any test with SyntaxError: Unexpected token ':' — even for a test that imports nothing.
  3. bootstrapForum() additionally needs @flarum/core/tests/factory and ../locale/core.yml, whose relative paths only resolve inside the monorepo.

Corroboration: flarum/framework's own messages extension ships the jest config but has empty tests/unit and tests/integration dirs.

What currently is possible standalone

Pure-logic unit tests work if you skip the core-importing global setup and map the specific core utilities you use to their underlying npm packages (e.g. flarum/common/utils/Streammithril/stream). Component/app-bootstrapped tests do not.

Suggested resolutions (any one)

  • Publish @flarum/core to npm (including src/, tests/factory, and locale/) so extensions can depend on it.
  • Make @flarum/jest-config resolve core from the Composer-vendored path (vendor/flarum/core/js) and ensure that source is transformed.
  • At minimum, document the prerequisite/limitation: that frontend tests (especially bootstrap*) currently require developing within the monorepo, and which subset works standalone.

Environment

@flarum/jest-config@2.0.0, standalone extension with flarum/core: ^2.0.0-rc.2 (Composer), vendor/flarum/core/js present, Node 24 / Yarn 1.22.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions