Skip to content

Commit

Permalink
Migration will now report head and script failures
Browse files Browse the repository at this point in the history
Added test to make sure additional step is always called if it exists
  • Loading branch information
BenSurgisonGDS committed Dec 19, 2022
1 parent e4dac2e commit 1f3dc3e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/migrator/migrationSteps.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,17 @@ module.exports.upgradeIfUnchanged = (filePaths, starterFilePath, additionalStep)

const reporter = await addReporter(`Overwrite ${filePath}`)

if (!matchFound) {
await reporter(false)
return false
}

let result = false
try {
await copyFileFromStarter(starterFilePath || filePath, filePath)
if (matchFound) {
await copyFileFromStarter(starterFilePath || filePath, filePath)
} else {
await reporter(false)
}
if (additionalStep) {
result = await additionalStep()
} else {
result = true
result = matchFound
}
} catch (e) {
await verboseLog(e.message)
Expand Down
24 changes: 24 additions & 0 deletions lib/migrator/migrationSteps.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('migration steps', () => {
beforeEach(() => {
fileHelpers.replaceStartOfFile.mockResolvedValue(true)
fileHelpers.getFileAsLines.mockResolvedValue(true)
fileHelpers.matchAgainstOldVersions.mockResolvedValue(true)
})

afterEach(() => {
Expand Down Expand Up @@ -283,6 +284,29 @@ describe('migration steps', () => {
expect(mockReporter).toHaveBeenCalledWith(true)
})

it('report if changed layout', async () => {
const layout = 'app/views/layout.html'
const additionalStep = jest.fn().mockResolvedValue(true)

fileHelpers.matchAgainstOldVersions.mockReturnValue(false)

const result = await upgradeIfUnchanged([layout], layout, additionalStep)

expect(result).toBeTruthy()

expect(fileHelpers.matchAgainstOldVersions).toHaveBeenCalledTimes(1)
expect(fileHelpers.matchAgainstOldVersions).toHaveBeenCalledWith(layout)

expect(additionalStep).toHaveBeenCalledTimes(1)
expect(additionalStep).toHaveBeenCalled()

expect(reporter.addReporter).toHaveBeenCalledTimes(1)
expect(reporter.addReporter).toHaveBeenCalledWith(`Overwrite ${layout}`)

expect(mockReporter).toHaveBeenCalledTimes(2)
expect(mockReporter).toHaveBeenCalledWith(true)
})

it('delete if unchanged unbranded layout', async () => {
const unbrandedLayout = 'app/views/layout_unbranded.html'

Expand Down

0 comments on commit 1f3dc3e

Please sign in to comment.