Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions test/14-init.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
'use strict'
const test = require('brittle')
const tmp = require('test-tmp')
const fs = require('bare-fs')
const path = require('bare-path')
const os = require('bare-os')
const Helper = require('./helper')
const init = require('../init')

test('init uses custom template defaults (#747)', async function ({
ok,
is,
plan,
teardown,
timeout
}) {
timeout(180000)
plan(4)

const helper = new Helper()
teardown(() => helper.close(), { order: Infinity })
await helper.ready()

const templateDir = Helper.fixture('custom-template-defaults')
const outDir = await tmp()
teardown(() => Helper.gc(outDir))

const output = await init(templateDir, outDir, {
cwd: os.cwd(),
ipc: helper,
autosubmit: true,
defaults: { name: 'test-app', height: 540, width: 720 },
header: '',
force: true,
pkg: null
Comment on lines 28 to 35
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.
})

let success = false
for await (const msg of output) {
if (msg.tag === 'error') throw new Error(msg.data?.stack || msg.data?.message)
if (msg.tag === 'final') {
success = msg.data.success
break
}
}
Comment on lines 39 to 45
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.

ok(success, 'init completed successfully')

const raw = await fs.promises.readFile(path.join(outDir, 'package.json'), 'utf8')
const pkg = JSON.parse(raw)
is(pkg.name, 'test-app', 'name from passed defaults should be used')
is(
pkg.pear.gui.height,
1080,
'template default for height (1080) should be used, not hardcoded 540'
)
is(pkg.pear.gui.width, 800, 'template default for width (800) should be used, not hardcoded 720')
})
22 changes: 22 additions & 0 deletions test/fixtures/custom-template-defaults/_template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"params": [
{
"name": "name",
"prompt": "name"
},
{
"name": "height",
"default": 1080,
"prompt": "height",
"validation": "(value) => Number.isInteger(+value)",
"msg": "must be an integer"
},
{
"name": "width",
"default": 800,
"prompt": "width",
"validation": "(value) => Number.isInteger(+value)",
"msg": "must be an integer"
}
]
}
11 changes: 11 additions & 0 deletions test/fixtures/custom-template-defaults/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "__name__",
"pear": {
"name": "__name__",
"type": "terminal",
"gui": {
"height": __height__,
"width": __width__
}
}
}
1 change: 1 addition & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ async function runTests() {
await import('./11-touch.test.js')
await import('./12-provision.test.js')
await import('./13-shutdown.test.js')
await import('./14-init.test.js')

test.resume()
}
Loading