|
| 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