Skip to content

Commit ef76c26

Browse files
committed
Add regression test for custom template defaults (#747)
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.
1 parent 4c05f3d commit ef76c26

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

test/14-init.test.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
'use strict'
2+
const test = require('brittle')
3+
const tmp = require('test-tmp')
4+
const fs = require('bare-fs')
5+
const path = require('bare-path')
6+
const os = require('bare-os')
7+
const Helper = require('./helper')
8+
const init = require('../init')
9+
10+
test('init uses custom template defaults (#747)', async function ({ is, plan, teardown, timeout }) {
11+
timeout(180000)
12+
plan(3)
13+
14+
const helper = new Helper()
15+
teardown(() => helper.close(), { order: Infinity })
16+
await helper.ready()
17+
18+
const templateDir = Helper.fixture('custom-template-defaults')
19+
const outDir = await tmp()
20+
teardown(() => Helper.gc(outDir))
21+
22+
const output = await init(templateDir, outDir, {
23+
cwd: os.cwd(),
24+
ipc: helper,
25+
autosubmit: true,
26+
defaults: { name: 'test-app', height: 540, width: 720 },
27+
header: '',
28+
force: true,
29+
pkg: null
30+
})
31+
32+
for await (const msg of output) {
33+
if (msg.tag === 'final') break
34+
}
35+
36+
const raw = await fs.promises.readFile(path.join(outDir, 'package.json'), 'utf8')
37+
const pkg = JSON.parse(raw)
38+
is(pkg.name, 'test-app', 'name from passed defaults should be used')
39+
is(
40+
pkg.pear.gui.height,
41+
'1080',
42+
'template default for height (1080) should be used, not hardcoded 540'
43+
)
44+
is(
45+
pkg.pear.gui.width,
46+
'800',
47+
'template default for width (800) should be used, not hardcoded 720'
48+
)
49+
})
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"params": [
3+
{
4+
"name": "name",
5+
"prompt": "name"
6+
},
7+
{
8+
"name": "height",
9+
"default": 1080,
10+
"prompt": "height",
11+
"validation": "(value) => Number.isInteger(+value)",
12+
"msg": "must be an integer"
13+
},
14+
{
15+
"name": "width",
16+
"default": 800,
17+
"prompt": "width",
18+
"validation": "(value) => Number.isInteger(+value)",
19+
"msg": "must be an integer"
20+
}
21+
]
22+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "__name__",
3+
"pear": {
4+
"name": "__name__",
5+
"type": "terminal",
6+
"gui": {
7+
"height": "__height__",
8+
"width": "__width__"
9+
}
10+
}
11+
}

test/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ async function runTests() {
2121
await import('./11-touch.test.js')
2222
await import('./12-provision.test.js')
2323
await import('./13-shutdown.test.js')
24+
await import('./14-init.test.js')
2425

2526
test.resume()
2627
}

0 commit comments

Comments
 (0)