Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: test redirects: 10000 itens #531

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions faststore.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ module.exports = {
nodeVersion: 18,
cypressVersion: 12,
},
redirects: () => {
const redirects = require("./src/redirects.json");
return redirects
},
account: "storeframework",
vtexHeadlessCms: {
webhookUrls: [
Expand Down
31 changes: 31 additions & 0 deletions generateRedirects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const fs = require('fs')

const possibleDestinations = ['/4k-philips-monitor-99988213/p', '/aedle-vk1-headphone-99988211/p', '/echo-dot-smart-speaker-99988214/p']

function generateRandomString(prefix, length) {
const characters = 'abcdefghijklmnopqrstuvwxyz';
const randomString = Array(length)
.fill()
.map(() => characters.charAt(Math.floor(Math.random() * characters.length)))
.join('')
return prefix + randomString
}


function generateRedirects(amount) {
const redirects = []
for (let i = 0; i < amount; i++) {
const source = generateRandomString('/produto/', 15)
const destination = possibleDestinations[i % possibleDestinations.length]
redirects.push({ source, destination, permanent: true })
}

return redirects
}

(function main() {
const redirects = generateRedirects(10000)
console.log(redirects)
fs.writeFileSync('./src/redirects.json', JSON.stringify(redirects, null, 2))
})()

Loading