mirror of
https://github.com/cupcakearmy/cryptgeon.git
synced 2024-12-23 00:36:28 +00:00
testing
This commit is contained in:
parent
3af5d0ef1a
commit
a2cf751012
@ -4,10 +4,12 @@
|
||||
"dev:docker": "docker-compose -f docker-compose.dev.yaml up redis",
|
||||
"dev:packages": "pnpm --parallel run dev",
|
||||
"dev": "run-p dev:*",
|
||||
"docker:up": "docker compose -f docker-compose.dev.yaml up",
|
||||
"docker:build": "docker compose -f docker-compose.dev.yaml build",
|
||||
"test": "playwright test --project chrome firefox safari",
|
||||
"test:local": "playwright test --project local",
|
||||
"test:server": "docker compose -f docker-compose.dev.yaml up",
|
||||
"test:prepare": "docker compose -f docker-compose.dev.yaml build",
|
||||
"test:server": "run-s docker:up",
|
||||
"test:prepare": "run-p build docker:build",
|
||||
"build": "pnpm run --recursive --filter=!@cryptgeon/backend build"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -21,10 +21,10 @@ const config: PlaywrightTestConfig = {
|
||||
{ name: 'chrome', use: { ...devices['Desktop Chrome'] } },
|
||||
{ name: 'firefox', use: { ...devices['Desktop Firefox'] } },
|
||||
{ name: 'safari', use: { ...devices['Desktop Safari'] } },
|
||||
{
|
||||
name: 'local',
|
||||
use: { ...devices['Desktop Chrome'] },
|
||||
},
|
||||
|
||||
{ name: 'cli', use: { ...devices['Desktop Chrome'] }, grep: [/@cli/] },
|
||||
{ name: 'web', use: { ...devices['Desktop Chrome'] }, grep: [/@web/] },
|
||||
{ name: 'cross', use: { ...devices['Desktop Chrome'] }, grep: [/@cross/] },
|
||||
],
|
||||
}
|
||||
|
||||
|
13
test/cli/text/simple.spec.ts
Normal file
13
test/cli/text/simple.spec.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { test } from '@playwright/test'
|
||||
import { CLI } from '../../utils'
|
||||
|
||||
test.describe('text @cli', () => {
|
||||
test('simple', async ({ page }) => {
|
||||
const text = `Endless prejudice endless play derive joy eternal-return selfish burying. Of decieve play pinnacle faith disgust. Spirit reason salvation burying strong of joy ascetic selfish against merciful sea truth. Ubermensch moral prejudice derive chaos mountains ubermensch justice philosophy justice ultimate joy ultimate transvaluation. Virtues convictions war ascetic eternal-return spirit. Ubermensch transvaluation noble revaluation sexuality intentions salvation endless decrepit hope noble fearful. Justice ideal ultimate snare god joy evil sexuality insofar gains oneself ideal.`
|
||||
const note = await CLI('send', 'text', text)
|
||||
const link = note.stdout.trim().replace(/(.|\s)*http/g, 'http')
|
||||
|
||||
const retrieved = await CLI('open', link)
|
||||
test.expect(retrieved.stdout.trim()).toBe(text)
|
||||
})
|
||||
})
|
19
test/cross/text/simple.spec.ts
Normal file
19
test/cross/text/simple.spec.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { test } from '@playwright/test'
|
||||
import { CLI, checkLinkForText, createNote } from '../../utils'
|
||||
|
||||
const text = `Endless prejudice endless play derive joy eternal-return selfish burying. Of decieve play pinnacle faith disgust. Spirit reason salvation burying strong of joy ascetic selfish against merciful sea truth. Ubermensch moral prejudice derive chaos mountains ubermensch justice philosophy justice ultimate joy ultimate transvaluation. Virtues convictions war ascetic eternal-return spirit. Ubermensch transvaluation noble revaluation sexuality intentions salvation endless decrepit hope noble fearful. Justice ideal ultimate snare god joy evil sexuality insofar gains oneself ideal.`
|
||||
|
||||
test.describe('text @cross', () => {
|
||||
test('cli to web', async ({ page }) => {
|
||||
const note = await CLI('send', 'text', text)
|
||||
const link = note.stdout.trim().replace(/(.|\s)*http/g, 'http')
|
||||
|
||||
await checkLinkForText(page, link, text)
|
||||
})
|
||||
|
||||
test('web to cli', async ({ page }) => {
|
||||
const link = await createNote(page, { text })
|
||||
const retrieved = await CLI('open', link)
|
||||
test.expect(retrieved.stdout.trim()).toBe(text)
|
||||
})
|
||||
})
|
@ -1,11 +0,0 @@
|
||||
import { test } from '@playwright/test'
|
||||
import { checkLinkForDownload, createNote, getFileChecksum } from '../utils'
|
||||
import Files from './files'
|
||||
|
||||
test('multiple', async ({ page }) => {
|
||||
const files = [Files.PDF, Files.Image]
|
||||
const checksums = await Promise.all(files.map(getFileChecksum))
|
||||
const link = await createNote(page, { files, views: 2 })
|
||||
await checkLinkForDownload(page, link, 'image.jpg', checksums[1])
|
||||
await checkLinkForDownload(page, link, 'AES.pdf', checksums[0])
|
||||
})
|
@ -1,24 +0,0 @@
|
||||
import { test } from '@playwright/test'
|
||||
import { checkLinkDoesNotExist, checkLinkForDownload, checkLinkForText, createNote, getFileChecksum } from '../utils'
|
||||
import Files from './files'
|
||||
|
||||
test('simple pdf', async ({ page }) => {
|
||||
const files = [Files.PDF]
|
||||
const link = await createNote(page, { files })
|
||||
await checkLinkForText(page, link, 'AES.pdf')
|
||||
await checkLinkDoesNotExist(page, link)
|
||||
})
|
||||
|
||||
test('pdf content', async ({ page }) => {
|
||||
const files = [Files.PDF]
|
||||
const checksum = await getFileChecksum(files[0])
|
||||
const link = await createNote(page, { files })
|
||||
await checkLinkForDownload(page, link, 'AES.pdf', checksum)
|
||||
})
|
||||
|
||||
test('image content', async ({ page }) => {
|
||||
const files = [Files.Image]
|
||||
const checksum = await getFileChecksum(files[0])
|
||||
const link = await createNote(page, { files })
|
||||
await checkLinkForDownload(page, link, 'image.jpg', checksum)
|
||||
})
|
@ -1,8 +0,0 @@
|
||||
import { test } from '@playwright/test'
|
||||
import { createNote } from '../utils'
|
||||
import Files from './files'
|
||||
|
||||
test.skip('to big zip', async ({ page }) => {
|
||||
const files = [Files.Zip]
|
||||
const link = await createNote(page, { files, error: 'note is to big' })
|
||||
})
|
37
test/text.ts
37
test/text.ts
@ -1,37 +0,0 @@
|
||||
import { expect, test, type Page } from '@playwright/test'
|
||||
|
||||
async function createNote(page: Page, text: string): Promise<string> {
|
||||
await page.goto('/')
|
||||
await page.locator('textarea').click()
|
||||
await page.locator('textarea').fill(text)
|
||||
await page.locator('button:has-text("create")').click()
|
||||
|
||||
await page.locator('[data-testid="share-link"]').click()
|
||||
const shareLink = await page.locator('[data-testid="share-link"]').inputValue()
|
||||
return shareLink
|
||||
}
|
||||
|
||||
async function checkLinkForText(page: Page, link: string, text: string) {
|
||||
await page.goto(link)
|
||||
await page.locator('[data-testid="show-note-button"]').click()
|
||||
expect(await page.locator('[data-testid="result"] >> .note').innerText()).toBe(text)
|
||||
}
|
||||
|
||||
async function checkLinkDoesNotExist(page: Page, link: string) {
|
||||
await page.goto('/') // Required due to firefox: https://github.com/microsoft/playwright/issues/15781
|
||||
await page.goto(link)
|
||||
await expect(page.locator('main')).toContainText('note was not found or was already deleted')
|
||||
}
|
||||
|
||||
test('simple', async ({ page }) => {
|
||||
const text = `Endless prejudice endless play derive joy eternal-return selfish burying. Of decieve play pinnacle faith disgust. Spirit reason salvation burying strong of joy ascetic selfish against merciful sea truth. Ubermensch moral prejudice derive chaos mountains ubermensch justice philosophy justice ultimate joy ultimate transvaluation. Virtues convictions war ascetic eternal-return spirit. Ubermensch transvaluation noble revaluation sexuality intentions salvation endless decrepit hope noble fearful. Justice ideal ultimate snare god joy evil sexuality insofar gains oneself ideal.`
|
||||
const shareLink = await createNote(page, text)
|
||||
await checkLinkForText(page, shareLink, text)
|
||||
})
|
||||
|
||||
test('only shown once', async ({ page }) => {
|
||||
const text = `Christian victorious reason suicide dead. Right ultimate gains god hope truth burying selfish society joy. Ultimate.`
|
||||
const shareLink = await createNote(page, text)
|
||||
await checkLinkForText(page, shareLink, text)
|
||||
await checkLinkDoesNotExist(page, shareLink)
|
||||
})
|
@ -1,14 +0,0 @@
|
||||
import { test } from '@playwright/test'
|
||||
import { checkLinkDoesNotExist, checkLinkForText, createNote } from '../utils'
|
||||
|
||||
test('1 minute', async ({ page }) => {
|
||||
const text = `Virtues value ascetic revaluation sea dead strong burying.`
|
||||
const minutes = 1
|
||||
const timeout = minutes * 60_000
|
||||
test.setTimeout(timeout * 2)
|
||||
const shareLink = await createNote(page, { text, expiration: minutes })
|
||||
await checkLinkForText(page, shareLink, text)
|
||||
await checkLinkForText(page, shareLink, text)
|
||||
await page.waitForTimeout(timeout)
|
||||
await checkLinkDoesNotExist(page, shareLink)
|
||||
})
|
@ -1,8 +0,0 @@
|
||||
import { test } from '@playwright/test'
|
||||
import { checkLinkForText, createNote } from '../utils'
|
||||
|
||||
test('simple', async ({ page }) => {
|
||||
const text = `Endless prejudice endless play derive joy eternal-return selfish burying. Of decieve play pinnacle faith disgust. Spirit reason salvation burying strong of joy ascetic selfish against merciful sea truth. Ubermensch moral prejudice derive chaos mountains ubermensch justice philosophy justice ultimate joy ultimate transvaluation. Virtues convictions war ascetic eternal-return spirit. Ubermensch transvaluation noble revaluation sexuality intentions salvation endless decrepit hope noble fearful. Justice ideal ultimate snare god joy evil sexuality insofar gains oneself ideal.`
|
||||
const shareLink = await createNote(page, { text })
|
||||
await checkLinkForText(page, shareLink, text)
|
||||
})
|
@ -1,18 +0,0 @@
|
||||
import { test } from '@playwright/test'
|
||||
import { checkLinkDoesNotExist, checkLinkForText, createNote } from '../utils'
|
||||
|
||||
test('only shown once', async ({ page }) => {
|
||||
const text = `Christian victorious reason suicide dead. Right ultimate gains god hope truth burying selfish society joy. Ultimate.`
|
||||
const shareLink = await createNote(page, { text })
|
||||
await checkLinkForText(page, shareLink, text)
|
||||
await checkLinkDoesNotExist(page, shareLink)
|
||||
})
|
||||
|
||||
test('view 3 times', async ({ page }) => {
|
||||
const text = `Justice holiest overcome fearful strong ultimate holiest christianity.`
|
||||
const shareLink = await createNote(page, { text, views: 3 })
|
||||
await checkLinkForText(page, shareLink, text)
|
||||
await checkLinkForText(page, shareLink, text)
|
||||
await checkLinkForText(page, shareLink, text)
|
||||
await checkLinkDoesNotExist(page, shareLink)
|
||||
})
|
@ -1,6 +1,10 @@
|
||||
import { expect, type Page } from '@playwright/test'
|
||||
import { createHash } from 'crypto'
|
||||
import { readFile } from 'fs/promises'
|
||||
import { execFile } from 'node:child_process'
|
||||
import { promisify } from 'node:util'
|
||||
|
||||
const exec = promisify(execFile)
|
||||
|
||||
type CreatePage = { text?: string; files?: string[]; views?: number; expiration?: number; error?: string }
|
||||
export async function createNote(page: Page, options: CreatePage): Promise<string> {
|
||||
@ -69,3 +73,12 @@ export async function getFileChecksum(file: string) {
|
||||
const hash = createHash('sha3-256').update(buffer).digest('hex')
|
||||
return hash
|
||||
}
|
||||
|
||||
export async function CLI(...args: string[]) {
|
||||
return await exec('./packages/cli/dist/index.cjs', args, {
|
||||
env: {
|
||||
...process.env,
|
||||
CRYPTGEON_SERVER: 'http://localhost:1234',
|
||||
},
|
||||
})
|
||||
}
|
||||
|
13
test/web/file/multiple.spec.ts
Normal file
13
test/web/file/multiple.spec.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { test } from '@playwright/test'
|
||||
import { checkLinkForDownload, createNote, getFileChecksum } from '../../utils'
|
||||
import Files from './files'
|
||||
|
||||
test.describe('@web', () => {
|
||||
test('multiple', async ({ page }) => {
|
||||
const files = [Files.PDF, Files.Image]
|
||||
const checksums = await Promise.all(files.map(getFileChecksum))
|
||||
const link = await createNote(page, { files, views: 2 })
|
||||
await checkLinkForDownload(page, link, 'image.jpg', checksums[1])
|
||||
await checkLinkForDownload(page, link, 'AES.pdf', checksums[0])
|
||||
})
|
||||
})
|
26
test/web/file/simple.spec.ts
Normal file
26
test/web/file/simple.spec.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { test } from '@playwright/test'
|
||||
import { checkLinkDoesNotExist, checkLinkForDownload, checkLinkForText, createNote, getFileChecksum } from '../../utils'
|
||||
import Files from './files'
|
||||
|
||||
test.describe('@web', () => {
|
||||
test('simple pdf', async ({ page }) => {
|
||||
const files = [Files.PDF]
|
||||
const link = await createNote(page, { files })
|
||||
await checkLinkForText(page, link, 'AES.pdf')
|
||||
await checkLinkDoesNotExist(page, link)
|
||||
})
|
||||
|
||||
test('pdf content', async ({ page }) => {
|
||||
const files = [Files.PDF]
|
||||
const checksum = await getFileChecksum(files[0])
|
||||
const link = await createNote(page, { files })
|
||||
await checkLinkForDownload(page, link, 'AES.pdf', checksum)
|
||||
})
|
||||
|
||||
test('image content', async ({ page }) => {
|
||||
const files = [Files.Image]
|
||||
const checksum = await getFileChecksum(files[0])
|
||||
const link = await createNote(page, { files })
|
||||
await checkLinkForDownload(page, link, 'image.jpg', checksum)
|
||||
})
|
||||
})
|
10
test/web/file/too-big.spec.ts
Normal file
10
test/web/file/too-big.spec.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { test } from '@playwright/test'
|
||||
import { createNote } from '../../utils'
|
||||
import Files from './files'
|
||||
|
||||
test.describe('@web', () => {
|
||||
test.skip('to big zip', async ({ page }) => {
|
||||
const files = [Files.Zip]
|
||||
const link = await createNote(page, { files, error: 'note is to big' })
|
||||
})
|
||||
})
|
16
test/web/text/expiration.spec.ts
Normal file
16
test/web/text/expiration.spec.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { test } from '@playwright/test'
|
||||
import { checkLinkDoesNotExist, checkLinkForText, createNote } from '../../utils'
|
||||
|
||||
test.describe('@web', () => {
|
||||
test('1 minute', async ({ page }) => {
|
||||
const text = `Virtues value ascetic revaluation sea dead strong burying.`
|
||||
const minutes = 1
|
||||
const timeout = minutes * 60_000
|
||||
test.setTimeout(timeout * 2)
|
||||
const shareLink = await createNote(page, { text, expiration: minutes })
|
||||
await checkLinkForText(page, shareLink, text)
|
||||
await checkLinkForText(page, shareLink, text)
|
||||
await page.waitForTimeout(timeout)
|
||||
await checkLinkDoesNotExist(page, shareLink)
|
||||
})
|
||||
})
|
10
test/web/text/simple.spec.ts
Normal file
10
test/web/text/simple.spec.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { test } from '@playwright/test'
|
||||
import { checkLinkForText, createNote } from '../../utils'
|
||||
|
||||
test.describe('@web', () => {
|
||||
test('simple', async ({ page }) => {
|
||||
const text = `Endless prejudice endless play derive joy eternal-return selfish burying. Of decieve play pinnacle faith disgust. Spirit reason salvation burying strong of joy ascetic selfish against merciful sea truth. Ubermensch moral prejudice derive chaos mountains ubermensch justice philosophy justice ultimate joy ultimate transvaluation. Virtues convictions war ascetic eternal-return spirit. Ubermensch transvaluation noble revaluation sexuality intentions salvation endless decrepit hope noble fearful. Justice ideal ultimate snare god joy evil sexuality insofar gains oneself ideal.`
|
||||
const shareLink = await createNote(page, { text })
|
||||
await checkLinkForText(page, shareLink, text)
|
||||
})
|
||||
})
|
20
test/web/text/views.spec.ts
Normal file
20
test/web/text/views.spec.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { test } from '@playwright/test'
|
||||
import { checkLinkDoesNotExist, checkLinkForText, createNote } from '../../utils'
|
||||
|
||||
test.describe('@web', () => {
|
||||
test('only shown once', async ({ page }) => {
|
||||
const text = `Christian victorious reason suicide dead. Right ultimate gains god hope truth burying selfish society joy. Ultimate.`
|
||||
const shareLink = await createNote(page, { text })
|
||||
await checkLinkForText(page, shareLink, text)
|
||||
await checkLinkDoesNotExist(page, shareLink)
|
||||
})
|
||||
|
||||
test('view 3 times', async ({ page }) => {
|
||||
const text = `Justice holiest overcome fearful strong ultimate holiest christianity.`
|
||||
const shareLink = await createNote(page, { text, views: 3 })
|
||||
await checkLinkForText(page, shareLink, text)
|
||||
await checkLinkForText(page, shareLink, text)
|
||||
await checkLinkForText(page, shareLink, text)
|
||||
await checkLinkDoesNotExist(page, shareLink)
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue
Block a user