Skip to content

Commit

Permalink
restructure e2e and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonfriesen committed Aug 25, 2024
1 parent fc407d5 commit 0464a4b
Show file tree
Hide file tree
Showing 12 changed files with 230 additions and 274 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build": "vite build",
"release": "bash scripts/bump_version.sh",
"release_verify": "bash scripts/prerelease_check.sh",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --testPathIgnorePatterns=\\.e2e\\.test\\.js$",
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules node_modules/jest/bin/jest.js --testPathIgnorePatterns=\\.e2e\\.test\\.js$",
"e2e": "playwright test"
},
"keywords": [
Expand Down Expand Up @@ -43,4 +43,4 @@
"tailwindcss": "^3.4.10",
"vite": "^2.9.18"
}
}
}
22 changes: 3 additions & 19 deletions src/content/config.e2e.js → src/content/e2e/config.e2e.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { test as base, expect } from '@playwright/test'
import siteConfigs from './config.js'
import { e2eTestUrls } from './targets.js'
import siteConfigs from '../config.js'

// Define a common user agent
const COMMON_USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
Expand Down Expand Up @@ -51,24 +52,7 @@ for (const [siteName, siteConfig] of Object.entries(siteConfigs)) {

for (const [pageName, pageConfig] of Object.entries(siteConfig.pages)) {
test(`${siteName} - ${pageName}`, async ({ page }) => {
const testUrls = {
github: {
pr: 'https://github.com/microsoft/playwright/pull/20635',
issue: 'https://github.com/microsoft/playwright/issues/20636',
discussion: 'https://github.com/golang/go/discussions/61669',
repo: 'https://github.com/microsoft/playwright',
user: 'https://github.com/microsoft',
release: 'https://github.com/microsoft/playwright/releases/tag/v1.32.3',
commit: 'https://github.com/golang/go/commit/96d8ff00c2d6a88384863a656fb5e53716b614d3',
actions: 'https://github.com/jonfriesen/quickcite/actions/runs/10446232111',
},
instagram: {
profile: 'https://www.instagram.com/jonfriesen/',
},
trello: {
board: 'https://trello.com/b/AwYSWOyt/ultimate-to-do-list',
},
}
const testUrls = e2eTestUrls

const testUrl = testUrls[siteName][pageName]
await testPageConfig(page, testUrl, pageConfig)
Expand Down
18 changes: 18 additions & 0 deletions src/content/e2e/targets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export const e2eTestUrls = {
github: {
pr: 'https://github.com/microsoft/playwright/pull/20635',
issue: 'https://github.com/microsoft/playwright/issues/20636',
discussion: 'https://github.com/golang/go/discussions/61669',
repo: 'https://github.com/microsoft/playwright',
user: 'https://github.com/microsoft',
release: 'https://github.com/microsoft/playwright/releases/tag/v1.32.3',
commit: 'https://github.com/golang/go/commit/96d8ff00c2d6a88384863a656fb5e53716b614d3',
actions: 'https://github.com/jonfriesen/quickcite/actions/runs/10446232111',
},
instagram: {
profile: 'https://www.instagram.com/jonfriesen/',
},
trello: {
board: 'https://trello.com/b/AwYSWOyt/ultimate-to-do-list',
},
}
110 changes: 0 additions & 110 deletions src/content/github.test.js

This file was deleted.

33 changes: 0 additions & 33 deletions src/content/instagram.test.js

This file was deleted.

47 changes: 0 additions & 47 deletions src/content/linkedin.test.js

This file was deleted.

83 changes: 83 additions & 0 deletions src/content/test/github.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { runUrlPatternTests, runMarkdownGeneratorTests } from './testUtils'

const urlPatternTestCases = [
{ page: 'pr', url: 'https://github.com/user/repo/pull/123', shouldMatch: true },
{ page: 'issue', url: 'https://github.com/user/repo/issues/456', shouldMatch: true },
{ page: 'discussion', url: 'https://github.com/user/repo/discussions/789', shouldMatch: true },
{ page: 'repo', url: 'https://github.com/user/repo', shouldMatch: true },
{ page: 'user', url: 'https://github.com/username', shouldMatch: true },
{ page: 'release', url: 'https://github.com/user/repo/releases/tag/v1.0.0', shouldMatch: true },
{ page: 'commit', url: 'https://github.com/user/repo/commit/1234567890123456789012345678901234567890', shouldMatch: true },
{ page: 'pr', url: 'https://github.com/user/repo', shouldMatch: false },
{ page: 'actions', url: 'https://github.com/jonfriesen/quickcite/actions/runs/10476888027', shouldMatch: true },
{ page: 'actions', url: 'https://github.com/octocat/Hello-World/actions/runs/12345678', shouldMatch: true },
{ page: 'actions', url: 'https://github.com/octocat/Hello-World/actions', shouldMatch: false },
{ page: 'actions', url: 'https://github.com/octocat/Hello-World/actions/runs/abcdefgh', shouldMatch: false },
{ page: 'actions', url: 'https://github.com/octocat/Hello-World/actions/runs/abcdefgh/job/12345678', shouldMatch: false },
]

const markdownTestCases = [
{
page: 'pr',
info: { number: '#123', title: 'Add new feature' },
url: 'https://github.com/user/repo/pull/123',
expected: '[#123: Add new feature](https://github.com/user/repo/pull/123)',
},
{
page: 'issue',
info: { number: '#456', title: 'Fix bug in login' },
url: 'https://github.com/user/repo/issues/456',
expected: '[#456: Fix bug in login](https://github.com/user/repo/issues/456)',
},
{
page: 'discussion',
info: { number: '#789', title: 'Propose new architecture' },
url: 'https://github.com/user/repo/discussions/789',
expected: '[#789: Propose new architecture](https://github.com/user/repo/discussions/789)',
},
{
page: 'repo',
info: { title: 'user/repo', description: 'A cool project' },
url: 'https://github.com/user/repo',
expected: '[user/repo](https://github.com/user/repo) - A cool project',
},
{
page: 'user',
info: { name: 'John Doe', bio: 'Software Developer' },
url: 'https://github.com/johndoe',
expected: '[John Doe](https://github.com/johndoe) - Software Developer',
},
{
page: 'release',
info: { title: 'v1.0.0: First Release', date: '2023-05-01T00:00:00Z' },
url: 'https://github.com/user/repo/releases/tag/v1.0.0',
expected: '[v1.0.0: First Release](https://github.com/user/repo/releases/tag/v1.0.0) - Released on ' + new Date('2023-05-01T00:00:00Z').toLocaleDateString(),
},
{
page: 'commit',
info: { title: 'Update README.md', hash: '1234567890abcdef', author: 'John Doe', date: '2023-05-01T00:00:00Z' },
url: 'https://github.com/user/repo/commit/1234567890abcdef',
expected: '[(1234567) - Update README.md](https://github.com/user/repo/commit/1234567890abcdef)\nBy John Doe on ' + new Date('2023-05-01T00:00:00Z').toLocaleString(),
},
{
page: 'actions',
info: { repoOwner: 'jonfriesen', repoName: 'quickcite', workflowName: 'CI', runNumber: '#1234', runStatus: 'Success', statusEmoji: '✅' },
url: 'https://github.com/jonfriesen/quickcite/actions/runs/10476888027',
expected: '[jonfriesen/quickcite: CI #1234 ✅ (Success)](https://github.com/jonfriesen/quickcite/actions/runs/10476888027)',
},
{
page: 'actions',
info: { repoOwner: 'octocat', repoName: 'Hello-World', workflowName: 'Build', runNumber: '#5678', runStatus: 'Failure', statusEmoji: '❌' },
url: 'https://github.com/octocat/Hello-World/actions/runs/12345678',
expected: '[octocat/Hello-World: Build #5678 ❌ (Failure)](https://github.com/octocat/Hello-World/actions/runs/12345678)',
},
{
page: 'actions',
info: { repoOwner: 'test', repoName: 'repo', workflowName: 'Deploy', runNumber: '#9012', runStatus: 'In progress', statusEmoji: '🔄' },
url: 'https://github.com/test/repo/actions/runs/90123456',
expected: '[test/repo: Deploy #9012 🔄 (In progress)](https://github.com/test/repo/actions/runs/90123456)',
},
]

runUrlPatternTests('github', urlPatternTestCases)
runMarkdownGeneratorTests('github', markdownTestCases)
18 changes: 18 additions & 0 deletions src/content/test/instagram.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { runUrlPatternTests, runMarkdownGeneratorTests } from './testUtils'

const urlPatternTestCases = [
{ page: 'profile', url: 'https://www.instagram.com/username/', shouldMatch: true },
{ page: 'profile', url: 'https://www.instagram.com/p/123456/', shouldMatch: false },
]

const markdownTestCases = [
{
page: 'profile',
info: { name: 'Travel Enthusiast' },
url: 'https://www.instagram.com/travelenthusiast/',
expected: '[Travel Enthusiast](https://www.instagram.com/travelenthusiast/)',
},
]

runUrlPatternTests('instagram', urlPatternTestCases)
runMarkdownGeneratorTests('instagram', markdownTestCases)
32 changes: 32 additions & 0 deletions src/content/test/linkedin.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { runUrlPatternTests, runMarkdownGeneratorTests } from './testUtils'

const urlPatternTestCases = [
{ page: 'profile', url: 'https://www.linkedin.com/in/username/', shouldMatch: true },
{ page: 'company', url: 'https://www.linkedin.com/company/companyname/', shouldMatch: true },
{ page: 'pulse', url: 'https://www.linkedin.com/pulse/article-title/', shouldMatch: true },
{ page: 'profile', url: 'https://www.linkedin.com/feed/', shouldMatch: false },
]

const markdownTestCases = [
{
page: 'profile',
info: { name: 'John Doe', headline: 'Software Engineer' },
url: 'https://www.linkedin.com/in/johndoe/',
expected: '[John Doe](https://www.linkedin.com/in/johndoe/) - Software Engineer',
},
{
page: 'company',
info: { name: 'Tech Corp', about: 'Leading technology company' },
url: 'https://www.linkedin.com/company/techcorp/',
expected: '[Tech Corp](https://www.linkedin.com/company/techcorp/) - Leading technology company',
},
{
page: 'pulse',
info: { title: 'The Future of AI', author: 'Jane Smith', date: 'May 1, 2023' },
url: 'https://www.linkedin.com/pulse/future-ai-jane-smith/',
expected: '[The Future of AI](https://www.linkedin.com/pulse/future-ai-jane-smith/)\nBy Jane Smith | May 1, 2023',
},
]

runUrlPatternTests('linkedin', urlPatternTestCases)
runMarkdownGeneratorTests('linkedin', markdownTestCases)
Loading

0 comments on commit 0464a4b

Please sign in to comment.