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:
@flarum/core can't be installed (404), so the bootstrap imports are unresolvable.
- 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.
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/Stream → mithril/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.
Summary
The frontend testing docs present a setup that works inside the
flarum/frameworkmonorepo 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-configresolves core from the@flarum/corenpm 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 viasetupFilesAfterEnv):src/boostrap/forum.js/common.js(the documentedbootstrapForum()):Reproduction
In a standalone extension, follow the docs exactly (
yarn add -D @flarum/jest-config,jest.config.cjs = require('@flarum/jest-config')(), add thetestscript +"type": "module"), write one trivial test, and runyarn test:@flarum/corecan't be installed (404), so the bootstrap imports are unresolvable.@flarum/core/*→ the Composer-vendoredvendor/flarum/core/jslets resolution proceed, but Jest does not transform that TypeScript (it's outside thejs/rootDir), sosetup-envfails before any test withSyntaxError: Unexpected token ':'— even for a test that imports nothing.bootstrapForum()additionally needs@flarum/core/tests/factoryand../locale/core.yml, whose relative paths only resolve inside the monorepo.Corroboration:
flarum/framework's ownmessagesextension ships the jest config but has emptytests/unitandtests/integrationdirs.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/Stream→mithril/stream). Component/app-bootstrapped tests do not.Suggested resolutions (any one)
@flarum/coreto npm (includingsrc/,tests/factory, andlocale/) so extensions can depend on it.@flarum/jest-configresolve core from the Composer-vendored path (vendor/flarum/core/js) and ensure that source is transformed.bootstrap*) currently require developing within the monorepo, and which subset works standalone.Environment
@flarum/jest-config@2.0.0, standalone extension withflarum/core: ^2.0.0-rc.2(Composer),vendor/flarum/core/jspresent, Node 24 / Yarn 1.22.