The great refactor (#82)

This commit is contained in:
Simon Lecoq
2021-01-30 12:31:09 +01:00
committed by GitHub
parent f8c6d19a4e
commit 682e43e10b
158 changed files with 6738 additions and 5022 deletions

View File

@@ -0,0 +1,66 @@
/** Mocked data */
export default function ({faker, url, options, login = faker.internet.userName()}) {
//Last.fm api
if (/^https:..ws.audioscrobbler.com.*$/.test(url)) {
//Get recently played tracks
if (/user.getrecenttracks/.test(url)) {
console.debug(`metrics/compute/mocks > mocking lastfm api result > ${url}`)
const artist = faker.random.word()
const album = faker.random.words(3)
const track = faker.random.words(5)
const date = faker.date.recent()
return ({
status:200,
data:{
recenttracks:{
"@attr":{
page:"1",
perPage:"1",
user:"RJ",
total:"100",
pages:"100",
},
track:[
{
artist:{
mbid:"",
"#text":artist,
},
album:{
mbid:"",
"#text":album,
},
image:[
{
size:"small",
"#text":faker.image.abstract(),
},
{
size:"medium",
"#text":faker.image.abstract(),
},
{
size:"large",
"#text":faker.image.abstract(),
},
{
size:"extralarge",
"#text":faker.image.abstract(),
},
],
streamable:"0",
date:{
uts:Math.floor(date.getTime() / 1000),
"#text":date.toUTCString().slice(5, 22),
},
url:faker.internet.url(),
name:track,
mbid:"",
},
],
},
},
})
}
}
}

View File

@@ -0,0 +1,105 @@
/** Mocked data */
export default function ({faker, url, options, login = faker.internet.userName()}) {
//Tested url
const tested = url.match(/&url=(?<tested>.*?)(?:&|$)/)?.groups?.tested ?? faker.internet.url()
//Pagespeed api
if (/^https:..www.googleapis.com.pagespeedonline.v5/.test(url)) {
//Pagespeed result
if (/v5.runPagespeed.*&key=MOCKED_TOKEN/.test(url)) {
console.debug(`metrics/compute/mocks > mocking pagespeed api result > ${url}`)
return ({
status:200,
data:{
captchaResult:"CAPTCHA_NOT_NEEDED",
id:tested,
lighthouseResult:{
requestedUrl:tested,
finalUrl:tested,
lighthouseVersion:"6.3.0",
audits:{
"final-screenshot":{
id:"final-screenshot",
title:"Final Screenshot",
score: null,
details:{
data:"data:image/jpg;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mOcOnfpfwAGfgLYttYINwAAAABJRU5ErkJggg==",
type:"screenshot",
timestamp:Date.now()
}
},
metrics:{
id:"metrics",
title:"Metrics",
score: null,
details:{
items:[
{
observedFirstContentfulPaint:faker.random.number(500),
observedFirstVisualChangeTs:faker.time.recent(),
observedFirstContentfulPaintTs:faker.time.recent(),
firstContentfulPaint:faker.random.number(500),
observedDomContentLoaded:faker.random.number(500),
observedFirstMeaningfulPaint:faker.random.number(1000),
maxPotentialFID:faker.random.number(500),
observedLoad:faker.random.number(500),
firstMeaningfulPaint:faker.random.number(500),
observedCumulativeLayoutShift:faker.random.float({max:1}),
observedSpeedIndex:faker.random.number(1000),
observedSpeedIndexTs:faker.time.recent(),
observedTimeOriginTs:faker.time.recent(),
observedLargestContentfulPaint:faker.random.number(1000),
cumulativeLayoutShift:faker.random.float({max:1}),
observedFirstPaintTs:faker.time.recent(),
observedTraceEndTs:faker.time.recent(),
largestContentfulPaint:faker.random.number(2000),
observedTimeOrigin:faker.random.number(10),
speedIndex:faker.random.number(1000),
observedTraceEnd:faker.random.number(2000),
observedDomContentLoadedTs:faker.time.recent(),
observedFirstPaint:faker.random.number(500),
totalBlockingTime:faker.random.number(500),
observedLastVisualChangeTs:faker.time.recent(),
observedFirstVisualChange:faker.random.number(500),
observedLargestContentfulPaintTs:faker.time.recent(),
estimatedInputLatency:faker.random.number(100),
observedLoadTs:faker.time.recent(),
observedLastVisualChange:faker.random.number(1000),
firstCPUIdle:faker.random.number(1000),
interactive:faker.random.number(1000),
observedNavigationStartTs:faker.time.recent(),
observedNavigationStart:faker.random.number(10),
observedFirstMeaningfulPaintTs:faker.time.recent()
},
]
},
},
},
categories:{
"best-practices":{
id:"best-practices",
title:"Best Practices",
score:faker.random.float({max:1}),
},
seo:{
id:"seo",
title:"SEO",
score:faker.random.float({max:1}),
},
accessibility:{
id:"accessibility",
title:"Accessibility",
score:faker.random.float({max:1}),
},
performance: {
id:"performance",
title:"Performance",
score:faker.random.float({max:1}),
}
},
},
analysisUTCTimestamp:`${faker.date.recent()}`,
}
})
}
}
}

View File

@@ -0,0 +1,65 @@
/** Mocked data */
export default function ({faker, url, options, login = faker.internet.userName()}) {
//Spotify api
if (/^https:..api.spotify.com/.test(url)) {
//Get recently played tracks
if (/me.player.recently-played/.test(url)&&(options?.headers?.Authorization === "Bearer MOCKED_TOKEN_ACCESS")) {
console.debug(`metrics/compute/mocks > mocking spotify api result > ${url}`)
const artist = faker.random.words()
const track = faker.random.words(5)
return ({
status:200,
data:{
items:[
{
track:{
album:{
album_type:"single",
artists:[
{
name:artist,
type:"artist",
}
],
images:[
{
height:640,
url:faker.image.abstract(),
width:640
},
{
height:300,
url:faker.image.abstract(),
width:300
},
{
height:64,
url:faker.image.abstract(),
width:64
}
],
name:track,
release_date:`${faker.date.past()}`.substring(0, 10),
type:"album",
},
artists:[
{
name:artist,
type:"artist",
}
],
name:track,
preview_url:faker.internet.url(),
type:"track",
},
played_at:`${faker.date.recent()}`,
context:{
type:"album",
}
},
],
}
})
}
}
}

View File

@@ -0,0 +1,64 @@
/** Mocked data */
export default function ({faker, url, options, login = faker.internet.userName()}) {
//Twitter api
if (/^https:..api.twitter.com/.test(url)) {
//Get user profile
if ((/users.by.username/.test(url))&&(options?.headers?.Authorization === "Bearer MOCKED_TOKEN")) {
console.debug(`metrics/compute/mocks > mocking twitter api result > ${url}`)
const username = url.match(/username[/](?<username>.*?)[?]/)?.groups?.username ?? faker.internet.userName()
return ({
status:200,
data:{
data:{
profile_image_url:faker.image.people(),
name:faker.name.findName(),
verified:faker.random.boolean(),
id:faker.random.number(1000000).toString(),
username,
},
}
})
}
//Get recent tweets
if ((/tweets.search.recent/.test(url))&&(options?.headers?.Authorization === "Bearer MOCKED_TOKEN")) {
console.debug(`metrics/compute/mocks > mocking twitter api result > ${url}`)
return ({
status:200,
data:{
data:[
{
id:faker.random.number(100000000000000).toString(),
created_at:`${faker.date.recent()}`,
entities:{
mentions:[
{start:22, end:33, username:"lowlighter"},
],
},
text:"Checkout metrics from @lowlighter ! #GitHub",
},
{
id:faker.random.number(100000000000000).toString(),
created_at:`${faker.date.recent()}`,
text:faker.lorem.paragraph(),
}
],
includes:{
users:[
{
id:faker.random.number(100000000000000).toString(),
name:"lowlighter",
username:"lowlighter",
},
]
},
meta:{
newest_id:faker.random.number(100000000000000).toString(),
oldest_id:faker.random.number(100000000000000).toString(),
result_count:2,
next_token:"MOCKED_CURSOR",
},
}
})
}
}
}