diff --git a/labware-library/cypress/integration/labware-creator/fileImport.spec.js b/labware-library/cypress/integration/labware-creator/fileImport.spec.js index 5b80c6a38f2..d92442f23da 100644 --- a/labware-library/cypress/integration/labware-creator/fileImport.spec.js +++ b/labware-library/cypress/integration/labware-creator/fileImport.spec.js @@ -137,5 +137,9 @@ context('File Import', () => { }) }) }) + + cy.window() + .its('__lastSavedFileName__') + .should('equal', 'TestPro 15 Well Plate 5 µL.zip') }) }) diff --git a/labware-library/cypress/mocks/file-saver.js b/labware-library/cypress/mocks/file-saver.js new file mode 100644 index 00000000000..4abd32d9229 --- /dev/null +++ b/labware-library/cypress/mocks/file-saver.js @@ -0,0 +1,6 @@ +// mock for 'file-saver' npm module + +export const saveAs = (blob, fileName) => { + global.__lastSavedBlobZip__ = blob + global.__lastSavedFileName__ = fileName +} diff --git a/labware-library/src/labware-creator/index.js b/labware-library/src/labware-creator/index.js index eaa4a8fede0..cd004639ea6 100644 --- a/labware-library/src/labware-creator/index.js +++ b/labware-library/src/labware-creator/index.js @@ -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({ diff --git a/labware-library/webpack.config.js b/labware-library/webpack.config.js index 3763e99a08d..c463b858024 100644 --- a/labware-library/webpack.config.js +++ b/labware-library/webpack.config.js @@ -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, @@ -66,4 +73,8 @@ module.exports = merge(baseConfig, { }, }), ], + + resolve: { + alias: testAliases, + }, })