New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@chromaui/test-archiver

Package Overview
Dependencies
Maintainers
12
Versions
229
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chromaui/test-archiver - npm Package Compare versions

Comparing version 0.0.53 to 0.0.54--canary.b9530ca.0

5

dist/cypress-api/index.d.ts

@@ -23,3 +23,6 @@ import { elementNode } from 'rrweb-snapshot';

declare const archiveCypress: (params: ArchiveParams) => Promise<null>;
declare const doCDP: () => Promise<any>;
declare const finishCDP: () => Promise<unknown>;
declare const onBeforeBrowserLaunch: (browser: {}, launchOptions: any) => any;
export { archiveCypress };
export { archiveCypress, doCDP, finishCDP, onBeforeBrowserLaunch };

21

dist/cypress-api/index.js
'use strict';
var H = require('chrome-remote-interface');
var fsExtra = require('fs-extra');
var E = require('path');
var P = require('mime');
var v = require('path');
var L = require('mime');
var crypto = require('crypto');
var rrwebSnapshot = require('rrweb-snapshot');
var U = require('srcset');
var k = require('srcset');
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
var E__default = /*#__PURE__*/_interopDefault(E);
var P__default = /*#__PURE__*/_interopDefault(P);
var U__default = /*#__PURE__*/_interopDefault(U);
var H__default = /*#__PURE__*/_interopDefault(H);
var v__default = /*#__PURE__*/_interopDefault(v);
var L__default = /*#__PURE__*/_interopDefault(L);
var k__default = /*#__PURE__*/_interopDefault(k);
var $=Object.defineProperty;var v=(i,t,e)=>t in i?$(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var n=(i,t)=>$(i,"name",{value:t,configurable:!0});var p=(i,t,e)=>(v(i,typeof t!="symbol"?t+"":t,e),e);var l=process.env.LOG?console:{log:(...i)=>{},warn:(...i)=>{}};var g=class{constructor(t,e,r){p(this,"url");p(this,"response");p(this,"shortenedFileNameLength");p(this,"pageUrl");this.url=new URL(t),this.response=e,this.shortenedFileNameLength=250,this.pageUrl=new URL(r);}originalSrc(){return this.url.toString()}toFileSystemPath(){let t=this.url.pathname;return t=this.preserveExternalDomain(this.url),t=this.ensureNonDirectory(t),t=this.encodeQueryString(t),t=this.truncateFileName(t),t=this.removeSpecialChars(t),t=this.addExtension(t),t}ensureNonDirectory(t){return t.endsWith("/")?`${t}index.html`:t}encodeQueryString(t){let e=this.url.search;if(!e)return t;let r=this.hash(e);return `${t}-${r}`}truncateFileName(t){let e=t.split("/"),r=[];return e.forEach((s,o)=>{let c=s;s.length>this.shortenedFileNameLength&&(c=s.substring(0,this.shortenedFileNameLength),l.log(`Chunk of filename '${s}' is too long. Shortening to '${c}'`)),r.push(c);}),`${t.startsWith("/")?"/":""}${E__default.default.join(...r)}`}removeSpecialChars(t){return t.replace(/[%]/g,"")}addExtension(t){if("error"in this.response||!this.response.contentType)return t;let e=t;if(!E__default.default.extname(e)){let r=P__default.default.getExtension(this.response.contentType);r&&(e=`${t}.${r}`);}return e}preserveExternalDomain(t){return t.origin===this.pageUrl.origin?t.pathname:`/${encodeURIComponent(t.host)}/${t.pathname}`}hash(t){return crypto.createHash("md5").update(t).digest("hex")}};n(g,"ArchiveFile");var F=/url\((?!['"]?(?:data):)['"]?([^'")]*)['"]?\)/gi,y=class{constructor(t){p(this,"snapshot");if(Buffer.isBuffer(t)){let e=t.toString("utf-8");this.snapshot=JSON.parse(e);}else this.snapshot=JSON.parse(t);}async mapAssetPaths(t){let e=await this.mapNode(this.snapshot,t);return JSON.stringify(e)}async mapNode(t,e){return t=this.mapNodeAttributes(t,e),t=this.mapTextElement(t,e),"childNodes"in t&&(t.childNodes=await Promise.all(t.childNodes.map(async r=>this.mapNode(r,e)))),t}mapNodeAttributes(t,e){if(t.type===rrwebSnapshot.NodeType.Element){if(t.attributes.src){let r=t.attributes.src;e.has(r)&&(t.attributes.src=e.get(r));}if(t.attributes.style){let r=t.attributes.style,s=this.mapCssUrls(r,e);t.attributes.style=s;}if(t.attributes._cssText){let r=t.attributes._cssText,s=this.mapCssUrls(r,e);t.attributes._cssText=s;}if(t.tagName==="img"&&t.attributes.srcset){let r=t.attributes.srcset,s=this.mapSrcsetUrls(r,e);s&&(t.attributes.src=s,delete t.attributes.srcset,delete t.attributes.sizes);}}return t}mapTextElement(t,e){if(t.type===rrwebSnapshot.NodeType.Text&&t.isStyle&&t.textContent){let r=this.mapCssUrls(t.textContent,e);t.textContent=r;}return t}mapCssUrls(t,e){return t.replace(F,(r,s)=>{let o=r;return e.has(s)&&(o=r.replace(s,e.get(s))),o})}mapSrcsetUrls(t,e){let r=U__default.default.parse(t),s;return r.forEach(o=>{e.has(o.url)&&(s=e.get(o.url));}),s}};n(y,"DOMSnapshot");var S=n(i=>i.toLowerCase().replace(/[ ’–—―′¿'`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi,"-").replace(/-+/g,"-").replace(/^-+/,"").replace(/-+$/,""),"sanitize");async function O(i,t,e,r){let{title:s,outputDir:o,pageUrl:c}=i,h=E.join(o,"..","chromatic-archives"),a=E.join(h,"archive");await fsExtra.ensureDir(h),l.log(`Writing test results for "${s}"`);let N=new Map;await Promise.all(Object.entries(e).map(async([u,f])=>{if("error"in f)return;let w=new g(u,f,c),b=w.originalSrc(),d=w.toFileSystemPath();b!==d&&N.set(b,d),await fsExtra.outputFile(E.join(a,d),f.body);})),await Promise.all(await Object.entries(t).map(async([u,f])=>{let b=await new y(f).mapAssetPaths(N);await fsExtra.outputFile(E.join(a,`${S(s)}-${S(u)}.snapshot.json`),b);})),await _(E.join(h,`${S(s)}.stories.json`),s,t,r);let x=Object.entries(e).filter(([,u])=>"error"in u);x.length>0&&(l.log(`Encountered ${x.length} errors archiving resources, writing to 'errors.json'`),await fsExtra.outputJson(E.join(a,"errors.json"),{errors:Object.fromEntries(x)}));}n(O,"writeTestResult");async function _(i,t,e,r){l.log(`Writing ${i}`),await fsExtra.outputJson(i,{title:t,stories:Object.keys(e).map(s=>({name:s,parameters:{server:{id:`${S(t)}-${S(s)}.snapshot.json`},chromatic:{...r}}}))});}n(_,"writeStoriesFile");var R=n(async({testTitle:i,domSnapshots:t,resourceArchive:e,chromaticStorybookParams:r,pageUrl:s})=>{let o=Object.entries(e).map(([h,a])=>[h,{...a,body:Buffer.from(a.body,"utf8")}]),c=Object.fromEntries(t.map((h,a)=>[`Snapshot #${a+1}`,Buffer.from(JSON.stringify(h))]));await O({title:i,outputDir:"./cypress/downloads/some",pageUrl:s},c,Object.fromEntries(o),{...r,viewport:{width:500,height:500}});},"doArchive"),st=n(async i=>(await R(i),null),"archiveCypress");
var E=Object.defineProperty;var P=(i,t,e)=>t in i?E(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var a=(i,t)=>E(i,"name",{value:t,configurable:!0});var c=(i,t,e)=>(P(i,typeof t!="symbol"?t+"":t,e),e);var n=process.env.LOG?console:{log:(...i)=>{},warn:(...i)=>{}};var S=class{constructor(t,e,r){c(this,"url");c(this,"response");c(this,"shortenedFileNameLength");c(this,"pageUrl");this.url=new URL(t),this.response=e,this.shortenedFileNameLength=250,this.pageUrl=new URL(r);}originalSrc(){return this.url.toString()}toFileSystemPath(){let t=this.url.pathname;return t=this.preserveExternalDomain(this.url),t=this.ensureNonDirectory(t),t=this.encodeQueryString(t),t=this.truncateFileName(t),t=this.removeSpecialChars(t),t=this.addExtension(t),t}ensureNonDirectory(t){return t.endsWith("/")?`${t}index.html`:t}encodeQueryString(t){let e=this.url.search;if(!e)return t;let r=this.hash(e);return `${t}-${r}`}truncateFileName(t){let e=t.split("/"),r=[];return e.forEach((s,o)=>{let l=s;s.length>this.shortenedFileNameLength&&(l=s.substring(0,this.shortenedFileNameLength),n.log(`Chunk of filename '${s}' is too long. Shortening to '${l}'`)),r.push(l);}),`${t.startsWith("/")?"/":""}${v__default.default.join(...r)}`}removeSpecialChars(t){return t.replace(/[%]/g,"")}addExtension(t){if("error"in this.response||!this.response.contentType)return t;let e=t;if(!v__default.default.extname(e)){let r=L__default.default.getExtension(this.response.contentType);r&&(e=`${t}.${r}`);}return e}preserveExternalDomain(t){return t.origin===this.pageUrl.origin?t.pathname:`/${encodeURIComponent(t.host)}/${t.pathname}`}hash(t){return crypto.createHash("md5").update(t).digest("hex")}};a(S,"ArchiveFile");var j=/url\((?!['"]?(?:data):)['"]?([^'")]*)['"]?\)/gi,N=class{constructor(t){c(this,"snapshot");if(Buffer.isBuffer(t)){let e=t.toString("utf-8");this.snapshot=JSON.parse(e);}else this.snapshot=JSON.parse(t);}async mapAssetPaths(t){let e=await this.mapNode(this.snapshot,t);return JSON.stringify(e)}async mapNode(t,e){return t=this.mapNodeAttributes(t,e),t=this.mapTextElement(t,e),"childNodes"in t&&(t.childNodes=await Promise.all(t.childNodes.map(async r=>this.mapNode(r,e)))),t}mapNodeAttributes(t,e){if(t.type===rrwebSnapshot.NodeType.Element){if(t.attributes.src){let r=t.attributes.src;e.has(r)&&(t.attributes.src=e.get(r));}if(t.attributes.style){let r=t.attributes.style,s=this.mapCssUrls(r,e);t.attributes.style=s;}if(t.attributes._cssText){let r=t.attributes._cssText,s=this.mapCssUrls(r,e);t.attributes._cssText=s;}if(t.tagName==="img"&&t.attributes.srcset){let r=t.attributes.srcset,s=this.mapSrcsetUrls(r,e);s&&(t.attributes.src=s,delete t.attributes.srcset,delete t.attributes.sizes);}}return t}mapTextElement(t,e){if(t.type===rrwebSnapshot.NodeType.Text&&t.isStyle&&t.textContent){let r=this.mapCssUrls(t.textContent,e);t.textContent=r;}return t}mapCssUrls(t,e){return t.replace(j,(r,s)=>{let o=r;return e.has(s)&&(o=r.replace(s,e.get(s))),o})}mapSrcsetUrls(t,e){let r=k__default.default.parse(t),s;return r.forEach(o=>{e.has(o.url)&&(s=e.get(o.url));}),s}};a(N,"DOMSnapshot");var x=a(i=>i.toLowerCase().replace(/[ ’–—―′¿'`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi,"-").replace(/-+/g,"-").replace(/^-+/,"").replace(/-+$/,""),"sanitize");async function $(i,t,e,r){let{title:s,outputDir:o,pageUrl:l}=i,h=v.join(o,"..","chromatic-archives"),u=v.join(h,"archive");await fsExtra.ensureDir(h),n.log(`Writing test results for "${s}"`);let w=new Map;await Promise.all(Object.entries(e).map(async([m,p])=>{if("error"in p)return;let y=new S(m,p,l),g=y.originalSrc(),R=y.toFileSystemPath();g!==R&&w.set(g,R),await fsExtra.outputFile(v.join(u,R),p.body);})),await Promise.all(await Object.entries(t).map(async([m,p])=>{let g=await new N(p).mapAssetPaths(w);await fsExtra.outputFile(v.join(u,`${x(s)}-${x(m)}.snapshot.json`),g);})),await D(v.join(h,`${x(s)}.stories.json`),s,t,r);let b=Object.entries(e).filter(([,m])=>"error"in m);b.length>0&&(n.log(`Encountered ${b.length} errors archiving resources, writing to 'errors.json'`),await fsExtra.outputJson(v.join(u,"errors.json"),{errors:Object.fromEntries(b)}));}a($,"writeTestResult");async function D(i,t,e,r){n.log(`Writing ${i}`),await fsExtra.outputJson(i,{title:t,stories:Object.keys(e).map(s=>({name:s,parameters:{server:{id:`${x(t)}-${x(s)}.snapshot.json`},chromatic:{...r}}}))});}a(D,"writeStoriesFile");var T=class{constructor(t,e=1e4,r){c(this,"archive",{});c(this,"client");c(this,"globalNetworkTimeoutMs");c(this,"allowedArchiveOrigins");c(this,"firstUrl");c(this,"closed",!1);c(this,"globalNetworkTimerId",null);c(this,"globalNetworkResolver");this.client=t,this.globalNetworkTimeoutMs=e,this.allowedArchiveOrigins=(r||[]).map(s=>`https://${s}`);}async watch(){this.client.on("Network.requestWillBeSent",this.requestWillBeSent.bind(this)),this.client.on("Network.responseReceived",this.responseReceived.bind(this)),this.client.on("Fetch.requestPaused",this.requestPaused.bind(this)),await this.client.send("Fetch.enable");}async idle(t){let e=new Promise((s,o)=>{this.globalNetworkResolver=s,this.globalNetworkTimerId=setTimeout(()=>{n.warn(`Global timeout of ${this.globalNetworkTimeoutMs}ms reached`),this.globalNetworkResolver();},this.globalNetworkTimeoutMs);}),r=t.waitForLoadState("networkidle").finally(()=>{clearTimeout(this.globalNetworkTimerId);});await Promise.race([e,r]),n.log("Watcher closing"),this.closed=!0;}setResponse(t,e){this.archive[t]=e;}requestWillBeSent(t){n.log("requestWillBeSent"),n.log(t);}responseReceived(t){n.log("responseReceived"),n.log(t);}async clientSend(t,e,r){try{return await this.client.send(e,r)}catch(s){return n.log("Client error",t.url,s),this.archive[t.url]={error:s},null}}async requestPaused({requestId:t,request:e,responseStatusCode:r,responseStatusText:s,responseErrorReason:o,responseHeaders:l}){if(!e.method.match(/get/i)){await this.clientSend(e,"Fetch.continueRequest",{requestId:t});return}if(r===304){await this.clientSend(e,"Fetch.continueRequest",{requestId:t});return}let h=new URL(e.url);this.firstUrl??(this.firstUrl=h);let u=h.origin===this.firstUrl.origin||this.allowedArchiveOrigins.includes(h.origin);if(n.log("requestPaused",h.toString(),r||o?"response":"request",this.firstUrl.toString(),u),this.closed&&n.log("Watcher closed, ignoring"),o){n.log(`Got response error: ${o}`),await this.clientSend(e,"Fetch.continueRequest",{requestId:t});return}if(r){if([301,302,307,308].includes(r)){await this.clientSend(e,"Fetch.continueRequest",{requestId:t,interceptResponse:!0});return}let w=await this.clientSend(e,"Fetch.getResponseBody",{requestId:t});if(w===null)return;let{body:b,base64Encoded:m}=w,p=l.find(({name:g})=>g.toLowerCase()==="content-type"),y=h.toString()===this.firstUrl.toString();u&&!y&&(this.archive[e.url]={statusCode:r,statusText:s,body:Buffer.from(b,m?"base64":"utf8"),contentType:p?.value}),await this.clientSend(e,"Fetch.continueRequest",{requestId:t});return}await this.clientSend(e,"Fetch.continueRequest",{requestId:t,interceptResponse:!0});}};a(T,"Watcher");var V=a(async({testTitle:i,domSnapshots:t,resourceArchive:e,chromaticStorybookParams:r,pageUrl:s})=>{let o=Object.entries(e).map(([h,u])=>[h,{...u,body:Buffer.from(u.body,"utf8")}]),l=Object.fromEntries(t.map((h,u)=>[`Snapshot #${u+1}`,Buffer.from(JSON.stringify(h))]));await $({title:i,outputDir:"./cypress/downloads/some",pageUrl:s},l,Object.fromEntries(o),{...r,viewport:{width:500,height:500}});},"doArchive"),wt=a(async i=>(await V({...i,resourceArchive:d.archive}),null),"archiveCypress"),d=null,A="",O="",bt=a(async()=>{try{let{webSocketDebuggerUrl:i}=await H.Version({host:A,port:O}),t=await H__default.default({target:i});d||(d=new T(t),await d.watch());}catch(i){console.log("err",i);}return null},"doCDP"),yt=a(()=>new Promise(i=>{d.idle().then(()=>{console.log("ARCHIVE OF POC",d.archive),i(null);});}),"finishCDP"),St=a((i={},t)=>{console.log("BEFORE LAUNCH");let e=t.args.find(l=>l.startsWith("--remote-debugging-address="));A=e?e.split("=")[1]:"127.0.0.1";let r=t.args.find(l=>l.startsWith("--remote-debugging-port=")),o=process.env.ELECTRON_EXTRA_LAUNCH_ARGS.split(" ").find(l=>l.startsWith("--remote-debugging-port")).split("=")[1];return O=r?r.split("=")[1]:o,t},"onBeforeBrowserLaunch");
exports.archiveCypress = st;
exports.archiveCypress = wt;
exports.doCDP = bt;
exports.finishCDP = yt;
exports.onBeforeBrowserLaunch = St;
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.js.map

@@ -5,4 +5,4 @@ 'use strict';

var c=Object.defineProperty;var n=(t,e)=>c(t,"name",{value:e,configurable:!0});Cypress.Commands.add("takeChromaticArchive",()=>{cy.document().then(t=>{let e=rrwebSnapshot.snapshot(t);cy.get("@manualSnapshots").then(s=>[...s,e]).as("manualSnapshots");});});var i=n(()=>{let t=null;cy.wrap({}).as("archive"),cy.wrap([]).as("manualSnapshots"),cy.intercept("**/*",e=>{if(!t){t=new URL(e.url);return}new URL(e.url).origin===t.origin&&(delete e.headers["if-none-match"],delete e.headers["if-modified-since"],e.continue(a=>{cy.get("@archive").then(r=>({...r,[a.url]:{statusCode:a.statusCode,statusText:a.statusMessage,body:a.body}})).as("archive");}));});},"setupNetworkListener"),u=n(()=>{cy.get("@archive").then(t=>{cy.document().then(e=>{let s=rrwebSnapshot.snapshot(e);cy.get("@manualSnapshots").then((a=[])=>{cy.url().then(r=>{cy.task("archiveCypress",{testTitle:Cypress.currentTest.title,domSnapshots:[...a,s],resourceArchive:t,chromaticStorybookParams:{diffThreshold:Cypress.env("diffThreshold")},pageUrl:r});});});});});},"completeArchive");beforeEach(()=>{i();});afterEach(()=>{u();});
var n=Object.defineProperty;var e=(t,s)=>n(t,"name",{value:s,configurable:!0});Cypress.Commands.add("takeChromaticArchive",()=>{cy.document().then(t=>{let s=rrwebSnapshot.snapshot(t);cy.get("@manualSnapshots").then(a=>[...a,s]).as("manualSnapshots");});});var c=e(()=>{cy.document().then(t=>{let s=rrwebSnapshot.snapshot(t);cy.get("@manualSnapshots").then((a=[])=>{cy.url().then(o=>{cy.task("archiveCypress",{testTitle:Cypress.currentTest.title,domSnapshots:[...a,s],chromaticStorybookParams:{diffThreshold:Cypress.env("diffThreshold")},pageUrl:o});});});});},"completeArchive");beforeEach(()=>{cy.wrap([]).as("manualSnapshots"),cy.task("doCDP");});afterEach(()=>{c(),cy.task("finishCDP");});
//# sourceMappingURL=out.js.map
//# sourceMappingURL=support.js.map
{
"name": "@chromaui/test-archiver",
"version": "0.0.53",
"version": "0.0.54--canary.b9530ca.0",
"description": "Archive end-to-end tests to be replayed in Storybook and Chromatic",

@@ -64,2 +64,3 @@ "repository": {

"@testing-library/user-event": "^13.2.1",
"@types/chrome-remote-interface": "^0",
"@types/express": "^4.17.17",

@@ -106,2 +107,3 @@ "@types/fs-extra": "^11.0.1",

"@segment/analytics-node": "^1.1.0",
"chrome-remote-interface": "^0.33.0",
"fs-extra": "^11.1.1",

@@ -108,0 +110,0 @@ "mime": "^3.0.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc