From a79a7a85cfe73cbf25b7dc1958e69ef5c0307c6f Mon Sep 17 00:00:00 2001 From: Alex Kern Date: Mon, 30 Jun 2025 20:17:53 -0700 Subject: [PATCH] Add upload/download e2e test --- playwright.config.ts | 4 ++-- tests/e2e/basic.test.ts | 2 +- tests/e2e/fixtures/testfile.txt | 1 + tests/e2e/upload-download.test.ts | 33 +++++++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 tests/e2e/fixtures/testfile.txt create mode 100644 tests/e2e/upload-download.test.ts diff --git a/playwright.config.ts b/playwright.config.ts index 4338e61..659df21 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -3,8 +3,8 @@ import { defineConfig } from '@playwright/test' export default defineConfig({ testDir: './tests/e2e', webServer: { - command: 'node .next/standalone/server.js', - port: 3000, + command: 'PORT=4100 node .next/standalone/server.js', + port: 4100, timeout: 120 * 1000, reuseExistingServer: true, }, diff --git a/tests/e2e/basic.test.ts b/tests/e2e/basic.test.ts index 5cd4674..036cdb4 100644 --- a/tests/e2e/basic.test.ts +++ b/tests/e2e/basic.test.ts @@ -2,7 +2,7 @@ import { test, expect } from '@playwright/test' test('home page loads', async ({ page }) => { - await page.goto('http://localhost:3000/') + await page.goto('http://localhost:4100/') await expect( page.getByText('Peer-to-peer file transfers in your browser.'), ).toBeVisible() diff --git a/tests/e2e/fixtures/testfile.txt b/tests/e2e/fixtures/testfile.txt new file mode 100644 index 0000000..776d967 --- /dev/null +++ b/tests/e2e/fixtures/testfile.txt @@ -0,0 +1 @@ +hello from filepizza diff --git a/tests/e2e/upload-download.test.ts b/tests/e2e/upload-download.test.ts new file mode 100644 index 0000000..ede832d --- /dev/null +++ b/tests/e2e/upload-download.test.ts @@ -0,0 +1,33 @@ +import { test, expect } from '@playwright/test' +import fs from 'fs' +import path from 'path' +import crypto from 'crypto' + +const testFilePath = path.join(__dirname, 'fixtures', 'testfile.txt') + +function sha256(file: Buffer): string { + return crypto.createHash('sha256').update(file).digest('hex') +} + +test('uploader to downloader transfer', async ({ browser }) => { + const fileBuffer = fs.readFileSync(testFilePath) + const expectedChecksum = sha256(fileBuffer) + + const uploader = await browser.newPage() + await uploader.goto('http://localhost:4100/') + await uploader.setInputFiles('input[type="file"]', testFilePath) + await uploader.getByText('Start').click() + + const shortInput = uploader.getByText('Short URL').locator('..').locator('input') + await expect(shortInput).toBeVisible() + const shareURL = await shortInput.inputValue() + + const downloader = await browser.newPage() + await downloader.goto(shareURL) + const downloadPromise = downloader.waitForEvent('download') + await downloader.getByText('Download').click() + const download = await downloadPromise + const downloadedPath = await download.path() + const downloadedBuffer = fs.readFileSync(downloadedPath!) + expect(sha256(downloadedBuffer)).toBe(expectedChecksum) +})