Skip to content

Commit aae3751

Browse files
fix: procfile comment parsing (#3641)
* this fixes the mocking difference causing flappy tests and adds chore to the title of the release PR * fixing procfile parsing by ignoring comment lines and updating local Procfile fixture and tests to prevent regressions
1 parent cf27509 commit aae3751

File tree

5 files changed

+77
-2
lines changed

5 files changed

+77
-2
lines changed

scripts/create-release-pr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ git add . -u
5858
echo "Creating git commit and pushing to GitHub..."
5959
git commit -m "v${PACKAGE_VERSION}"
6060
git push origin "${BRANCH_NAME}"
61-
gh pr create --title="release v${PACKAGE_VERSION}" --body "release v${PACKAGE_VERSION}"
61+
gh pr create --title="chore: release v${PACKAGE_VERSION}" --body "chore: release v${PACKAGE_VERSION}"

src/lib/local/load-foreman-procfile.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import fs from 'fs'
22

33
function parseProcfile(content: string): Record<string, string> {
44
const lines = content.split(/\r?\n/).filter((line, i) => {
5+
if (line.match(/^\s*#/)) {
6+
return false
7+
}
8+
59
if (line.match(/\w/)) {
610
if (!line.match(/^\s*\w+:/)) {
711
throw new Error('line ' + (i + 1) + ' parse error: ' + line)

test/fixtures/local/Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Example Procfile used by local command tests
12
web: echo "it works (web)! port: $PORT"
23
worker: echo "it works (worker)!"
34
release: echo "it works (release)!"

test/unit/commands/apps/diff.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ describe('apps:diff', function () {
133133
api
134134
.get(`/apps/${app1Name}/releases`).matchHeader('range', /version/).reply(404, {id: 'not_found', message: 'Couldn\'t find that app.'})
135135
.get(`/apps/${app2Name}/releases`).matchHeader('range', /version/).reply(200, releasesWithSlug(slugId2))
136-
.get(`/apps/${app2Name}/slugs/${slugId2}`).reply(200, slugBody(sameChecksum))
136+
.get(`/apps/${app2Name}/slugs/${slugId2}`).optionally().reply(200, slugBody(sameChecksum))
137137

138138
const {error} = await runCommand(AppsDiff, [app1Name, app2Name])
139139

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import {expect} from 'chai'
2+
import fs from 'fs'
3+
import os from 'os'
4+
import path from 'path'
5+
6+
import {loadProc} from '../../../../src/lib/local/load-foreman-procfile.js'
7+
8+
describe('load-foreman-procfile', function () {
9+
let tempDir: string
10+
11+
beforeEach(function () {
12+
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'heroku-local-procfile-'))
13+
})
14+
15+
afterEach(function () {
16+
fs.rmSync(tempDir, {force: true, recursive: true})
17+
})
18+
19+
it('ignores top-level comment lines', function () {
20+
const procfilePath = path.join(tempDir, 'Procfile')
21+
fs.writeFileSync(procfilePath, [
22+
'# Example Procfile for tests',
23+
'web: npm run start',
24+
'worker: npm run worker',
25+
'',
26+
].join('\n'))
27+
28+
const procHash = loadProc(procfilePath)
29+
expect(procHash).to.deep.equal({
30+
web: 'npm run start',
31+
worker: 'npm run worker',
32+
})
33+
})
34+
35+
it('ignores indented comment lines', function () {
36+
const procfilePath = path.join(tempDir, 'Procfile')
37+
fs.writeFileSync(procfilePath, [
38+
' # process descriptions',
39+
'web: npm run start',
40+
'',
41+
].join('\n'))
42+
43+
const procHash = loadProc(procfilePath)
44+
expect(procHash).to.deep.equal({
45+
web: 'npm run start',
46+
})
47+
})
48+
49+
it('retains existing parse errors for malformed lines', function () {
50+
const procfilePath = path.join(tempDir, 'Procfile')
51+
fs.writeFileSync(procfilePath, [
52+
'web: npm run start',
53+
'not a valid procfile line',
54+
'',
55+
].join('\n'))
56+
57+
expect(() => loadProc(procfilePath)).to.throw('line 2 parse error: not a valid procfile line')
58+
})
59+
60+
it('supports additional colons in process commands', function () {
61+
const procfilePath = path.join(tempDir, 'Procfile')
62+
fs.writeFileSync(procfilePath, [
63+
'web: node server.js --url=http://localhost:3000',
64+
'',
65+
].join('\n'))
66+
67+
const procHash = loadProc(procfilePath)
68+
expect(procHash.web).to.equal('node server.js --url=http://localhost:3000')
69+
})
70+
})

0 commit comments

Comments
 (0)