Fresh Windows checkout: lint, the root build and `scratch-gui` unit tests fail without any code changes

Open
#750 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
eslint, javascript, node.js

Research direction

Start with the root .gitattributes and packages/scratch-gui/package.json; the issue identifies the three failing commands and their causes. Check the existing *.js line-ending rule, the neighboring build scripts, and the quoted Jest patterns in scratch-storage. Done when a fresh Windows checkout passes lint and the root build, and test:unit runs only the unit suites.

Written by the indexing model from the issue text.

Description

Hello! Windows-native developer here. I found a few issues that come up when using Windows and they are small and easy changes that would allow better cross-os developer collaboration. None of these issues affect scratch users or CI, and each is a one-line fix. I searched issues and PRs and found no prior work or reports on these. Details below:

Expected Behavior

On a fresh clone of develop with npm ci done, a Windows contributor can run the same commands
as on Linux or macOS with the same results:

  • npm run lint / npm run test:lint passes in every package.
  • npm run build from the repo root builds all eight packages.
  • npm run test:unit in packages/scratch-gui runs only the unit suites.

Actual Behavior

Three independent things go wrong, none of which involve a code change. CI is unaffected because
it runs on Linux. Each has a one-line cause and a workaround.

1. Lint fails in seven of eight packages because .mjs files check out with CRLF

With Git for Windows' default core.autocrlf=true, every eslint.config.mjs, typedoc.config.mjs,
prettier.config.mjs and scripts/prepare.mjs is checked out with CRLF. ESLint then reports one
error per line in each of them:

  1:59   error  Expected linebreaks to be 'LF' but found 'CRLF'  @stylistic/linebreak-style
  2:45   error  Expected linebreaks to be 'LF' but found 'CRLF'  @stylistic/linebreak-style
  ...

and in task-herder Prettier fails the same way:

[warn] eslint.config.mjs
[warn] prettier.config.mjs
[warn] Code style issues found in 2 files. Run Prettier with --write to fix.

Error counts on an untouched checkout: scratch-gui 241, scratch-paint 72, scratch-vm 56,
scratch-render 53, scratch-svg-renderer 52, scratch-storage 47. Only scratch-media-lib-scripts
passes, because it has no .mjs files.

Cause: .gitattributes sets text eol=lf for *.js, *.jsx, *.ts, *.tsx, *.json and many
other types, but has no entry for *.mjs. git check-attr eol -- packages/scratch-vm/eslint.config.mjs
reports eol: unspecified, so the 14 tracked .mjs files follow core.autocrlf instead.

Workaround: git config core.autocrlf false in the clone and re-checkout.

2. npm run build exits 1 at scratch-gui

The seven other packages build, then:

> @scratch/[email protected] build:dev
> BUILD_TYPE=dev webpack

'BUILD_TYPE' is not recognized as an internal or external command,
operable program or batch file.

Cause: packages/scratch-gui/package.json has "build:dev": "BUILD_TYPE=dev webpack". That is
POSIX shell syntax, and npm runs scripts through cmd.exe on Windows regardless of the calling
shell. The neighbouring build:dist and build:dist-standalone scripts already use cross-env
for the same variable, and cross-env is already in scratch-gui's devDependencies.

Workaround: npm run build --workspace=packages/scratch-gui --script-shell="C:\Program Files\Git\bin\bash.exe".

3. scratch-gui npm run test:unit runs every suite

Jest rejects the path pattern and falls back to running everything:

  Invalid testPattern test[\\\]unit supplied. Running all tests instead.

The unit, integration, Playwright and smoke suites then run together. Without a gui build and
browsers that shows as 21 failed suites (127 failed, 328 passed of 463 tests) instead of the 50
unit suites passing. test:integration and test:smoke use the same pattern shape.

Cause: the patterns in packages/scratch-gui/package.json are passed unquoted:

"test:unit": "cross-env JEST_JUNIT_OUTPUT_NAME=unit-tests-results.xml jest test[\\\\/]unit",
"test:integration": "cross-env JEST_JUNIT_OUTPUT_NAME=integration-tests-results.xml jest --maxWorkers=4 test[\\\\/]integration",
"test:smoke": "jest --runInBand test[\\\\/]smoke",

Through cmd.exe the pattern reaches Jest as an invalid regex. scratch-storage passes the same
kind of pattern in double quotes (jest "test[\\\\/]unit") and works on Windows. The scratch-gui
README's advice to use cmd.exe instead of Git Bash makes no difference, because npm runs the
script through cmd.exe either way; the result is identical from PowerShell and Git Bash.

Workaround: npx jest test/unit runs exactly the unit suites (50 suites, 328 passed, 1 skipped,
about 10 seconds).

Steps to Reproduce

  1. On Windows with Git for Windows defaults (core.autocrlf=true), clone scratch-editor, check
    out develop, run npm ci from the repo root.
  2. cd packages/scratch-vm and run npm run lint: see the @stylistic/linebreak-style errors.
    Any package other than scratch-media-lib-scripts shows the same.
  3. From the repo root run npm run build: see 'BUILD_TYPE' is not recognized and exit code 1
    after the other seven packages build.
  4. cd packages/scratch-gui and run npm run test:unit: see Invalid testPattern ... Running all tests instead. followed by integration, Playwright and smoke suites running. Compare with
    npx jest test/unit, which runs only the unit suites and passes.

System Details

  • Windows 10 Pro 22H2 (build 19045); identical results from PowerShell 5.1 and Git Bash
  • Git for Windows with core.autocrlf=true; npm script-shell unset (scripts run in cmd.exe)
  • Node v24.21.0, npm 12.0.2, Jest 29.7.0
  • scratch-editor develop at 7b5559d29 (v15.3.0), fresh npm ci

Notes

Each cause has a small, self-contained fix, and I would be glad to open them as two separate PRs
referencing this issue so each is easy to review:

  1. Add *.mjs text eol=lf to .gitattributes. The committed blobs are already LF, so only
    checkout behaviour changes. Existing Windows clones need a re-checkout
    (git rm --cached -r . && git reset --hard).
  2. "build:dev": "cross-env BUILD_TYPE=dev webpack", matching the two neighbouring scripts.
  3. Either quote the three Jest patterns as scratch-storage does, or use plain test/unit,
    test/integration, test/smoke, which Jest matches on every platform because it normalises
    separators before applying the regex.

Bugs 2 and 3 are collapsed into one commit since they touch the same file.

Dominant language
JavaScript
Stars
310
Forks
299
Avg merge
19h 41m
Merged PRs (30d)
14

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 scratchfoundation/scratch-editor

All issues in scratchfoundation/scratch-editor

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.