Skip to content

Commit ad6abc9

Browse files
author
Théotime Huart
committed
fix: add lang to pathname
1 parent 048a80e commit ad6abc9

File tree

7 files changed

+19
-19
lines changed

7 files changed

+19
-19
lines changed

packages/didiff-lib/src/__tests__/index.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,33 +114,35 @@ describe('didiff-lib', () => {
114114
describe('getPathnameFromUrl', () => {
115115
it('should get slug from basic url', () => {
116116
expect(getPathnameFromUrl('https://scaleway.com/en/saas')).toMatch(
117-
'saas',
117+
'en-saas',
118118
)
119119
})
120120
it('should get slug from complex url', () => {
121121
expect(
122122
getPathnameFromUrl('https://scaleway.com/fr/dedibox/start'),
123-
).toMatch('dedibox!start')
123+
).toMatch('fr-dedibox-start')
124124
})
125125
it('should get slug from home url', () => {
126-
expect(getPathnameFromUrl('https://scaleway.com/en/')).toMatch('home')
126+
expect(getPathnameFromUrl('https://scaleway.com/en/')).toMatch(
127+
'en-index',
128+
)
127129
})
128130
})
129131
describe('getImageInformations', () => {
130132
it('should get informations about image', () => {
131133
const infos = getImageInformations({
132134
url: 'https://scaleway.com/en/saas',
133-
pathname: 'saas',
135+
pathname: 'en-saas',
134136
name: 'original',
135137
})
136138
const fsPath = nodePath.resolve(__dirname, '../screenshots')
137139

138140
expect(infos).toMatchObject({
139141
url: 'https://scaleway.com/en/saas',
140142
name: 'original',
141-
fullName: 'saas-original.png',
142-
fullPath: `${fsPath}/saas-original.png`,
143-
path: `${fsPath}/saas`,
143+
fullName: 'en-saas-original.png',
144+
fullPath: `${fsPath}/en-saas-original.png`,
145+
path: `${fsPath}/en-saas`,
144146
})
145147
})
146148
})

packages/didiff-lib/src/capture/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ async function capturePages({ original, sample }) {
8383
log.err('Fail during the screenshoting process ❌', error)
8484
process.exit(1)
8585
}
86-
87-
log.info('Capturing ✅')
8886
}
8987

9088
export default capturePages

packages/didiff-lib/src/diff.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ async function cropBiggerImage({ image, path }, dimensions) {
2020
width: dimensions.width,
2121
height: dimensions.height,
2222
})
23-
log.info('Cropping ✅')
2423
}
2524
function getSmallestDimensions({ originalData, sampleData }) {
2625
if (sampleData.png.height > originalData.png.height) {
@@ -84,7 +83,7 @@ async function isCapturesDifferents({ original = {}, sample = {}, diff = {} }) {
8483
log.info('Diff was found ❗️')
8584
return true
8685
}
87-
log.info('No diff')
86+
log.info('No diff, skipping')
8887
return false
8988
} catch (error) {
9089
log.err('Fail during the diffing process ❌', error)

packages/didiff-lib/src/helpers.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ function getImageInformations({ url = '', pathname = '', name = '' }) {
3737
}
3838
function getPathnameFromUrl(url = '') {
3939
const urlParts = url.split('/').filter(Boolean)
40-
const langIndex = urlParts.findIndex(v => v === 'en' || v === 'fr') + 1
41-
return urlParts.slice(langIndex, urlParts.length).join('!') || 'home'
40+
const langIndex = urlParts.findIndex(v => v === 'en' || v === 'fr')
41+
const slicedName = urlParts.slice(langIndex, urlParts.length) || []
42+
return (slicedName.length > 1 ? slicedName : [...slicedName, 'index']).join(
43+
'-',
44+
)
4245
}
4346

4447
export {

packages/didiff-lib/src/run.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ dotenv.config()
1818
const TEST_DATE = new Date()
1919

2020
function cleanCaptures(fsPaths = []) {
21-
log.info('Cleaning screenshots ...')
2221
removeFiles(fsPaths)
23-
log.info('Cleaning screenshots ✅')
2422
}
2523
function upload(pathname, { original, sample, diff }) {
2624
const dateString = TEST_DATE.toLocaleDateString('fr').replace(/\//g, '-')
@@ -65,7 +63,7 @@ async function startLoop(urls) {
6563
const nbUrls = urls.length
6664
let totalDiff = 0
6765

68-
log.info(`Didiff will now check ${nbUrls} urls 📸`)
66+
log.info(`Didiff will now check ${nbUrls} urls 📸 \n`)
6967
for (let i = 0; i < nbUrls; i += 1) {
7068
const [original, sample] = urls[i]
7169
const pathname = getPathnameFromUrl(original)
@@ -106,11 +104,12 @@ async function startLoop(urls) {
106104

107105
log.info(`Process for /${pathname} done.`)
108106
if (nbUrls - (i + 1) === 0) {
109-
log.info(`All urls have been handled! (${nbUrls}) 📸`)
107+
log.info(`\nAll urls have been handled! (${nbUrls}) 📸`)
110108
log.info(`Didiff found ${totalDiff} diffs.`)
111109
log.info(`Shutting down...`)
112110
} else {
113111
log.info(`Still ${nbUrls - (i + 1)} check to do.`)
112+
log.info('---')
114113
}
115114
}
116115
}

packages/didiff-lib/src/s3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ function init() {
2121
}
2222

2323
function upload({ key, body }) {
24-
log.info('Uploading', key)
2524
const client = getClient()
2625
client.upload(
2726
{
@@ -38,6 +37,7 @@ function upload({ key, body }) {
3837
}
3938

4039
async function uploadBatch(batch = []) {
40+
log.info('Uploading...')
4141
batch.forEach(data => upload(data))
4242
}
4343

packages/didiff-lib/src/urls.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ function getUrls(file = '') {
1515
const [o, s] = curr.split(',')
1616
return [...acc, [o, s]]
1717
}, [])
18-
log.info('Getting urls done ✅')
1918
return urls || []
2019
} catch (error) {
2120
log.err(

0 commit comments

Comments
 (0)