How to use purgeCloudflareCache method in Cypress

Best JavaScript code snippet using cypress

utilsController.js

Source:utilsController.js Github

copy

Full Screen

...203 .update('editedAt', Math.floor(Date.now() / 1000))204 .catch(console.error)205 }206 if (config.cloudflare.purgeCache) {207 // purgeCloudflareCache() is an async function, but let us not wait for it208 const names = filtered.map(file => file.name)209 utilsController.purgeCloudflareCache(names)210 }211 return failed212}213utilsController.purgeCloudflareCache = async names => {214 if (!cloudflareAuth) { return }215 const thumbs = []216 names = names.map(name => {217 const url = `${config.domain}/${name}`218 const extname = utilsController.extname(name)219 if (utilsController.mayGenerateThumb(extname)) {220 thumbs.push(`${config.domain}/thumbs/${name.slice(0, -extname.length)}.png`)221 }222 return url223 })...

Full Screen

Full Screen

upload.js

Source:upload.js Github

copy

Full Screen

...73 'zip filename should end with .zip', zipName)74 const osName = getUploadNameByOsAndArch(platform)75 la(check.unemptyString(osName), 'missing osName', osName)76 const url = getDesktopUrl(version, osName, zipName)77 return purgeCloudflareCache(url)78}79// purges links to desktop app for all platforms80// for a given version81const purgeDesktopAppAllPlatforms = function (version, zipName) {82 la(check.unemptyString(version), 'missing desktop version', version)83 la(check.unemptyString(zipName), 'missing zipName', zipName)84 const platforms = ['darwin', 'linux', 'win32']85 console.log(`purging all desktop links for version ${version} from Cloudflare`)86 return Promise.mapSeries(platforms, (platform) => {87 return purgeDesktopAppFromCache({ version, platform, zipName })88 })89}90// all architectures we are building test runner for91const validPlatformArchs = ['darwin-x64', 'linux-x64', 'win32-ia32', 'win32-x64']...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...20 })21 await app.process()22 return app.build()23}24async function purgeCloudflareCache(urls) {25 for (let index = 0; index < urls.length; index += 30) {26 let sliced = urls.slice(index, index + 30 < urls.length ? urls.length : index + 30)27 try {28 let res = await request(29 {30 url: `https://api.cloudflare.com/client/v4/zones/${cf_zone_id}/purge_cache`,31 method: 'POST',32 body: {33 "files": sliced34 },35 json: true,36 headers: {37 "X-Auth-Email": cf_email,38 "X-Auth-Key": cf_key39 }40 })41 console.log(JSON.stringify(res))42 } catch (e) {43 console.log(JSON.stringify(e))44 }45 }46}47function collectTargets(body) {48 let targets = new Set()49 body.commits.forEach(commit => {50 let changes = commit.added.concat(commit.removed).concat(commit.modified)51 changes.forEach(change => {52 let i = change.indexOf('/')53 if (i != -1) {54 let target = change.substring(0, i)55 if (target in sites) {56 targets.add(target)57 }58 }59 })60 })61 return targets62}63function collectFiles(parent, files) {64 fs.readdirSync(parent).forEach(file => {65 var child = parent + path.sep + file;66 if (fs.lstatSync(child).isDirectory()) {67 collectFiles(child, files);68 } else {69 files.push(parent + path.sep + file);70 }71 });72}73function collectUrls(target, path) {74 let urls = new Set()75 let files = []76 collectFiles(path, files)77 for (const file of files) {78 urls.add(`https://${sites[target]}/${file.replace(path, "").replace(/\\/g, "/").substring(1)}`)79 }80 return urls81}82http.createServer(function (req, res) {83 let body = []84 req.on('error', (err) => {85 console.error(err)86 }).on('data', function (data) {87 body.push(data)88 }).on('end', async () => {89 res.on('error', (err) => {90 console.error(err)91 })92 body = Buffer.concat(body).toString()93 let sig = "sha1=" + crypto.createHmac('sha1', secret).update(body).digest('hex')94 if (process.env.NODE_ENV === 'production') {95 if (req.headers['x-hub-signature'] != sig) {96 console.error(`bad request: ${req.headers['x-hub-signature']} rather than ${sig}`)97 res.statusCode = 40398 res.end()99 return100 }101 }102 let targets103 try {104 targets = collectTargets(JSON.parse(body))105 } catch (e) {106 console.log(e)107 res.write(e.toString())108 res.write('\n')109 }110 targets.forEach(value => {111 res.write(`Site https://${sites[value]} requires rebuild.\n`)112 console.log(`Site https://${sites[value]} requires rebuild`)113 })114 res.write("Calling git pull...\n")115 console.log("Calling git pull")116 let child = spawn('git', ['pull'])117 child.stdout.on('data', function (data) {118 res.write(data)119 console.log(data.toString())120 })121 child.stderr.on('data', function (data) {122 res.write(data)123 console.error(data.toString())124 })125 child.on('close', async (code) => {126 res.write(`Child process exited with code ${code}`)127 console.log(`Child process exited with code ${code}`)128 res.statusCode = 200129 res.end()130 for (const target of targets) {131 console.log(`vuepress build ../${target}...`)132 await buildVuePress(`../${target}`)133 console.log(`purge Cloudflare cache...`)134 let urls = collectUrls(target, `../${target}/.vuepress/dist`)135 urls.forEach(value => {136 console.log(`Url ${value} requires purge cache`)137 })138 await purgeCloudflareCache(urls)139 }140 })141 })...

Full Screen

Full Screen

entrypoint.mjs

Source:entrypoint.mjs Github

copy

Full Screen

...19 20 if (sha256Hash !== expectedWindowsSha256Hash)21 throw new Error(`sha256sum doesn't match for downloaded ${windowsFilename}`)22 await $`b2 upload-file --quiet --noProgress --sha1 ${sha1Hash} assets-birkhoff-me ./${windowsFilename} clash.exe`23 await purgeCloudflareCache(["https://assets.birkhoff.me/clash.exe"])24 })(),25 (async () => {26 await $`wget -q -O ${macosFilename} ${macosUrl}`27 const sha256Hash = await hashFile(macosFilename, "sha256")28 const sha1Hash = await hashFile(macosFilename, "sha1")29 if (sha256Hash !== expectedMacosSha256Hash)30 throw new Error(`sha256sum doesn't match for downloaded ${macosFilename}`)31 await $`b2 upload-file --quiet --noProgress --sha1 ${sha1Hash} assets-birkhoff-me ./${macosFilename} clash.dmg`32 await purgeCloudflareCache(["https://assets.birkhoff.me/clash.dmg"])33 })()34])...

Full Screen

Full Screen

cloudflare.mjs

Source:cloudflare.mjs Github

copy

Full Screen

1export async function purgeCloudflareCache (files) {2 const req = await fetch(`https://api.cloudflare.com/client/v4/zones/${process.env.CF_ZONE_ID}/purge_cache`, {3 method: 'post',4 headers: {5 'Content-Type': 'application/json',6 'Authorization': `Bearer ${process.env.CF_API_TOKEN}`7 },8 body: JSON.stringify({ files }),9 })10 const resp = await req.json()11 if (!resp.success) {12 throw new Error(JSON.stringify(resp))13 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1Cypress.Commands.add('purgeCloudflareCache', (url) => {2 cy.request({3 headers: {4 },5 body: {6 },7 });8});9Cypress.Commands.add('purgeCloudflareCache', (url) => {10 cy.request({11 headers: {12 },13 body: {14 },15 });16});17Cypress.Commands.add('purgeCloudflareCache', (url) => {18 cy.request({19 headers: {20 },21 body: {22 },23 });24});25Cypress.Commands.add('purgeCloudflareCache', (url) => {26 cy.request({27 headers: {28 },29 body: {30 },31 });32});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { purgeCloudflareCache } from 'cypress-cloudflare-cache'2describe('test', () => {3it('test', () => {4})5})6import { purgeCloudflareCache } from 'cypress-cloudflare-cache'7describe('test', () => {8it('test', () => {9})10})11import { purgeCloudflareCache } from 'cypress-cloudflare-cache'12describe('test', () => {13it('test', () => {14purgeCloudflareCache()15})16})17import { purgeCloudflareCache } from 'cypress-cloudflare-cache'18describe('test', () => {19it('test', () => {20purgeCloudflareCache(['tag1', 'tag2'])21})22})23import { purgeCloudflareCache } from '

Full Screen

Using AI Code Generation

copy

Full Screen

1describe("My Test", () => {2 it("Should do something", () => {3 });4});5describe("My Test", () => {6 it("Should do something", () => {7 });8});

Full Screen

Using AI Code Generation

copy

Full Screen

1const purgeCloudflareCache = require('cypress-cloudflare-cache-purge').purgeCloudflareCache;2describe('My First Test', function() {3 it('Does not do much!', function() {4 cy.contains('Some Text');5 })6})

Full Screen

Cypress Tutorial

Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.

Chapters:

  1. What is Cypress? -
  2. Why Cypress? - Learn why Cypress might be a good choice for testing your web applications.
  3. Features of Cypress Testing - Learn about features that make Cypress a powerful and flexible tool for testing web applications.
  4. Cypress Drawbacks - Although Cypress has many strengths, it has a few limitations that you should be aware of.
  5. Cypress Architecture - Learn more about Cypress architecture and how it is designed to be run directly in the browser, i.e., it does not have any additional servers.
  6. Browsers Supported by Cypress - Cypress is built on top of the Electron browser, supporting all modern web browsers. Learn browsers that support Cypress.
  7. Selenium vs Cypress: A Detailed Comparison - Compare and explore some key differences in terms of their design and features.
  8. Cypress Learning: Best Practices - Take a deep dive into some of the best practices you should use to avoid anti-patterns in your automation tests.
  9. How To Run Cypress Tests on LambdaTest? - Set up a LambdaTest account, and now you are all set to learn how to run Cypress tests.

Certification

You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.

YouTube

Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.

Run Cypress automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful