Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Add descriptive names to e2e response tapes (#1193)
Browse files Browse the repository at this point in the history
* Add descriptive names to e2e response tapes

* Add connection details to the tape name
  • Loading branch information
obulat authored Mar 28, 2022
1 parent dd9c148 commit e33d638
Show file tree
Hide file tree
Showing 307 changed files with 42,003 additions and 22,173 deletions.
2 changes: 1 addition & 1 deletion test/playwright/e2e/filters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ for (const searchType of supportedSearchTypes) {
page,
}) => {
const searchTypePath = searchType === ALL_MEDIA ? '' : searchType
const searchUrl = `/search/${searchTypePath}/?q=cat`
const searchUrl = `/search/${searchTypePath}?q=cat`
await page.goto(searchUrl)

await openFilters(page)
Expand Down
2 changes: 1 addition & 1 deletion test/playwright/e2e/search-types.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const audioConfig = {
url: '/search/audio?q=birds',
canLoadMore: true,
metaSourceCount: 3,
results: /93 results/,
results: /764 results/,
} as const

const searchTypes = [allContentConfig, imageConfig, audioConfig] as const
Expand Down
37 changes: 36 additions & 1 deletion test/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,42 @@ const talkback = require('talkback')
const port = 49152
const host = 'https://api.openverse.engineering'

const urlPatterns = {
search: /\/(?<mediaType>images|audio)\/*\?(?<query>[\w&=]+)/,
thumb: /\/(?<mediaType>images|audio)\/(?<uuid>[\w-]{32,})\/thumb/,
related: /\/(?<mediaType>images|audio)\/(?<uuid>[\w-]{32,})\/related/,
detail: /\/(?<mediaType>images|audio)\/(?<uuid>[\w-]{32,})\//,
}

/**
* @param {string} urlString
* @returns {{match: ({groups}|*), type: string}|null}
*/
const findTypeMatch = (urlString) => {
for (let [matchName, matchPattern] of Object.entries(urlPatterns)) {
const patternMatch = urlString.match(matchPattern)
if (patternMatch && patternMatch.groups) {
return { type: matchName, match: patternMatch }
}
}
return null
}
/** @type {TalkbackOptions['tapeNameGenerator']} */
const tapeNameGenerator = (tapeNumber) => `response-${tapeNumber}`
const tapeNameGenerator = (tapeNumber, tape) => {
const typeMatch = findTypeMatch(tape.req.url)
if (typeMatch && typeMatch.type) {
const groups = typeMatch.match.groups
const prefix = `${typeMatch.type}_${groups.mediaType}`
const suffix = tape.req.headers.connection
if (typeMatch.type === 'search') {
return `${prefix}_${groups.query}_${suffix}`
} else {
return `${prefix}_${groups.uuid}_${suffix}`
}
} else {
return `response-${tapeNumber}`
}
}

const updatingTapes =
process.argv.includes('--update-tapes') || process.env.UPDATE_TAPES === 'true'
Expand Down Expand Up @@ -117,6 +151,7 @@ const opts = /** @type {Partial<TalkbackOptions>} */ ({
path: './test/tapes',
record: recordMode,
fallbackMode: talkback.Options.FallbackMode.NOT_FOUND,
ignoreBody: true,
ignoreHeaders: ['user-agent', 'origin', 'referrer', 'content-length', 'host'],
name: 'Openverse e2e proxy',
summary: false,
Expand Down
49 changes: 35 additions & 14 deletions test/tapes/response-48.json5 → ...3-4892-96b4-10297dd84ed0_keep-alive.json5
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
{
meta: {
createdAt: '2022-03-14T17:05:28.485Z',
createdAt: '2022-03-28T15:14:01.070Z',
host: 'https://api.openverse.engineering',
resHumanReadable: true,
resUncompressed: true,
},
req: {
headers: {
connection: 'keep-alive',
pragma: 'no-cache',
'cache-control': 'no-cache',
'sec-ch-ua': '',
accept: 'application/json, text/plain, */*',
'sec-ch-ua-mobile': '?0',
Expand All @@ -20,15 +18,15 @@
referer: 'http://localhost:8443/',
'accept-encoding': 'gzip, deflate, br',
},
url: '/v1/audio/?license_type=commercial&license=cc0&searchBy=creator&creator=cat',
url: '/v1/images/53841492-9703-4892-96b4-10297dd84ed0/',
method: 'GET',
body: '',
},
res: {
status: 200,
headers: {
date: [
'Mon, 14 Mar 2022 17:05:35 GMT',
'Mon, 28 Mar 2022 15:14:01 GMT',
],
'content-type': [
'application/json',
Expand All @@ -40,7 +38,7 @@
'keep-alive',
],
vary: [
'Accept, Authorization, Origin, Accept-Encoding',
'Accept-Encoding, Accept, Authorization, Origin',
],
allow: [
'GET, HEAD, OPTIONS',
Expand All @@ -57,17 +55,20 @@
'referrer-policy': [
'same-origin',
],
'cross-origin-opener-policy': [
'same-origin',
],
'cache-control': [
'max-age=14400',
],
'cf-cache-status': [
'HIT',
],
age: [
'10339',
'101219',
],
'last-modified': [
'Mon, 14 Mar 2022 14:13:16 GMT',
'Sun, 27 Mar 2022 11:07:02 GMT',
],
'expect-ct': [
'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"',
Expand All @@ -79,7 +80,7 @@
'cloudflare',
],
'cf-ray': [
'6ebe98552b751078-ATL',
'6f3150266ed968bb-BUD',
],
'content-encoding': [
'br',
Expand All @@ -89,11 +90,31 @@
],
},
body: {
result_count: 0,
page_count: 0,
page_size: 20,
page: 1,
results: [],
id: '53841492-9703-4892-96b4-10297dd84ed0',
title: 'Olympic Games Seoul ´88',
foreign_landing_url: 'https://www.flickr.com/photos/40365317@N06/6263511475',
creator: 'Numerius',
creator_url: 'https://www.flickr.com/photos/40365317@N06',
url: 'https://live.staticflickr.com/6046/6263511475_35ffe5e9ac_b.jpg',
filesize: null,
filetype: null,
license: 'by-nd',
license_version: '2.0',
license_url: 'https://creativecommons.org/licenses/by-nd/2.0/',
provider: 'flickr',
source: 'flickr',
category: null,
tags: [
{
name: 'cinellilaser',
},
],
attribution: '"Olympic Games Seoul ´88" by Numerius is licensed under CC-BY-ND 2.0. To view a copy of this license, visit https://creativecommons.org/licenses/by-nd/2.0/.',
height: 1024,
width: 651,
thumbnail: 'http://localhost:49152/v1/images/53841492-9703-4892-96b4-10297dd84ed0/thumb/',
detail_url: 'http://localhost:49152/v1/images/53841492-9703-4892-96b4-10297dd84ed0/',
related_url: 'http://localhost:49152/v1/images/53841492-9703-4892-96b4-10297dd84ed0/related/',
},
},
}
13 changes: 8 additions & 5 deletions test/tapes/response-76.json5 → ...e-4911-9b9f-4e66678ec7f7_keep-alive.json5
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
meta: {
createdAt: '2022-03-14T17:05:53.560Z',
createdAt: '2022-03-28T15:06:10.273Z',
host: 'https://api.openverse.engineering',
resHumanReadable: true,
resUncompressed: true,
Expand All @@ -26,7 +26,7 @@
status: 200,
headers: {
date: [
'Mon, 14 Mar 2022 17:05:53 GMT',
'Mon, 28 Mar 2022 15:06:10 GMT',
],
'content-type': [
'application/json',
Expand Down Expand Up @@ -55,17 +55,20 @@
'referrer-policy': [
'same-origin',
],
'cross-origin-opener-policy': [
'same-origin',
],
'cache-control': [
'max-age=14400',
],
'cf-cache-status': [
'HIT',
],
age: [
'7104',
'99175',
],
'last-modified': [
'Mon, 14 Mar 2022 15:07:29 GMT',
'Sun, 27 Mar 2022 11:33:15 GMT',
],
'expect-ct': [
'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"',
Expand All @@ -77,7 +80,7 @@
'cloudflare',
],
'cf-ray': [
'6ebe98c68cf48d4c-ATL',
'6f3144a7a8726847-BUD',
],
'content-encoding': [
'br',
Expand Down
13 changes: 8 additions & 5 deletions test/tapes/response-70.json5 → ...8-621b-4ec2-bf70-f47a74380452_close.json5
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
meta: {
createdAt: '2022-03-14T17:05:46.058Z',
createdAt: '2022-03-28T15:06:02.599Z',
host: 'https://api.openverse.engineering',
resHumanReadable: true,
},
Expand All @@ -17,7 +17,7 @@
status: 200,
headers: {
date: [
'Mon, 14 Mar 2022 17:05:46 GMT',
'Mon, 28 Mar 2022 15:06:02 GMT',
],
'content-type': [
'application/json',
Expand All @@ -43,17 +43,20 @@
'referrer-policy': [
'same-origin',
],
'cross-origin-opener-policy': [
'same-origin',
],
'cache-control': [
'max-age=14400',
],
'cf-cache-status': [
'HIT',
],
age: [
'10409',
'102891',
],
'last-modified': [
'Mon, 14 Mar 2022 14:12:17 GMT',
'Sun, 27 Mar 2022 10:31:11 GMT',
],
'expect-ct': [
'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"',
Expand All @@ -65,7 +68,7 @@
'cloudflare',
],
'cf-ray': [
'6ebe989a2bb60fc5-ATL',
'6f3144779db31cb8-BUD',
],
'alt-svc': [
'h3=":443"; ma=86400, h3-29=":443"; ma=86400',
Expand Down
13 changes: 8 additions & 5 deletions test/tapes/response-190.json5 → ...4-4c49-9f6f-5c4529b701d8_keep-alive.json5
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
meta: {
createdAt: '2022-03-14T17:07:06.183Z',
createdAt: '2022-03-28T15:07:11.173Z',
host: 'https://api.openverse.engineering',
resHumanReadable: true,
resUncompressed: true,
Expand Down Expand Up @@ -28,7 +28,7 @@
status: 200,
headers: {
date: [
'Mon, 14 Mar 2022 17:07:08 GMT',
'Mon, 28 Mar 2022 15:07:11 GMT',
],
'content-type': [
'application/json',
Expand Down Expand Up @@ -57,17 +57,20 @@
'referrer-policy': [
'same-origin',
],
'cross-origin-opener-policy': [
'same-origin',
],
'cache-control': [
'max-age=14400',
],
'cf-cache-status': [
'HIT',
],
age: [
'7089',
'102870',
],
'last-modified': [
'Mon, 14 Mar 2022 15:08:59 GMT',
'Sun, 27 Mar 2022 10:32:41 GMT',
],
'expect-ct': [
'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"',
Expand All @@ -79,7 +82,7 @@
'cloudflare',
],
'cf-ray': [
'6ebe9a994fddf379-ATL',
'6f3146243c22d433-BUD',
],
'content-encoding': [
'br',
Expand Down
13 changes: 8 additions & 5 deletions test/tapes/response-71.json5 → ...8-621b-4ec2-bf70-f47a74380452_close.json5
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
meta: {
createdAt: '2022-03-14T17:05:46.673Z',
createdAt: '2022-03-28T15:06:02.913Z',
host: 'https://api.openverse.engineering',
resHumanReadable: true,
},
Expand All @@ -17,7 +17,7 @@
status: 200,
headers: {
date: [
'Mon, 14 Mar 2022 17:05:47 GMT',
'Mon, 28 Mar 2022 15:06:03 GMT',
],
'content-type': [
'application/json',
Expand All @@ -43,17 +43,20 @@
'referrer-policy': [
'same-origin',
],
'cross-origin-opener-policy': [
'same-origin',
],
'cache-control': [
'max-age=14400',
],
'cf-cache-status': [
'HIT',
],
age: [
'10409',
'102891',
],
'last-modified': [
'Mon, 14 Mar 2022 14:12:18 GMT',
'Sun, 27 Mar 2022 10:31:12 GMT',
],
'expect-ct': [
'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"',
Expand All @@ -65,7 +68,7 @@
'cloudflare',
],
'cf-ray': [
'6ebe989cacf0f371-ATL',
'6f31447989f7684c-BUD',
],
'alt-svc': [
'h3=":443"; ma=86400, h3-29=":443"; ma=86400',
Expand Down
Loading

0 comments on commit e33d638

Please sign in to comment.