-
Notifications
You must be signed in to change notification settings - Fork 22
Add regression test for init template defaults (#747) #1016
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| }) | ||
|
|
||
| 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
|
||
|
|
||
| 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') | ||
| }) | ||
| 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" | ||
| } | ||
| ] | ||
| } |
| 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__ | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
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
defaultsonly includesname, so even a precedence bug where passed defaults override template defaults forheight/widthwouldn’t be caught. To make this a true regression test, passheight: 540andwidth: 720indefaults(to mimic the previous hardcoded fallbacks) and assert the generatedpackage.jsonstill uses the template defaults (1080/800).