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.55 to 0.0.56--canary.55.8655fbb.0

17

dist/cypress-api/index.d.ts

@@ -1,14 +0,9 @@

import { elementNode } from 'rrweb-snapshot';
import { a as ChromaticStorybookParameters } from '../types-2f6f869c.js';
interface WriteParams {
testTitle: string;
domSnapshots: elementNode[];
chromaticStorybookParams: ChromaticStorybookParameters;
pageUrl: string;
interface TaskParams {
action: 'setup-network-listener' | 'save-archives';
payload?: any;
}
declare const setupNetworkListener: () => Promise<null>;
declare const saveArchives: (archiveInfo: WriteParams) => Promise<unknown>;
declare const prepareArchives: ({ action, payload }: TaskParams) => Promise<unknown>;
declare const onBeforeBrowserLaunch: (browser: Cypress.Browser, launchOptions: Cypress.BeforeBrowserLaunchOptions) => Cypress.BeforeBrowserLaunchOptions;
declare const installPlugin: (on: any) => void;
export { onBeforeBrowserLaunch, saveArchives, setupNetworkListener };
export { installPlugin, onBeforeBrowserLaunch, prepareArchives };
'use strict';
var H = require('chrome-remote-interface');
var k = require('chrome-remote-interface');
var fsExtra = require('fs-extra');

@@ -13,3 +13,3 @@ var E = require('path');

var H__default = /*#__PURE__*/_interopDefault(H);
var k__default = /*#__PURE__*/_interopDefault(k);
var E__default = /*#__PURE__*/_interopDefault(E);

@@ -19,8 +19,8 @@ var j__default = /*#__PURE__*/_interopDefault(j);

var T=Object.defineProperty;var L=(i,t,e)=>t in i?T(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var o=(i,t)=>T(i,"name",{value:t,configurable:!0});var c=(i,t,e)=>(L(i,typeof t!="symbol"?t+"":t,e),e);var u=process.env.LOG?console:{log:(...i)=>{},warn:(...i)=>{}};var b=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,n)=>{let l=s;s.length>this.shortenedFileNameLength&&(l=s.substring(0,this.shortenedFileNameLength),u.log(`Chunk of filename '${s}' is too long. Shortening to '${l}'`)),r.push(l);}),`${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=j__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")}};o(b,"ArchiveFile");var _=/url\((?!['"]?(?:data):)['"]?([^'")]*)['"]?\)/gi,S=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(_,(r,s)=>{let n=r;return e.has(s)&&(n=r.replace(s,e.get(s))),n})}mapSrcsetUrls(t,e){let r=D__default.default.parse(t),s;return r.forEach(n=>{e.has(n.url)&&(s=e.get(n.url));}),s}};o(S,"DOMSnapshot");var x=o(i=>i.toLowerCase().replace(/[ ’–—―′¿'`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi,"-").replace(/-+/g,"-").replace(/^-+/,"").replace(/-+$/,""),"sanitize");async function C(i,t,e,r){let{title:s,outputDir:n,pageUrl:l}=i,a=E.join(n,"..","chromatic-archives"),h=E.join(a,"archive");await fsExtra.ensureDir(a),u.log(`Writing test results for "${s}"`);let w=new Map;await Promise.all(Object.entries(e).map(async([p,m])=>{if("error"in m)return;let y=new b(p,m,l),g=y.originalSrc(),v=y.toFileSystemPath();g!==v&&w.set(g,v),await fsExtra.outputFile(E.join(h,v),m.body);})),await Promise.all(await Object.entries(t).map(async([p,m])=>{let g=await new S(m).mapAssetPaths(w);await fsExtra.outputFile(E.join(h,`${x(s)}-${x(p)}.snapshot.json`),g);})),await W(E.join(a,`${x(s)}.stories.json`),s,t,r);let d=Object.entries(e).filter(([,p])=>"error"in p);d.length>0&&(u.log(`Encountered ${d.length} errors archiving resources, writing to 'errors.json'`),await fsExtra.outputJson(E.join(h,"errors.json"),{errors:Object.fromEntries(d)}));}o(C,"writeTestResult");async function W(i,t,e,r){u.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}}}))});}o(W,"writeStoriesFile");var N=class{constructor(t,e){c(this,"archive",{});c(this,"client");c(this,"allowedArchiveOrigins");c(this,"firstUrl");this.client=t,this.allowedArchiveOrigins=(e||[]).map(r=>`https://${r}`);}async watch(){this.client.on("Fetch.requestPaused",this.requestPaused.bind(this)),await this.client.send("Fetch.enable");}async clientSend(t,e,r){try{return await this.client.send(e,r)}catch(s){return u.log("Client error",t.url,s),this.archive[t.url]={error:s},null}}async requestPaused({requestId:t,request:e,responseStatusCode:r,responseStatusText:s,responseErrorReason:n,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 a=new URL(e.url);this.firstUrl??(this.firstUrl=a);let h=a.origin===this.firstUrl.origin||this.allowedArchiveOrigins.includes(a.origin);if(u.log("requestPaused",a.toString(),r||n?"response":"request",this.firstUrl.toString(),h),n){u.log(`Got response error: ${n}`),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:d,base64Encoded:p}=w,m=l.find(({name:g})=>g.toLowerCase()==="content-type"),y=a.toString()===this.firstUrl.toString();h&&!y&&(this.archive[e.url]={statusCode:r,statusText:s,body:Buffer.from(d,p?"base64":"utf8"),contentType:m?.value}),await this.clientSend(e,"Fetch.continueRequest",{requestId:t});return}await this.clientSend(e,"Fetch.continueRequest",{requestId:t,interceptResponse:!0});}};o(N,"Watcher");var k=o(async({testTitle:i,domSnapshots:t,resourceArchive:e,chromaticStorybookParams:r,pageUrl:s})=>{let n=Object.entries(e).map(([a,h])=>[a,{...h,body:Buffer.from(h.body,"utf8")}]),l=Object.fromEntries(t.map((a,h)=>[`Snapshot #${h+1}`,Buffer.from(JSON.stringify(a))]));await C({title:i,outputDir:"./cypress/downloads/some",pageUrl:s},l,Object.fromEntries(n),r);},"writeArchives"),$=null,A="",P=0,gt=o(async()=>{try{let{webSocketDebuggerUrl:i}=await H.Version({host:A,port:P}),t=await H__default.default({target:i});$||($=new N(t),await $.watch());}catch(i){console.log("err",i);}return null},"setupNetworkListener"),ft=o(i=>new Promise(t=>k({...i,resourceArchive:$.archive}).then(()=>{t(null);})),"saveArchives"),wt=o((i,t)=>{let e=t.args.find(n=>n.startsWith("--remote-debugging-address="));A=e?e.split("=")[1]:"127.0.0.1";let r=t.args.find(n=>n.startsWith("--remote-debugging-port=")),s="";return r?[,s]=r.split("="):[,s]=process.env.ELECTRON_EXTRA_LAUNCH_ARGS.split(" ").find(l=>l.startsWith("--remote-debugging-port")).split("="),P=parseInt(s,10),t},"onBeforeBrowserLaunch");
var T=Object.defineProperty;var L=(i,t,e)=>t in i?T(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var o=(i,t)=>T(i,"name",{value:t,configurable:!0});var c=(i,t,e)=>(L(i,typeof t!="symbol"?t+"":t,e),e);var u=process.env.LOG?console:{log:(...i)=>{},warn:(...i)=>{}};var b=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,n)=>{let l=s;s.length>this.shortenedFileNameLength&&(l=s.substring(0,this.shortenedFileNameLength),u.log(`Chunk of filename '${s}' is too long. Shortening to '${l}'`)),r.push(l);}),`${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=j__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")}};o(b,"ArchiveFile");var _=/url\((?!['"]?(?:data):)['"]?([^'")]*)['"]?\)/gi,S=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(_,(r,s)=>{let n=r;return e.has(s)&&(n=r.replace(s,e.get(s))),n})}mapSrcsetUrls(t,e){let r=D__default.default.parse(t),s;return r.forEach(n=>{e.has(n.url)&&(s=e.get(n.url));}),s}};o(S,"DOMSnapshot");var x=o(i=>i.toLowerCase().replace(/[ ’–—―′¿'`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi,"-").replace(/-+/g,"-").replace(/^-+/,"").replace(/-+$/,""),"sanitize");async function A(i,t,e,r){let{title:s,outputDir:n,pageUrl:l}=i,a=E.join(n,"..","chromatic-archives"),h=E.join(a,"archive");await fsExtra.ensureDir(a),u.log(`Writing test results for "${s}"`);let w=new Map;await Promise.all(Object.entries(e).map(async([p,m])=>{if("error"in m)return;let y=new b(p,m,l),g=y.originalSrc(),$=y.toFileSystemPath();g!==$&&w.set(g,$),await fsExtra.outputFile(E.join(h,$),m.body);})),await Promise.all(await Object.entries(t).map(async([p,m])=>{let g=await new S(m).mapAssetPaths(w);await fsExtra.outputFile(E.join(h,`${x(s)}-${x(p)}.snapshot.json`),g);})),await W(E.join(a,`${x(s)}.stories.json`),s,t,r);let d=Object.entries(e).filter(([,p])=>"error"in p);d.length>0&&(u.log(`Encountered ${d.length} errors archiving resources, writing to 'errors.json'`),await fsExtra.outputJson(E.join(h,"errors.json"),{errors:Object.fromEntries(d)}));}o(A,"writeTestResult");async function W(i,t,e,r){u.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}}}))});}o(W,"writeStoriesFile");var N=class{constructor(t,e){c(this,"archive",{});c(this,"client");c(this,"allowedArchiveOrigins");c(this,"firstUrl");this.client=t,this.allowedArchiveOrigins=(e||[]).map(r=>`https://${r}`);}async watch(){this.client.on("Fetch.requestPaused",this.requestPaused.bind(this)),await this.client.send("Fetch.enable");}async clientSend(t,e,r){try{return await this.client.send(e,r)}catch(s){return u.log("Client error",t.url,s),this.archive[t.url]={error:s},null}}async requestPaused({requestId:t,request:e,responseStatusCode:r,responseStatusText:s,responseErrorReason:n,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 a=new URL(e.url);this.firstUrl??(this.firstUrl=a);let h=a.origin===this.firstUrl.origin||this.allowedArchiveOrigins.includes(a.origin);if(u.log("requestPaused",a.toString(),r||n?"response":"request",this.firstUrl.toString(),h),n){u.log(`Got response error: ${n}`),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:d,base64Encoded:p}=w,m=l.find(({name:g})=>g.toLowerCase()==="content-type"),y=a.toString()===this.firstUrl.toString();h&&!y&&(this.archive[e.url]={statusCode:r,statusText:s,body:Buffer.from(d,p?"base64":"utf8"),contentType:m?.value}),await this.clientSend(e,"Fetch.continueRequest",{requestId:t});return}await this.clientSend(e,"Fetch.continueRequest",{requestId:t,interceptResponse:!0});}};o(N,"Watcher");var J=o(async({testTitle:i,domSnapshots:t,resourceArchive:e,chromaticStorybookParams:r,pageUrl:s})=>{let n=Object.entries(e).map(([a,h])=>[a,{...h,body:Buffer.from(h.body,"utf8")}]),l=Object.fromEntries(t.map((a,h)=>[`Snapshot #${h+1}`,Buffer.from(JSON.stringify(a))]));await A({title:i,outputDir:"./cypress/downloads/some",pageUrl:s},l,Object.fromEntries(n),r);},"writeArchives"),v=null,C="",P=0,G=o(async()=>{try{let{webSocketDebuggerUrl:i}=await k.Version({host:C,port:P}),t=await k__default.default({target:i});v||(v=new N(t),await v.watch());}catch(i){console.log("err",i);}return null},"setupNetworkListener"),z=o(i=>new Promise(t=>J({...i,resourceArchive:v.archive}).then(()=>{t(null);})),"saveArchives"),Q=o(async({action:i,payload:t})=>{switch(i){case"setup-network-listener":return G();case"save-archives":return z(t);default:return null}},"prepareArchives"),V=o((i,t)=>{let e=t.args.find(n=>n.startsWith("--remote-debugging-address="));C=e?e.split("=")[1]:"127.0.0.1";let r=t.args.find(n=>n.startsWith("--remote-debugging-port=")),s="";return r?[,s]=r.split("="):[,s]=process.env.ELECTRON_EXTRA_LAUNCH_ARGS.split(" ").find(l=>l.startsWith("--remote-debugging-port")).split("="),P=parseInt(s,10),t},"onBeforeBrowserLaunch"),yt=o(i=>{i("task",{prepareArchives:Q}),i("before:browser:launch",V);},"installPlugin");
exports.onBeforeBrowserLaunch = wt;
exports.saveArchives = ft;
exports.setupNetworkListener = gt;
exports.installPlugin = yt;
exports.onBeforeBrowserLaunch = V;
exports.prepareArchives = Q;
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.js.map

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

Cypress.Commands.add("takeChromaticArchive",()=>{cy.document().then(t=>{let s=rrwebSnapshot.snapshot(t);cy.get("@manualSnapshots").then(a=>[...a,s]).as("manualSnapshots");});});beforeEach(()=>{cy.wrap([]).as("manualSnapshots"),cy.task("setupNetworkListener");});afterEach(()=>{cy.document().then(t=>{let s=rrwebSnapshot.snapshot(t);cy.get("@manualSnapshots").then((a=[])=>{cy.url().then(e=>{cy.task("saveArchives",{testTitle:Cypress.currentTest.title,domSnapshots:[...a,s],chromaticStorybookParams:{diffThreshold:Cypress.env("diffThreshold")},pageUrl:e});});});});});
Cypress.Commands.add("takeChromaticArchive",()=>{cy.document().then(a=>{let t=rrwebSnapshot.snapshot(a);cy.get("@manualSnapshots").then(s=>[...s,t]).as("manualSnapshots");});});beforeEach(()=>{cy.wrap([]).as("manualSnapshots"),cy.task("prepareArchives",{action:"setup-network-listener"});});afterEach(()=>{cy.document().then(a=>{let t=rrwebSnapshot.snapshot(a);cy.get("@manualSnapshots").then((s=[])=>{cy.url().then(e=>{cy.task("prepareArchives",{action:"save-archives",payload:{testTitle:Cypress.currentTest.title,domSnapshots:[...s,t],chromaticStorybookParams:{diffThreshold:Cypress.env("diffThreshold")},pageUrl:e}});});});});});
//# sourceMappingURL=out.js.map
//# sourceMappingURL=support.js.map

@@ -1,2 +0,1 @@

import { C as ChromaticConfig } from './types-2f6f869c.js';
import * as _playwright_test from '@playwright/test';

@@ -6,2 +5,14 @@ import { Page, TestInfo } from '@playwright/test';

interface ChromaticConfig {
delay?: number;
diffIncludeAntiAliasing?: boolean;
diffThreshold?: number;
disableAutoCapture?: boolean;
forcedColors?: string;
pauseAnimationAtEnd?: boolean;
prefersReducedMotion?: string;
resourceArchiveTimeout?: number;
allowedArchiveDomains?: string[];
}
declare function takeArchive(page: Page, testInfo: TestInfo): Promise<void>;

@@ -8,0 +19,0 @@ declare function takeArchive(page: Page, name: string, testInfo: TestInfo): Promise<void>;

{
"name": "@chromaui/test-archiver",
"version": "0.0.55",
"version": "0.0.56--canary.55.8655fbb.0",
"description": "Archive end-to-end tests to be replayed in Storybook and Chromatic",

@@ -5,0 +5,0 @@ "repository": {

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