Skip to content

Commit

Permalink
add e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
mifi committed Dec 4, 2024
1 parent ed279b5 commit 24d1921
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
12 changes: 12 additions & 0 deletions e2e/cypress/integration/dashboard-xhr.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
interceptCompanionUrlMetaRequest,
interceptCompanionUrlRequest,
runRemoteUrlImageUploadTest,
runRemoteUnsplashUploadTest,
} from './reusable-tests.ts'
Expand Down Expand Up @@ -57,6 +58,17 @@ describe('Dashboard with XHR', () => {
})
})

it('should upload unknown size files', () => {
cy.get('[data-cy="Url"]').click()
cy.get('.uppy-Url-input').type('http://localhost:4678/unknown-size')
cy.get('.uppy-Url-importButton').click()
interceptCompanionUrlRequest()
cy.get('.uppy-StatusBar-actionBtn--upload').click()
cy.wait('@url').then(() => {
cy.get('.uppy-StatusBar-statusPrimary').should('contain', 'Complete')
})
})

it('should upload remote image with Unsplash plugin', () => {
runRemoteUnsplashUploadTest()
})
Expand Down
2 changes: 1 addition & 1 deletion e2e/cypress/integration/reusable-tests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global cy */

const interceptCompanionUrlRequest = () =>
export const interceptCompanionUrlRequest = () =>
cy
.intercept({ method: 'POST', url: 'http://localhost:3020/url/get' })
.as('url')
Expand Down
25 changes: 25 additions & 0 deletions e2e/mock-server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,31 @@ const requestListener = (req, res) => {
}
case '/file-no-headers':
break

case '/unknown-size': {
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
res.setHeader('Transfer-Encoding', 'chunked');
const chunkSize = 1e5;
if (req.method === 'GET') {
let i = 0;
const interval = setInterval(() => {
if (i >= 10) { // 1MB
clearInterval(interval);
res.end();
return;
}
res.write(Buffer.from(Array.from({ length: chunkSize }, () => '1').join('')));
res.write('\n');
i++;
}, 10);
} else if (req.method === 'HEAD') {
res.end();
} else {
throw new Error('Unhandled method')
}
}
break;

default:
res.writeHead(404).end('Unhandled request')
}
Expand Down

0 comments on commit 24d1921

Please sign in to comment.