Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(labware-library): mock file-saver while using cypress #5932

Merged
merged 1 commit into from
Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
? {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we needed any more E2E mocks, we'd add them here

'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,
},
})