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

Make Cypress more stable & add e2e test for error events when upload fails #3662

Merged
merged 10 commits into from
May 4, 2022
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ module.exports = {
},
{
files: ['e2e/**/*.ts', 'e2e/**/*.js'],
rules: { 'import/no-extraneous-dependencies': 'off' },
rules: { 'import/no-extraneous-dependencies': 'off', 'no-unused-expressions': 'off' },
Murderlon marked this conversation as resolved.
Show resolved Hide resolved
},
],
}
28 changes: 27 additions & 1 deletion e2e/cypress/integration/dashboard-tus.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ type Tus = BaseTus & {
requests: { isPaused: boolean }
}

// NOTE: we have to use different files to upload per test
// because we are uploading to https://tusd.tusdemo.net,
// constantly uploading the same images gives a different cached result (or something).
describe('Dashboard with Tus', () => {
beforeEach(() => {
cy.visit('/dashboard-tus')
Expand All @@ -13,6 +16,29 @@ describe('Dashboard with Tus', () => {
cy.intercept('http://localhost:3020/search/unsplash/*').as('unsplash')
})

it('should emit `error` and `upload-error` events on failed POST request', () => {
cy.get('@file-input').attachFile(['images/traffic.jpg'])

const error = cy.spy()
const uploadError = cy.spy()
cy.window().then(({ uppy }) => {
uppy.on('upload-error', uploadError)
uppy.on('error', error)
})

cy.get('.uppy-StatusBar-actionBtn--upload').click()

cy.intercept(
{ method: 'POST', pathname: '/files', times: 1 },
{ statusCode: 401, body: { code: 401, message: 'Expired JWT Token' } },
).as('post')

cy.wait('@post').then(() => {
expect(error).to.be.called
expect(uploadError).to.be.called
})
})

it('should upload cat image successfully', () => {
cy.get('@file-input').attachFile('images/cat.jpg')
cy.get('.uppy-StatusBar-actionBtn--upload').click()
Expand All @@ -23,7 +49,7 @@ describe('Dashboard with Tus', () => {
})

it('should start exponential backoff when receiving HTTP 429', () => {
cy.get('@file-input').attachFile(['images/cat.jpg', 'images/traffic.jpg'])
cy.get('@file-input').attachFile(['images/baboon.png'])
cy.get('.uppy-StatusBar-actionBtn--upload').click()

cy.intercept(
Expand Down