Skip to content

Commit

Permalink
test(labware-library): mock file-saver while using cypress
Browse files Browse the repository at this point in the history
Addresses LC side of #5457
  • Loading branch information
IanLondon committed Jun 16, 2020
1 parent c3ef153 commit 4263dfc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,9 @@ context('File Import', () => {
})
})
})

cy.window()
.its('__lastSavedFileName__')
.should('equal', 'TestPro 15 Well Plate 5 µL.zip')
})
})
6 changes: 6 additions & 0 deletions labware-library/cypress/mocks/file-saver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// mock for 'file-saver' npm module

export const saveAs = (blob, fileName) => {
global.__lastSavedBlobZip__ = blob
global.__lastSavedFileName__ = fileName
}
8 changes: 1 addition & 7 deletions labware-library/src/labware-creator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,13 +493,7 @@ export const LabwareCreator = (): React.Node => {
labwareTestProtocol({ pipetteName, definition: def })
)
zip.generateAsync({ type: 'blob' }).then(blob => {
if (global.Cypress) {
// HACK(IL, 2020-04-02): can't figure out a better way to do this yet
// https://docs.cypress.io/faq/questions/using-cypress-faq.html#Can-my-tests-interact-with-Redux-Vuex-data-store
global.__lastSavedBlobZip__ = blob
} else {
saveAs(blob, `${displayName}.zip`)
}
saveAs(blob, `${displayName}.zip`)
})

reportEvent({
Expand Down
11 changes: 11 additions & 0 deletions labware-library/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ const envVars = passThruEnvVars.reduce(
{ ...envVarsWithDefaults }
)

const testAliases =
process.env.CYPRESS === '1'
? {
'file-saver': path.resolve(__dirname, 'cypress/mocks/file-saver.js'),
}
: {}

module.exports = merge(baseConfig, {
entry: JS_ENTRY,

Expand Down Expand Up @@ -66,4 +73,8 @@ module.exports = merge(baseConfig, {
},
}),
],

resolve: {
alias: testAliases,
},
})

0 comments on commit 4263dfc

Please sign in to comment.