Skip to content

Commit fa831ad

Browse files
authored
Merge pull request #4289 from FlowFuse/snapshot-package-json-fix
Fix snapshot package.json download dependencies
2 parents 4f52ff4 + bc25cb9 commit fa831ad

6 files changed

Lines changed: 73 additions & 3 deletions

File tree

frontend/src/pages/application/Snapshots.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export default {
178178
description: `${ownerType} snapshot, ${snapshot.name} - ${snapshot.description}`,
179179
private: true,
180180
version: '0.0.0-' + snapshot.id,
181-
dependencies: ss.settings?.modules || {}
181+
dependencies: ss.modules || {}
182182
}
183183
downloadData(packageJSON, 'package.json')
184184
},

frontend/src/pages/device/Snapshots/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ export default {
266266
description: `${ownerType} snapshot, ${snapshot.name} - ${snapshot.description}`,
267267
private: true,
268268
version: '0.0.0-' + snapshot.id,
269-
dependencies: ss.settings?.modules || {}
269+
dependencies: ss.modules || {}
270270
}
271271
downloadData(packageJSON, 'package.json')
272272
},

frontend/src/pages/instance/Snapshots/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ export default {
272272
description: `${ownerType} snapshot, ${snapshot.name} - ${snapshot.description}`,
273273
private: true,
274274
version: '0.0.0-' + snapshot.id,
275-
dependencies: ss.settings?.modules || {}
275+
dependencies: ss.modules || {}
276276
}
277277
downloadData(packageJSON, 'package.json')
278278
},

test/e2e/frontend/cypress/tests-ee/devices/snapshots.spec.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,4 +319,35 @@ describe('FlowForge - Devices - With Billing', () => {
319319
expect(body.targetSnapshot).to.be.a('string')
320320
})
321321
})
322+
it('download snapshot package.json', () => {
323+
cy.intercept('GET', '/api/*/projects/*/snapshots', deviceSnapshots).as('snapshotData')
324+
cy.intercept('GET', '/api/*/snapshots/*').as('snapshot')
325+
326+
cy.contains('span', 'application-device-a').click()
327+
cy.get('[data-nav="device-snapshots"]').click()
328+
329+
// ensure package.json does not exist in the downloads folder before the test
330+
cy.task('clearDownloads')
331+
// click kebab menu in row 1
332+
cy.get('[data-el="snapshots"] tbody').find('.ff-kebab-menu').eq(0).click()
333+
// click the Download Package.json option
334+
cy.get('[data-el="snapshots"] tbody .ff-kebab-menu .ff-kebab-options').find('.ff-list-item').eq(IDX_DOWNLOAD_PACKAGE).click()
335+
336+
cy.wait('@snapshot').then(async interception => {
337+
// At this point, the endpoint has returned but occasionally, the test fails as the file is not yet written to the filesystem.
338+
// To counter this, there is a short 250ms wait to allow time for the file to be written to the filesystem.
339+
// A better solution would be to use a cy.command (named waitForFileDownload) that polls the downloads folder
340+
// and calls `cy.wait` with timeout and retry. This would allow the test to wait for the file in a more reliable way.
341+
// For now, a small delay here gets the job done.
342+
cy.wait(250) // eslint-disable-line cypress/no-unnecessary-waiting
343+
const downloadsFolder = Cypress.config('downloadsFolder')
344+
return cy.readFile(`${downloadsFolder}/package.json`)
345+
}).then((packageObject) => {
346+
expect(packageObject).to.have.property('name', 'application-device-a')
347+
expect(packageObject).to.have.property('description')
348+
expect(packageObject).to.have.property('dependencies')
349+
expect(packageObject.dependencies).to.have.property('node-red')
350+
expect(packageObject.dependencies).to.have.property('@flowfuse/nr-project-nodes')
351+
})
352+
})
322353
})

test/e2e/frontend/cypress/tests/applications/snapshots.spec.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,35 @@ describe('FlowForge - Application - Snapshots', () => {
158158
// check an SVG in present the content section
159159
cy.get('[data-el="dialog-compare-snapshot"] .ff-dialog-content svg').should('exist')
160160
})
161+
it('download snapshot package.json', () => {
162+
cy.intercept('GET', '/api/*/projects/*/snapshots', deviceSnapshots).as('snapshotData')
163+
cy.intercept('GET', '/api/*/snapshots/*').as('snapshot')
164+
165+
cy.get('[data-nav="application-snapshots"]').click()
166+
167+
// ensure package.json does not exist in the downloads folder before the test
168+
cy.task('clearDownloads')
169+
// click kebab menu in row 1
170+
cy.get('[data-el="snapshots"] tbody').find('.ff-kebab-menu').eq(0).click()
171+
// click the Download Package.json option
172+
cy.get('[data-el="snapshots"] tbody .ff-kebab-menu .ff-kebab-options').find('.ff-list-item').eq(IDX_DOWNLOAD_PACKAGE).click()
173+
174+
cy.wait('@snapshot').then(async interception => {
175+
// At this point, the endpoint has returned but occasionally, the test fails as the file is not yet written to the filesystem.
176+
// To counter this, there is a short 250ms wait to allow time for the file to be written to the filesystem.
177+
// A better solution would be to use a cy.command (named waitForFileDownload) that polls the downloads folder
178+
// and calls `cy.wait` with timeout and retry. This would allow the test to wait for the file in a more reliable way.
179+
// For now, a small delay here gets the job done.
180+
cy.wait(250) // eslint-disable-line cypress/no-unnecessary-waiting
181+
const downloadsFolder = Cypress.config('downloadsFolder')
182+
return cy.readFile(`${downloadsFolder}/package.json`)
183+
}).then((packageObject) => {
184+
expect(packageObject).to.have.property('name', 'instance-2-with-devices')
185+
expect(packageObject).to.have.property('description')
186+
expect(packageObject).to.have.property('dependencies')
187+
// expect(packageObject.dependencies).to.have.property('node-red', '4.0.0')
188+
// expect(packageObject.dependencies).to.have.property('@flowfuse/nr-project-nodes', '0.6.4')
189+
// expect(packageObject.dependencies).to.have.property('@flowfuse/node-red-dashboard', '*')
190+
})
191+
})
161192
})

test/e2e/frontend/cypress/tests/instances/snapshots.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,14 @@ describe('FlowForge - Instance Snapshots', () => {
216216
cy.wait(250) // eslint-disable-line cypress/no-unnecessary-waiting
217217
const downloadsFolder = Cypress.config('downloadsFolder')
218218
cy.task('fileExists', { dir: downloadsFolder, file: 'package.json' })
219+
return cy.readFile(`${downloadsFolder}/package.json`)
220+
}).then((packageObject) => {
221+
expect(packageObject).to.have.property('name', 'instance-2')
222+
expect(packageObject).to.have.property('description')
223+
expect(packageObject).to.have.property('dependencies')
224+
expect(packageObject.dependencies).to.have.property('node-red')
225+
expect(packageObject.dependencies).to.have.property('@flowfuse/nr-project-nodes')
226+
expect(packageObject.dependencies).to.have.property('@flowfuse/node-red-dashboard')
219227
})
220228
})
221229

0 commit comments

Comments
 (0)