From 03725f551237811f48a7cef3a24ba1975b0e34e7 Mon Sep 17 00:00:00 2001 From: Tilman Vatteroth Date: Sat, 11 Dec 2021 21:17:23 +0100 Subject: [PATCH] Update to cypress 9 and fix firefox upload crash (#1653) Signed-off-by: Tilman Vatteroth Co-authored-by: Renovate Bot --- cypress/fixtures/{import.md.txt => import.md} | 0 ...mport.md.txt.license => import.md.license} | 0 cypress/fixtures/invalid-history.txt | 1 + cypress/fixtures/invalid-history.txt.license | 3 + cypress/integration/fileUpload.spec.ts | 14 +++-- cypress/integration/history.spec.ts | 18 +++--- cypress/integration/import.spec.ts | 8 +-- package.json | 9 +-- .../sidebar/import-markdown-sidebar-entry.tsx | 2 +- .../editor-page/sidebar/upload-input.tsx | 28 +++++++--- yarn.lock | 55 +++++++++++-------- 11 files changed, 80 insertions(+), 58 deletions(-) rename cypress/fixtures/{import.md.txt => import.md} (100%) rename cypress/fixtures/{import.md.txt.license => import.md.license} (100%) create mode 100644 cypress/fixtures/invalid-history.txt create mode 100644 cypress/fixtures/invalid-history.txt.license diff --git a/cypress/fixtures/import.md.txt b/cypress/fixtures/import.md similarity index 100% rename from cypress/fixtures/import.md.txt rename to cypress/fixtures/import.md diff --git a/cypress/fixtures/import.md.txt.license b/cypress/fixtures/import.md.license similarity index 100% rename from cypress/fixtures/import.md.txt.license rename to cypress/fixtures/import.md.license diff --git a/cypress/fixtures/invalid-history.txt b/cypress/fixtures/invalid-history.txt new file mode 100644 index 000000000..ca059b9a9 --- /dev/null +++ b/cypress/fixtures/invalid-history.txt @@ -0,0 +1 @@ +Invalid json diff --git a/cypress/fixtures/invalid-history.txt.license b/cypress/fixtures/invalid-history.txt.license new file mode 100644 index 000000000..078e5a9ac --- /dev/null +++ b/cypress/fixtures/invalid-history.txt.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + +SPDX-License-Identifier: CC0-1.0 diff --git a/cypress/integration/fileUpload.spec.ts b/cypress/integration/fileUpload.spec.ts index 57498437d..695adb3bb 100644 --- a/cypress/integration/fileUpload.spec.ts +++ b/cypress/integration/fileUpload.spec.ts @@ -40,8 +40,11 @@ describe('File upload', () => { ) }) it('via button', () => { - cy.getById('editor-toolbar-upload-image-button').click() - cy.getById('editor-toolbar-upload-image-input').attachFile({ filePath: 'demo.png', mimeType: 'image/png' }) + cy.getById('editor-toolbar-upload-image-button').should('be.visible') + cy.getById('editor-toolbar-upload-image-input').attachFixture({ + filePath: 'demo.png', + mimeType: 'image/png' + }) cy.get('.CodeMirror-activeline').contains(`![](${imageUrl})`) }) @@ -83,9 +86,10 @@ describe('File upload', () => { statusCode: 400 } ) - cy.getById('editor-toolbar-upload-image-button').click() - cy.fixture('demo.png').then(() => { - cy.getById('editor-toolbar-upload-image-input').attachFile({ filePath: 'demo.png', mimeType: 'image/png' }) + cy.getById('editor-toolbar-upload-image-button').should('be.visible') + cy.getById('editor-toolbar-upload-image-input').attachFixture({ + filePath: 'demo.png', + mimeType: 'image/png' }) cy.get('.CodeMirror-activeline').contains('![upload of demo.png failed]()') }) diff --git a/cypress/integration/history.spec.ts b/cypress/integration/history.spec.ts index 812a6c12f..4b794e4ce 100644 --- a/cypress/integration/history.spec.ts +++ b/cypress/integration/history.spec.ts @@ -136,8 +136,8 @@ describe('History', () => { }) it('works with valid file', () => { - cy.getById('import-history-file-button').click() - cy.getById('import-history-file-input').attachFile({ + cy.getById('import-history-file-button').should('be.visible') + cy.getById('import-history-file-input').attachFixture({ filePath: 'history.json', mimeType: 'application/json' }) @@ -145,23 +145,23 @@ describe('History', () => { }) it('fails on invalid file', () => { - cy.getById('import-history-file-button').click() - cy.getById('import-history-file-input').attachFile({ - filePath: 'history.json.license', + cy.getById('import-history-file-button').should('be.visible') + cy.getById('import-history-file-input').attachFixture({ + filePath: 'invalid-history.txt', mimeType: 'text/plain' }) cy.getById('notification-toast').should('be.visible') }) it('works when selecting two files with the same name', () => { - cy.getById('import-history-file-button').click() - cy.getById('import-history-file-input').attachFile({ + cy.getById('import-history-file-button').should('be.visible') + cy.getById('import-history-file-input').attachFixture({ filePath: 'history.json', mimeType: 'application/json' }) cy.getById('history-entry-title').should('have.length', 1).contains('cy-Test') - cy.getById('import-history-file-button').click() - cy.getById('import-history-file-input').attachFile({ + cy.getById('import-history-file-button').should('be.visible') + cy.getById('import-history-file-input').attachFixture({ filePath: 'history-2.json', fileName: 'history.json', mimeType: 'application/json' diff --git a/cypress/integration/import.spec.ts b/cypress/integration/import.spec.ts index 7f3fc9700..fb1421bf5 100644 --- a/cypress/integration/import.spec.ts +++ b/cypress/integration/import.spec.ts @@ -11,8 +11,8 @@ describe('Import markdown file', () => { it('import on blank note', () => { cy.getById('menu-import').click() - cy.getById('menu-import-markdown').click() - cy.getById('menu-import-markdown-input').attachFile({ + cy.getById('menu-import-markdown-button').should('be.visible') + cy.getById('menu-import-markdown-input').attachFixture({ filePath: 'import.md', mimeType: 'text/markdown' }) @@ -26,8 +26,8 @@ describe('Import markdown file', () => { it('import on note with content', () => { cy.setCodemirrorContent('test\nabc') cy.getById('menu-import').click() - cy.getById('menu-import-markdown').click() - cy.getById('menu-import-markdown-input').attachFile({ + cy.getById('menu-import-markdown-button').should('be.visible') + cy.getById('menu-import-markdown-input').attachFixture({ filePath: 'import.md', mimeType: 'text/markdown' }) diff --git a/package.json b/package.json index 36801b219..ce72f79d9 100644 --- a/package.json +++ b/package.json @@ -119,9 +119,9 @@ "codemirror": "5.64.0", "copy-webpack-plugin": "6.4.1", "cross-env": "7.0.3", - "cypress": "7.7.0", - "cypress-commands": "1.1.0", - "cypress-file-upload": "5.0.8", + "cypress": "9.1.1", + "cypress-commands": "2.0.1", + "cypress-file-upload": "6.0.0-beta.0", "d3-graphviz": "3.2.0", "diff": "5.0.0", "dompurify": "2.3.4", @@ -199,8 +199,5 @@ "vega-lite": "5.2.0", "webpack-bundle-analyzer": "4.5.0", "words-count": "2.0.2" - }, - "resolutions": { - "cypress": "7.7.0" } } diff --git a/src/components/editor-page/sidebar/import-markdown-sidebar-entry.tsx b/src/components/editor-page/sidebar/import-markdown-sidebar-entry.tsx index 558363e83..83a9a6b73 100644 --- a/src/components/editor-page/sidebar/import-markdown-sidebar-entry.tsx +++ b/src/components/editor-page/sidebar/import-markdown-sidebar-entry.tsx @@ -43,7 +43,7 @@ export const ImportMarkdownSidebarEntry: React.FC = () => { return ( - + = ({ onLoad, acceptedFiles, onClickRef, ...props }) => { const fileInputReference = useRef(null) const onClick = useCallback(() => { - const fileInput = fileInputReference.current - if (!fileInput) { - return - } - fileInput.addEventListener('change', () => { + fileInputReference.current?.click() + }, []) + + const onChange = useCallback>( + (event) => { + const fileInput = event.currentTarget if (!fileInput.files || fileInput.files.length < 1) { return } @@ -37,13 +38,22 @@ export const UploadInput: React.FC = ({ onLoad, acceptedFiles, .catch((error: Error) => { log.error('Error while uploading file', error) }) - }) - fileInput.click() - }, [onLoad]) + }, + [onLoad] + ) useEffect(() => { onClickRef.current = onClick }) - return + return ( + + ) } diff --git a/yarn.lock b/yarn.lock index dcc1aba25..516a4a414 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1263,7 +1263,7 @@ resolved "https://registry.yarnpkg.com/@csstools/normalize.css/-/normalize.css-10.1.0.tgz#f0950bba18819512d42f7197e56c518aa491cf18" integrity sha512-ij4wRiunFfaJxjB0BdrYHIH8FxBJpOwNPhhAcunlmPdXudL1WQV1qoP9un6JsEBAgQH+7UXyyjh0g7jTxXK6tg== -"@cypress/request@^2.88.5": +"@cypress/request@^2.88.10": version "2.88.10" resolved "https://registry.yarnpkg.com/@cypress/request/-/request-2.88.10.tgz#b66d76b07f860d3a4b8d7a0604d020c662752cce" integrity sha512-Zp7F+R93N0yZyG34GutyTNr+okam7s/Fzc1+i3kcqOP8vk6OuajuE9qZJ6Rs+10/1JFtXFYMdyarnU1rZuJesg== @@ -3779,7 +3779,7 @@ blob-util@^2.0.2: resolved "https://registry.yarnpkg.com/blob-util/-/blob-util-2.0.2.tgz#3b4e3c281111bb7f11128518006cdc60b403a1eb" integrity sha512-T7JQa+zsXXEa6/8ZhHcQEW1UFfVM49Ts65uBkFL6fz2QmrElqmbajIDJvuA0tEhRe5eIjpV9ZF+0RfZR9voJFQ== -bluebird@^3.5.5, bluebird@^3.7.1, bluebird@^3.7.2: +bluebird@3.7.2, bluebird@^3.5.5, bluebird@^3.7.1: version "3.7.2" resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f" integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg== @@ -5064,29 +5064,31 @@ cyclist@^1.0.1: resolved "https://registry.yarnpkg.com/cyclist/-/cyclist-1.0.1.tgz#596e9698fd0c80e12038c2b82d6eb1b35b6224d9" integrity sha1-WW6WmP0MgOEgOMK4LW6xs1tiJNk= -cypress-commands@1.1.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/cypress-commands/-/cypress-commands-1.1.0.tgz#9248190168783deb8ab27ae7c722e3e01d172c97" - integrity sha512-Q8Jr25pHJQFXwln6Hp8O+Hgs8Z506Y2wA9F1Te2cTajjc5L9gtt9WPOcw1Ogh+OgyqaMHF+uq31vdfImRTio5Q== - -cypress-file-upload@5.0.8: - version "5.0.8" - resolved "https://registry.yarnpkg.com/cypress-file-upload/-/cypress-file-upload-5.0.8.tgz#d8824cbeaab798e44be8009769f9a6c9daa1b4a1" - integrity sha512-+8VzNabRk3zG6x8f8BWArF/xA/W0VK4IZNx3MV0jFWrJS/qKn8eHfa5nU73P9fOQAgwHFJx7zjg4lwOnljMO8g== - -cypress@7.7.0: - version "7.7.0" - resolved "https://registry.yarnpkg.com/cypress/-/cypress-7.7.0.tgz#0839ae28e5520536f9667d6c9ae81496b3836e64" - integrity sha512-uYBYXNoI5ym0UxROwhQXWTi8JbUEjpC6l/bzoGZNxoKGsLrC1SDPgIDJMgLX/MeEdPL0UInXLDUWN/rSyZUCjQ== +cypress-commands@2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/cypress-commands/-/cypress-commands-2.0.1.tgz#35651fa4d932b0244724273dbcfaf8d9ecdf4fd7" + integrity sha512-I+bLR2sXk/+m8GufQLDBf+jOGhpWMiDTMAogTWZglpzQw9px6cqz8GmD+FfWivDy3enK8aIIK6Xt8/jhbll9bA== dependencies: - "@cypress/request" "^2.88.5" + path-browserify "^1.0.1" + +cypress-file-upload@6.0.0-beta.0: + version "6.0.0-beta.0" + resolved "https://registry.yarnpkg.com/cypress-file-upload/-/cypress-file-upload-6.0.0-beta.0.tgz#77cb3a89cf719dd9124869fc5c76c094e1c84c27" + integrity sha512-6CDL3TKpLoPl0zme9twxQqfyI/SkzOjryy/Q49ijF4MD6ZXfoos1JZJY0wtWNqNJI9sy1YxH7OrlWVD0AlAigQ== + +cypress@9.1.1: + version "9.1.1" + resolved "https://registry.yarnpkg.com/cypress/-/cypress-9.1.1.tgz#26720ca5a22077cd85f49745616b7a08152a298f" + integrity sha512-yWcYD8SEQ8F3okFbRPqSDj5V0xhrZBT5QRIH+P1J2vYvtEmZ4KGciHE7LCcZZLILOrs7pg4WNCqkj/XRvReQlQ== + dependencies: + "@cypress/request" "^2.88.10" "@cypress/xvfb" "^1.2.4" "@types/node" "^14.14.31" "@types/sinonjs__fake-timers" "^6.0.2" "@types/sizzle" "^2.3.2" arch "^2.2.0" blob-util "^2.0.2" - bluebird "^3.7.2" + bluebird "3.7.2" cachedir "^2.3.0" chalk "^4.1.0" check-more-types "^2.24.0" @@ -5113,7 +5115,7 @@ cypress@7.7.0: minimist "^1.2.5" ospath "^1.2.2" pretty-bytes "^5.6.0" - ramda "~0.27.1" + proxy-from-env "1.0.0" request-progress "^3.0.0" supports-color "^8.1.1" tmp "~0.2.1" @@ -10749,6 +10751,11 @@ path-browserify@0.0.1: resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-0.0.1.tgz#e6c4ddd7ed3aa27c68a20cc4e50e1a4ee83bbc4a" integrity sha512-BapA40NHICOS+USX9SN4tyhq+A2RrN/Ws5F0Z5aMHDp98Fl86lX8Oti8B7uN93L4Ifv4fHOEA+pQw87gmMO/lQ== +path-browserify@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-1.0.1.tgz#d98454a9c3753d5790860f16f68867b9e46be1fd" + integrity sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g== + path-dirname@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/path-dirname/-/path-dirname-1.0.2.tgz#cc33d24d525e099a5388c0336c6e32b9160609e0" @@ -11717,6 +11724,11 @@ proxy-addr@~2.0.5: forwarded "0.2.0" ipaddr.js "1.9.1" +proxy-from-env@1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.0.0.tgz#33c50398f70ea7eb96d21f7b817630a55791c7ee" + integrity sha1-M8UDmPcOp+uW0h97gXYwpVeRx+4= + prr@~1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/prr/-/prr-1.0.1.tgz#d3fc114ba06995a45ec6893f484ceb1d78f5f476" @@ -11846,11 +11858,6 @@ raf@^3.4.1: dependencies: performance-now "^2.1.0" -ramda@~0.27.1: - version "0.27.1" - resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.27.1.tgz#66fc2df3ef873874ffc2da6aa8984658abacf5c9" - integrity sha512-PgIdVpn5y5Yns8vqb8FzBUEYn98V3xcPgawAkkgj0YJ0qDsnHCiNmZYfOGMgOvoB0eWFLpYbhxUR3mxfDIMvpw== - randombytes@^2.0.0, randombytes@^2.0.1, randombytes@^2.0.5, randombytes@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/randombytes/-/randombytes-2.1.0.tgz#df6f84372f0270dc65cdf6291349ab7a473d4f2a"