Skip to content

Add regression test for init template defaults (#747)#1016

Open
malikkaraoui wants to merge 1 commit intoholepunchto:mainfrom
malikkaraoui:test/init-template-defaults-747
Open

Add regression test for init template defaults (#747)#1016
malikkaraoui wants to merge 1 commit intoholepunchto:mainfrom
malikkaraoui:test/init-template-defaults-747

Conversation

@malikkaraoui
Copy link

@malikkaraoui malikkaraoui commented Feb 10, 2026

Summary

Context

Issue #747 reported that hardcoded height: 540 and width: 720 fallbacks in cmd/init.js were overriding custom template defaults. This was resolved during the v2 refactor — the defaults object now only contains { name }, and init/index.js correctly prioritizes template defaults:

defaults[prompt.name] = prompt.default ?? defaults[prompt.name]

However, no test existed to prevent regression. This PR adds one.

What's included

  • Fixture test/fixtures/custom-template-defaults/ — a template with height: 1080 and width: 800 defaults
  • Test test/14-init.test.js — calls init() with autosubmit: true and verifies:
    • name uses the passed default (test-app)
    • height uses the template default (1080, not 540)
    • width uses the template default (800, not 720)

Test plan

  • npm run lint passes
  • npm test passes with new test included

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a regression test + fixture to ensure pear init uses _template.json-provided defaults (not hardcoded fallbacks), preventing a recurrence of #747.

Changes:

  • Add test/14-init.test.js to validate template defaults are honored during init() with autosubmit: true
  • Add test/fixtures/custom-template-defaults/ fixture template defining height/width defaults
  • Register the new test in test/index.js

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
test/index.js Includes the new init regression test in the test runner.
test/fixtures/custom-template-defaults/package.json Adds a template output file using stamp placeholders for name/height/width.
test/fixtures/custom-template-defaults/_template.json Defines template params/defaults (including height/width) to reproduce #747.
test/14-init.test.js New regression test asserting init output uses template defaults.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 22 to 29
const output = await init(templateDir, outDir, {
cwd: os.cwd(),
ipc: helper,
autosubmit: true,
defaults: { name: 'test-app' },
header: '',
force: true,
pkg: null
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn’t currently reproduce the regression scenario from #747: the passed defaults only includes name, so even a precedence bug where passed defaults override template defaults for height/width wouldn’t be caught. To make this a true regression test, pass height: 540 and width: 720 in defaults (to mimic the previous hardcoded fallbacks) and assert the generated package.json still uses the template defaults (1080/800).

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 7 to 8
"height": "__height__",
"width": "__width__"
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this fixture, height/width placeholders are quoted, so the generated package.json will have pear.gui.height/width as strings. If these fields are intended to be numbers (as in examples/desktop/package.json), consider removing the quotes around __height__ / __width__ and updating the test assertions accordingly so the regression test matches real-world config types.

Suggested change
"height": "__height__",
"width": "__width__"
"height": __height__,
"width": __width__

Copilot uses AI. Check for mistakes.
Comment on lines 32 to 34
for await (const msg of output) {
if (msg.tag === 'final') break
}
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test breaks out of the output stream loop at the final tag but doesn’t assert final.data.success === true or fail on any error tags. Consider capturing the final message and asserting success (and/or scanning for error output) to avoid silent partial failures where package.json happened to be written but the init run still failed.

Copilot uses AI. Check for mistakes.
The hardcoded height/width fallbacks (540/720) in cmd/init.js were
removed during the v2 refactor. Add a test that passes the old
hardcoded values in defaults and verifies that template defaults
(1080/800) take precedence, preventing the original regression.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pear's 'init' command - hardcoded fallbacks override '_template.json' defaults for height and width.

1 participant