infra frontendTesting: tsconfig.test.json doesn't work in a standalone extension, and webpack.config.js is left behind

Open Beginner friendly
#71 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
node.js, typescript
Domain
cli, tooling

Research direction

Start with the frontendTesting module definition in src/steps/gen-ext-scaffolder.ts and inspect the generated tsconfig.test.json, webpack.config.cjs, and js/package.json. Compare the generated TypeScript includes and shim path with the standalone extension setup described in the issue, and check how the generator handles the old webpack config. Done means a standalone extension gets working test type-checking, only the intended webpack config, and a focused package file diff.

Written by the indexing model from the issue text.

Description

Running flarum-cli infra frontendTesting -n (3.0.15) on an existing standalone (Composer-installed) Flarum 2 extension gives a setup where yarn test runs, but the tests don't type-check and an old file is left behind:

  1. js/tsconfig.test.json points at the monorepo's node_modules. "files": ["../../../node_modules/@flarum/jest-config/shims.d.ts"] only resolves inside flarum/framework. In a standalone extension it should be ./node_modules/@flarum/jest-config/shims.d.ts, as the testing docs show.
  2. js/tsconfig.test.json replaces the base include with ["tests/**/*"]. Tests that import the extension's src then lose core's global typings (../vendor/*/*/js/dist-typings/@types/**/*) and the extension's own declaration files. tsc -p tsconfig.test.json --noEmit fails with Cannot find name 'm', Cannot find name 'flarum', and errors on model attributes added through declaration merging. Repeating the base include with tests added fixes it:
    "include": ["src/**/*", "tests/**/*", "../vendor/*/*/js/dist-typings/@types/**/*", "@types/**/*"],
    
  3. js/webpack.config.js is left in place next to the new js/webpack.config.cjs. The module adds the .cjs file (needed now that "type": "module" is set) but doesn't remove the .js one, which the docs say to rename.
  4. Minor: js/package.json is rewritten with 4-space indentation, so the whole file shows up in the diff.

3.x has the same skeleton tsconfig.test.json and the same frontendTesting module definition in src/steps/gen-ext-scaffolder.ts.

Dominant language
TypeScript
Stars
47
Forks
4
Avg merge
8m
Merged PRs (30d)
2

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from flarum/cli

All issues in flarum/cli

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.