diff --git a/lib/command/apply.ts b/lib/command/apply.ts index 3774a55..1b25e10 100644 --- a/lib/command/apply.ts +++ b/lib/command/apply.ts @@ -54,7 +54,7 @@ export default function apply(config: Config) { let previousEntry = journal.then(es => R.last(es)); let newEntries = Promise.join(previousEntry, apply, (prev, es) => - R.filter(e => e.timestamp > prev.timestamp, es) + prev ? R.filter(e => e.timestamp > prev.timestamp, es) : apply ); return newEntries diff --git a/test/command/apply.ts b/test/command/apply.ts index f52d32b..49758cd 100644 --- a/test/command/apply.ts +++ b/test/command/apply.ts @@ -284,4 +284,31 @@ describe('Command apply', () => { assert.equal(formatSpy.callCount, 1) ); }); + + describe('with empty journal', () => { + before(resetSpies); + + before(() => { + readJournalStub.restore(); + readJournalStub = sinon.stub(runner, 'readJournal', () => + Promise.resolve([]) + ); + + applyAllStub.restore(); + applyAllStub = sinon.stub( + runner, + 'applyAll', + (n: string, c: Config, j: string, ms: files.Migration[]) => + Promise.resolve(R.map(migrationToEntry, ms)) + ); + }); + + it('succeeds', () => + apply(loadObject({commands: {apply: {pending: true}}})) + ); + + it('calls formatJournalEntry for new entries', () => + assert.equal(formatSpy.callCount, 3) + ); + }); });