@chromatic-com/cypress 0.10.1 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/support.js CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  var rrwebSnapshot = require('@chromaui/rrweb-snapshot');
4
4
 
5
- var m=Object.defineProperty;var a=(t,e)=>m(t,"name",{value:e,configurable:!0});var n=a((t,e)=>new Promise(r=>{!e&&Cypress.env("disableAutoSnapshot")&&r(null);let o=rrwebSnapshot.snapshot(t),d=a(async p=>{let c=await(await fetch(p)).blob();return new Promise((h,f)=>{let i=new FileReader;i.onloadend=()=>h(i.result),i.onerror=f,i.readAsDataURL(c);})},"toDataURL"),l=a(async p=>{await Promise.all(p.childNodes.map(async s=>{if(s.tagName==="img"&&s.attributes.src?.startsWith("blob:")){let c=await d(s.attributes.src);s.attributes.src=c;}s.childNodes?.length&&await l(s);}));},"replaceBlobUrls");l(o).then(()=>{r({snapshot:o});});}),"takeSnapshot");Cypress.Commands.add("takeSnapshot",t=>{Cypress.config("isTextTerminal")&&cy.document().then(e=>{cy.wrap(n(e,!0)).then(r=>{cy.get("@manualSnapshots").then(o=>[...o,{...r,name:t}]).as("manualSnapshots");});});});var y=a(t=>({...t("diffThreshold")&&{diffThreshold:t("diffThreshold")},...t("delay")&&{delay:t("delay")},...t("diffIncludeAntiAliasing")&&{diffIncludeAntiAliasing:t("diffIncludeAntiAliasing")},...t("diffThreshold")&&{diffThreshold:t("diffThreshold")},...t("forcedColors")&&{forcedColors:t("forcedColors")},...t("pauseAnimationAtEnd")&&{pauseAnimationAtEnd:t("pauseAnimationAtEnd")},...t("prefersReducedMotion")&&{prefersReducedMotion:t("prefersReducedMotion")},...t("cropToViewport")&&{cropToViewport:t("cropToViewport")},...t("ignoreSelectors")&&{ignoreSelectors:t("ignoreSelectors")}}),"buildChromaticParams");beforeEach(()=>{Cypress.config("isTextTerminal")&&(cy.wrap([]).as("manualSnapshots"),cy.task("prepareArchives",{action:"setup-network-listener",payload:{allowedDomains:Cypress.env("assetDomains")}}));});afterEach(()=>{Cypress.config("isTextTerminal")&&cy.document().then(t=>{cy.wrap(n(t)).then(e=>{cy.get("@manualSnapshots").then((r=[])=>{cy.url().then(o=>{cy.task("prepareArchives",{action:"save-archives",payload:{testTitlePath:[Cypress.spec.relativeToCommonRoot,...Cypress.currentTest.titlePath],domSnapshots:[...r,...e?[e]:[]],chromaticStorybookParams:y(Cypress.env),pageUrl:o,viewport:{height:Cypress.config("viewportHeight"),width:Cypress.config("viewportWidth")},outputDir:Cypress.config("downloadsFolder")}});});});});});});
5
+ var m=Object.defineProperty;var a=(e,t)=>m(e,"name",{value:t,configurable:!0});var n=a((e,t)=>new Promise(r=>{!t&&Cypress.env("disableAutoSnapshot")&&r(null);let o=rrwebSnapshot.snapshot(e,{recordCanvas:!0}),d=a(async p=>{let c=await(await fetch(p)).blob();return new Promise((h,f)=>{let i=new FileReader;i.onloadend=()=>h(i.result),i.onerror=f,i.readAsDataURL(c);})},"toDataURL"),l=a(async p=>{await Promise.all(p.childNodes.map(async s=>{if(s.tagName==="img"&&s.attributes.src?.startsWith("blob:")){let c=await d(s.attributes.src);s.attributes.src=c;}s.childNodes?.length&&await l(s);}));},"replaceBlobUrls");l(o).then(()=>{r({snapshot:o});});}),"takeSnapshot");Cypress.Commands.add("takeSnapshot",e=>{Cypress.config("isTextTerminal")&&cy.document().then(t=>{cy.wrap(n(t,!0)).then(r=>{cy.get("@manualSnapshots").then(o=>[...o,{...r,name:e}]).as("manualSnapshots");});});});var y=a(e=>({...e("diffThreshold")&&{diffThreshold:e("diffThreshold")},...e("delay")&&{delay:e("delay")},...e("diffIncludeAntiAliasing")&&{diffIncludeAntiAliasing:e("diffIncludeAntiAliasing")},...e("diffThreshold")&&{diffThreshold:e("diffThreshold")},...e("forcedColors")&&{forcedColors:e("forcedColors")},...e("pauseAnimationAtEnd")&&{pauseAnimationAtEnd:e("pauseAnimationAtEnd")},...e("prefersReducedMotion")&&{prefersReducedMotion:e("prefersReducedMotion")},...e("cropToViewport")&&{cropToViewport:e("cropToViewport")},...e("ignoreSelectors")&&{ignoreSelectors:e("ignoreSelectors")}}),"buildChromaticParams");beforeEach(()=>{Cypress.config("isTextTerminal")&&(cy.wrap([]).as("manualSnapshots"),cy.task("prepareArchives",{action:"setup-network-listener",payload:{allowedDomains:Cypress.env("assetDomains")}}));});afterEach(()=>{Cypress.config("isTextTerminal")&&cy.document().then(e=>{cy.wrap(n(e)).then(t=>{cy.get("@manualSnapshots").then((r=[])=>{cy.url().then(o=>{cy.task("prepareArchives",{action:"save-archives",payload:{testTitlePath:[Cypress.spec.relativeToCommonRoot,...Cypress.currentTest.titlePath],domSnapshots:[...r,...t?[t]:[]],chromaticStorybookParams:y(Cypress.env),pageUrl:o,viewport:{height:Cypress.config("viewportHeight"),width:Cypress.config("viewportWidth")},outputDir:Cypress.config("downloadsFolder")}});});});});});});
6
6
  //# sourceMappingURL=out.js.map
7
7
  //# sourceMappingURL=support.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/takeSnapshot.ts","../src/commands.ts","../src/support.ts"],"names":["snapshot","takeSnapshot","__name","doc","isManualSnapshot","Promise","resolve","Cypress","env","domSnapshot","toDataURL","url","blob","fetch","resolveFileRead","reject","reader","FileReader","onloadend","result","onerror","readAsDataURL","replaceBlobUrls","node","all","childNodes","map","childNode","tagName","attributes","src","startsWith","base64Url","length","then","Commands","add","name","config","cy","document","wrap","takeChromaticSnapshot","manualSnapshot","get","snapshots","as","buildChromaticParams","diffThreshold","delay","diffIncludeAntiAliasing","forcedColors","pauseAnimationAtEnd","prefersReducedMotion","cropToViewport","ignoreSelectors","beforeEach","task","action","payload","allowedDomains","afterEach","automaticSnapshot","manualSnapshots","testTitlePath","spec","relativeToCommonRoot","currentTest","titlePath","domSnapshots","chromaticStorybookParams","pageUrl","viewport","height","width","outputDir"],"mappings":"+EAAA,OAA+BA,YAAAA,MAAgB,2BAGxC,IAAMC,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B,GAAAA,CAEb4B,GAAGkB,KAAK,kBAAmB,CACzBC,OAAQ,gBACRC,QAAS,CAEPK,cAAe,CAACzD,QAAQ0D,KAAKC,wBAAyB3D,QAAQ4D,YAAYC,WAC1EC,aAAc,IAAIN,KAAqBD,EAAoB,CAACA,GAAqB,CAAA,GACjFQ,yBAA0BvB,EAAqBxC,QAAQC,GAAG,EAC1D+D,QAAS5D,EACT6D,SAAU,CACRC,OAAQlE,QAAQ+B,OAAO,gBAAA,EACvBoC,MAAOnE,QAAQ+B,OAAO,eAAA,CACxB,EACAqC,UAAWpE,QAAQ+B,OAAO,iBAAA,CAC5B,CACF,CAAA,CACF,CAAA,CACF,CAAA,CACF,CAAA,CACF,CAAA,CACF,CAAA","sourcesContent":["import { serializedNodeWithId, snapshot } from '@chromaui/rrweb-snapshot';\nimport { CypressSnapshot } from './types';\n\nexport const takeSnapshot = (\n doc: Document,\n isManualSnapshot?: boolean\n): Promise<CypressSnapshot | null> => {\n return new Promise((resolve) => {\n if (!isManualSnapshot && Cypress.env('disableAutoSnapshot')) {\n resolve(null);\n }\n\n const domSnapshot = snapshot(doc);\n // do some post-processing on the snapshot\n const toDataURL = async (url: string) => {\n // read contents of the blob URL\n const response = await fetch(url);\n const blob = await response.blob();\n return new Promise((resolveFileRead, reject) => {\n const reader = new FileReader();\n reader.onloadend = () => resolveFileRead(reader.result);\n reader.onerror = reject;\n // convert the blob to base64 string\n reader.readAsDataURL(blob);\n });\n };\n\n const replaceBlobUrls = async (node: serializedNodeWithId) => {\n await Promise.all(\n // @ts-expect-error we assume childNodes will be on there\n node.childNodes.map(async (childNode) => {\n if (childNode.tagName === 'img' && childNode.attributes.src?.startsWith('blob:')) {\n const base64Url = await toDataURL(childNode.attributes.src);\n // eslint-disable-next-line no-param-reassign\n childNode.attributes.src = base64Url;\n }\n\n if (childNode.childNodes?.length) {\n await replaceBlobUrls(childNode);\n }\n })\n );\n };\n\n replaceBlobUrls(domSnapshot).then(() => {\n resolve({ snapshot: domSnapshot });\n });\n });\n};\n","import { takeSnapshot as takeChromaticSnapshot } from './takeSnapshot';\nimport { CypressSnapshot } from './types';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace Cypress {\n interface Chainable {\n /**\n * Method for taking a manual snapshot with Chromatic\n *\n *\n * @param {string} name - Use to apply a custom name to the snapshot (optional)\n */\n takeSnapshot(name?: string): Chainable<any>;\n }\n }\n}\n\nCypress.Commands.add('takeSnapshot', (name?: string) => {\n // don't take snapshots when running `cypress open`\n if (!Cypress.config('isTextTerminal')) {\n return;\n }\n\n cy.document().then((doc) => {\n // here, handle the source map\n\n cy.wrap(takeChromaticSnapshot(doc, true)).then((manualSnapshot: CypressSnapshot) => {\n // reassign manualSnapshots so it includes this new snapshot\n cy.get('@manualSnapshots')\n // @ts-expect-error will fix when Cypress has its own package\n .then((snapshots: CypressSnapshot[]) => {\n return [...snapshots, { ...manualSnapshot, name }];\n })\n .as('manualSnapshots');\n });\n });\n});\n","import './commands';\nimport { takeSnapshot } from './takeSnapshot';\nimport { CypressSnapshot } from './types';\n\nconst buildChromaticParams = (env: Cypress.Cypress['env']) => ({\n ...(env('diffThreshold') && {\n diffThreshold: env('diffThreshold'),\n }),\n ...(env('delay') && { delay: env('delay') }),\n ...(env('diffIncludeAntiAliasing') && {\n diffIncludeAntiAliasing: env('diffIncludeAntiAliasing'),\n }),\n ...(env('diffThreshold') && {\n diffThreshold: env('diffThreshold'),\n }),\n ...(env('forcedColors') && { forcedColors: env('forcedColors') }),\n ...(env('pauseAnimationAtEnd') && {\n pauseAnimationAtEnd: env('pauseAnimationAtEnd'),\n }),\n ...(env('prefersReducedMotion') && {\n prefersReducedMotion: env('prefersReducedMotion'),\n }),\n ...(env('cropToViewport') && {\n cropToViewport: env('cropToViewport'),\n }),\n ...(env('ignoreSelectors') && {\n ignoreSelectors: env('ignoreSelectors'),\n }),\n});\n\n// these client-side lifecycle hooks will be added to the user's Cypress suite\nbeforeEach(() => {\n // don't take snapshots when running `cypress open`\n if (!Cypress.config('isTextTerminal')) {\n return;\n }\n // this \"manualSnapshots\" variable will be available before, during, and after the test,\n // then cleaned up before the next test is run\n // (see https://docs.cypress.io/guides/core-concepts/variables-and-aliases#Aliases)\n cy.wrap([]).as('manualSnapshots');\n cy.task('prepareArchives', {\n action: 'setup-network-listener',\n payload: { allowedDomains: Cypress.env('assetDomains') },\n });\n});\n\nafterEach(() => {\n // don't take snapshots when running `cypress open`\n if (!Cypress.config('isTextTerminal')) {\n return;\n }\n // can we be sure this always fires after all the requests are back?\n cy.document().then((doc) => {\n cy.wrap(takeSnapshot(doc)).then((automaticSnapshot: CypressSnapshot) => {\n // @ts-expect-error will fix when Cypress has its own package\n cy.get('@manualSnapshots').then((manualSnapshots = []) => {\n cy.url().then((url) => {\n // pass the snapshot to the server to write to disk\n cy.task('prepareArchives', {\n action: 'save-archives',\n payload: {\n // @ts-expect-error relativeToCommonRoot is on spec (but undocumented)\n testTitlePath: [Cypress.spec.relativeToCommonRoot, ...Cypress.currentTest.titlePath],\n domSnapshots: [...manualSnapshots, ...(automaticSnapshot ? [automaticSnapshot] : [])],\n chromaticStorybookParams: buildChromaticParams(Cypress.env),\n pageUrl: url,\n viewport: {\n height: Cypress.config('viewportHeight'),\n width: Cypress.config('viewportWidth'),\n },\n outputDir: Cypress.config('downloadsFolder'),\n },\n });\n });\n });\n });\n });\n});\n"]}
1
+ {"version":3,"sources":["../src/takeSnapshot.ts","../src/commands.ts","../src/support.ts"],"names":["snapshot","takeSnapshot","__name","doc","isManualSnapshot","Promise","resolve","Cypress","env","domSnapshot","recordCanvas","toDataURL","url","blob","fetch","resolveFileRead","reject","reader","FileReader","onloadend","result","onerror","readAsDataURL","replaceBlobUrls","node","all","childNodes","map","childNode","tagName","attributes","src","startsWith","base64Url","length","then","Commands","add","name","config","cy","document","wrap","takeChromaticSnapshot","manualSnapshot","get","snapshots","as","buildChromaticParams","diffThreshold","delay","diffIncludeAntiAliasing","forcedColors","pauseAnimationAtEnd","prefersReducedMotion","cropToViewport","ignoreSelectors","beforeEach","task","action","payload","allowedDomains","afterEach","automaticSnapshot","manualSnapshots","testTitlePath","spec","relativeToCommonRoot","currentTest","titlePath","domSnapshots","chromaticStorybookParams","pageUrl","viewport","height","width","outputDir"],"mappings":"+EAAA,OAA+BA,YAAAA,MAAgB,2BAGxC,IAAMC,EAAeC,EAAA,CAC1BC,EACAC,IAEO,IAAIC,QAASC,GAAAA,CACd,CAACF,GAAoBG,QAAQC,IAAI,qBAAA,GACnCF,EAAQ,IAAA,EAGV,IAAMG,EAAcT,EAASG,EAAK,CAAEO,aAAc,EAAK,CAAA,EAEjDC,EAAYT,EAAA,MAAOU,GAAAA,CAGvB,IAAMC,EAAO,MADI,MAAMC,MAAMF,CAAAA,GACDC,KAAI,EAChC,OAAO,IAAIR,QAAQ,CAACU,EAAiBC,IAAAA,CACnC,IAAMC,EAAS,IAAIC,WACnBD,EAAOE,UAAY,IAAMJ,EAAgBE,EAAOG,MAAM,EACtDH,EAAOI,QAAUL,EAEjBC,EAAOK,cAAcT,CAAAA,CACvB,CAAA,CACF,EAXkB,aAaZU,EAAkBrB,EAAA,MAAOsB,GAAAA,CAC7B,MAAMnB,QAAQoB,IAEZD,EAAKE,WAAWC,IAAI,MAAOC,GAAAA,CACzB,GAAIA,EAAUC,UAAY,OAASD,EAAUE,WAAWC,KAAKC,WAAW,OAAA,EAAU,CAChF,IAAMC,EAAY,MAAMtB,EAAUiB,EAAUE,WAAWC,GAAG,EAE1DH,EAAUE,WAAWC,IAAME,CAC7B,CAEIL,EAAUF,YAAYQ,QACxB,MAAMX,EAAgBK,CAAAA,CAE1B,CAAA,CAAA,CAEJ,EAfwB,mBAiBxBL,EAAgBd,CAAAA,EAAa0B,KAAK,IAAA,CAChC7B,EAAQ,CAAEN,SAAUS,CAAY,CAAA,CAClC,CAAA,CACF,CAAA,EA5C0B,gBCe5BF,QAAQ6B,SAASC,IAAI,eAAiBC,GAAAA,CAE/B/B,QAAQgC,OAAO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C,OAAO,gBAAA,GAIpBC,GAAGC,SAAQ,EAAGN,KAAMhC,GAAAA,CAClBqC,GAAGE,KAAKzC,EAAaE,CAAAA,CAAAA,EAAMgC,KAAM4B,GAAAA,CAE/BvB,GAAGK,IAAI,kBAAA,EAAoBV,KAAK,CAAC6B,EAAkB,CAAA,IAAE,CACnDxB,GAAG5B,IAAG,EAAGuB,KAAMvB,GAAAA,CAEb4B,GAAGkB,KAAK,kBAAmB,CACzBC,OAAQ,gBACRC,QAAS,CAEPK,cAAe,CAAC1D,QAAQ2D,KAAKC,wBAAyB5D,QAAQ6D,YAAYC,WAC1EC,aAAc,IAAIN,KAAqBD,EAAoB,CAACA,GAAqB,CAAA,GACjFQ,yBAA0BvB,EAAqBzC,QAAQC,GAAG,EAC1DgE,QAAS5D,EACT6D,SAAU,CACRC,OAAQnE,QAAQgC,OAAO,gBAAA,EACvBoC,MAAOpE,QAAQgC,OAAO,eAAA,CACxB,EACAqC,UAAWrE,QAAQgC,OAAO,iBAAA,CAC5B,CACF,CAAA,CACF,CAAA,CACF,CAAA,CACF,CAAA,CACF,CAAA,CACF,CAAA","sourcesContent":["import { serializedNodeWithId, snapshot } from '@chromaui/rrweb-snapshot';\nimport { CypressSnapshot } from './types';\n\nexport const takeSnapshot = (\n doc: Document,\n isManualSnapshot?: boolean\n): Promise<CypressSnapshot | null> => {\n return new Promise((resolve) => {\n if (!isManualSnapshot && Cypress.env('disableAutoSnapshot')) {\n resolve(null);\n }\n\n const domSnapshot = snapshot(doc, { recordCanvas: true });\n // do some post-processing on the snapshot\n const toDataURL = async (url: string) => {\n // read contents of the blob URL\n const response = await fetch(url);\n const blob = await response.blob();\n return new Promise((resolveFileRead, reject) => {\n const reader = new FileReader();\n reader.onloadend = () => resolveFileRead(reader.result);\n reader.onerror = reject;\n // convert the blob to base64 string\n reader.readAsDataURL(blob);\n });\n };\n\n const replaceBlobUrls = async (node: serializedNodeWithId) => {\n await Promise.all(\n // @ts-expect-error we assume childNodes will be on there\n node.childNodes.map(async (childNode) => {\n if (childNode.tagName === 'img' && childNode.attributes.src?.startsWith('blob:')) {\n const base64Url = await toDataURL(childNode.attributes.src);\n // eslint-disable-next-line no-param-reassign\n childNode.attributes.src = base64Url;\n }\n\n if (childNode.childNodes?.length) {\n await replaceBlobUrls(childNode);\n }\n })\n );\n };\n\n replaceBlobUrls(domSnapshot).then(() => {\n resolve({ snapshot: domSnapshot });\n });\n });\n};\n","import { takeSnapshot as takeChromaticSnapshot } from './takeSnapshot';\nimport { CypressSnapshot } from './types';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace Cypress {\n interface Chainable {\n /**\n * Method for taking a manual snapshot with Chromatic\n *\n *\n * @param {string} name - Use to apply a custom name to the snapshot (optional)\n */\n takeSnapshot(name?: string): Chainable<any>;\n }\n }\n}\n\nCypress.Commands.add('takeSnapshot', (name?: string) => {\n // don't take snapshots when running `cypress open`\n if (!Cypress.config('isTextTerminal')) {\n return;\n }\n\n cy.document().then((doc) => {\n // here, handle the source map\n\n cy.wrap(takeChromaticSnapshot(doc, true)).then((manualSnapshot: CypressSnapshot) => {\n // reassign manualSnapshots so it includes this new snapshot\n cy.get('@manualSnapshots')\n // @ts-expect-error will fix when Cypress has its own package\n .then((snapshots: CypressSnapshot[]) => {\n return [...snapshots, { ...manualSnapshot, name }];\n })\n .as('manualSnapshots');\n });\n });\n});\n","import './commands';\nimport { takeSnapshot } from './takeSnapshot';\nimport { CypressSnapshot } from './types';\n\nconst buildChromaticParams = (env: Cypress.Cypress['env']) => ({\n ...(env('diffThreshold') && {\n diffThreshold: env('diffThreshold'),\n }),\n ...(env('delay') && { delay: env('delay') }),\n ...(env('diffIncludeAntiAliasing') && {\n diffIncludeAntiAliasing: env('diffIncludeAntiAliasing'),\n }),\n ...(env('diffThreshold') && {\n diffThreshold: env('diffThreshold'),\n }),\n ...(env('forcedColors') && { forcedColors: env('forcedColors') }),\n ...(env('pauseAnimationAtEnd') && {\n pauseAnimationAtEnd: env('pauseAnimationAtEnd'),\n }),\n ...(env('prefersReducedMotion') && {\n prefersReducedMotion: env('prefersReducedMotion'),\n }),\n ...(env('cropToViewport') && {\n cropToViewport: env('cropToViewport'),\n }),\n ...(env('ignoreSelectors') && {\n ignoreSelectors: env('ignoreSelectors'),\n }),\n});\n\n// these client-side lifecycle hooks will be added to the user's Cypress suite\nbeforeEach(() => {\n // don't take snapshots when running `cypress open`\n if (!Cypress.config('isTextTerminal')) {\n return;\n }\n // this \"manualSnapshots\" variable will be available before, during, and after the test,\n // then cleaned up before the next test is run\n // (see https://docs.cypress.io/guides/core-concepts/variables-and-aliases#Aliases)\n cy.wrap([]).as('manualSnapshots');\n cy.task('prepareArchives', {\n action: 'setup-network-listener',\n payload: { allowedDomains: Cypress.env('assetDomains') },\n });\n});\n\nafterEach(() => {\n // don't take snapshots when running `cypress open`\n if (!Cypress.config('isTextTerminal')) {\n return;\n }\n // can we be sure this always fires after all the requests are back?\n cy.document().then((doc) => {\n cy.wrap(takeSnapshot(doc)).then((automaticSnapshot: CypressSnapshot) => {\n // @ts-expect-error will fix when Cypress has its own package\n cy.get('@manualSnapshots').then((manualSnapshots = []) => {\n cy.url().then((url) => {\n // pass the snapshot to the server to write to disk\n cy.task('prepareArchives', {\n action: 'save-archives',\n payload: {\n // @ts-expect-error relativeToCommonRoot is on spec (but undocumented)\n testTitlePath: [Cypress.spec.relativeToCommonRoot, ...Cypress.currentTest.titlePath],\n domSnapshots: [...manualSnapshots, ...(automaticSnapshot ? [automaticSnapshot] : [])],\n chromaticStorybookParams: buildChromaticParams(Cypress.env),\n pageUrl: url,\n viewport: {\n height: Cypress.config('viewportHeight'),\n width: Cypress.config('viewportWidth'),\n },\n outputDir: Cypress.config('downloadsFolder'),\n },\n });\n });\n });\n });\n });\n});\n"]}
package/dist/support.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { snapshot } from '@chromaui/rrweb-snapshot';
2
2
 
3
- var m=Object.defineProperty;var a=(t,e)=>m(t,"name",{value:e,configurable:!0});var n=a((t,e)=>new Promise(r=>{!e&&Cypress.env("disableAutoSnapshot")&&r(null);let o=snapshot(t),d=a(async p=>{let c=await(await fetch(p)).blob();return new Promise((h,f)=>{let i=new FileReader;i.onloadend=()=>h(i.result),i.onerror=f,i.readAsDataURL(c);})},"toDataURL"),l=a(async p=>{await Promise.all(p.childNodes.map(async s=>{if(s.tagName==="img"&&s.attributes.src?.startsWith("blob:")){let c=await d(s.attributes.src);s.attributes.src=c;}s.childNodes?.length&&await l(s);}));},"replaceBlobUrls");l(o).then(()=>{r({snapshot:o});});}),"takeSnapshot");Cypress.Commands.add("takeSnapshot",t=>{Cypress.config("isTextTerminal")&&cy.document().then(e=>{cy.wrap(n(e,!0)).then(r=>{cy.get("@manualSnapshots").then(o=>[...o,{...r,name:t}]).as("manualSnapshots");});});});var y=a(t=>({...t("diffThreshold")&&{diffThreshold:t("diffThreshold")},...t("delay")&&{delay:t("delay")},...t("diffIncludeAntiAliasing")&&{diffIncludeAntiAliasing:t("diffIncludeAntiAliasing")},...t("diffThreshold")&&{diffThreshold:t("diffThreshold")},...t("forcedColors")&&{forcedColors:t("forcedColors")},...t("pauseAnimationAtEnd")&&{pauseAnimationAtEnd:t("pauseAnimationAtEnd")},...t("prefersReducedMotion")&&{prefersReducedMotion:t("prefersReducedMotion")},...t("cropToViewport")&&{cropToViewport:t("cropToViewport")},...t("ignoreSelectors")&&{ignoreSelectors:t("ignoreSelectors")}}),"buildChromaticParams");beforeEach(()=>{Cypress.config("isTextTerminal")&&(cy.wrap([]).as("manualSnapshots"),cy.task("prepareArchives",{action:"setup-network-listener",payload:{allowedDomains:Cypress.env("assetDomains")}}));});afterEach(()=>{Cypress.config("isTextTerminal")&&cy.document().then(t=>{cy.wrap(n(t)).then(e=>{cy.get("@manualSnapshots").then((r=[])=>{cy.url().then(o=>{cy.task("prepareArchives",{action:"save-archives",payload:{testTitlePath:[Cypress.spec.relativeToCommonRoot,...Cypress.currentTest.titlePath],domSnapshots:[...r,...e?[e]:[]],chromaticStorybookParams:y(Cypress.env),pageUrl:o,viewport:{height:Cypress.config("viewportHeight"),width:Cypress.config("viewportWidth")},outputDir:Cypress.config("downloadsFolder")}});});});});});});
3
+ var m=Object.defineProperty;var a=(e,t)=>m(e,"name",{value:t,configurable:!0});var n=a((e,t)=>new Promise(r=>{!t&&Cypress.env("disableAutoSnapshot")&&r(null);let o=snapshot(e,{recordCanvas:!0}),d=a(async p=>{let c=await(await fetch(p)).blob();return new Promise((h,f)=>{let i=new FileReader;i.onloadend=()=>h(i.result),i.onerror=f,i.readAsDataURL(c);})},"toDataURL"),l=a(async p=>{await Promise.all(p.childNodes.map(async s=>{if(s.tagName==="img"&&s.attributes.src?.startsWith("blob:")){let c=await d(s.attributes.src);s.attributes.src=c;}s.childNodes?.length&&await l(s);}));},"replaceBlobUrls");l(o).then(()=>{r({snapshot:o});});}),"takeSnapshot");Cypress.Commands.add("takeSnapshot",e=>{Cypress.config("isTextTerminal")&&cy.document().then(t=>{cy.wrap(n(t,!0)).then(r=>{cy.get("@manualSnapshots").then(o=>[...o,{...r,name:e}]).as("manualSnapshots");});});});var y=a(e=>({...e("diffThreshold")&&{diffThreshold:e("diffThreshold")},...e("delay")&&{delay:e("delay")},...e("diffIncludeAntiAliasing")&&{diffIncludeAntiAliasing:e("diffIncludeAntiAliasing")},...e("diffThreshold")&&{diffThreshold:e("diffThreshold")},...e("forcedColors")&&{forcedColors:e("forcedColors")},...e("pauseAnimationAtEnd")&&{pauseAnimationAtEnd:e("pauseAnimationAtEnd")},...e("prefersReducedMotion")&&{prefersReducedMotion:e("prefersReducedMotion")},...e("cropToViewport")&&{cropToViewport:e("cropToViewport")},...e("ignoreSelectors")&&{ignoreSelectors:e("ignoreSelectors")}}),"buildChromaticParams");beforeEach(()=>{Cypress.config("isTextTerminal")&&(cy.wrap([]).as("manualSnapshots"),cy.task("prepareArchives",{action:"setup-network-listener",payload:{allowedDomains:Cypress.env("assetDomains")}}));});afterEach(()=>{Cypress.config("isTextTerminal")&&cy.document().then(e=>{cy.wrap(n(e)).then(t=>{cy.get("@manualSnapshots").then((r=[])=>{cy.url().then(o=>{cy.task("prepareArchives",{action:"save-archives",payload:{testTitlePath:[Cypress.spec.relativeToCommonRoot,...Cypress.currentTest.titlePath],domSnapshots:[...r,...t?[t]:[]],chromaticStorybookParams:y(Cypress.env),pageUrl:o,viewport:{height:Cypress.config("viewportHeight"),width:Cypress.config("viewportWidth")},outputDir:Cypress.config("downloadsFolder")}});});});});});});
4
4
  //# sourceMappingURL=out.js.map
5
5
  //# sourceMappingURL=support.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/takeSnapshot.ts","../src/commands.ts","../src/support.ts"],"names":["snapshot","takeSnapshot","__name","doc","isManualSnapshot","Promise","resolve","Cypress","env","domSnapshot","toDataURL","url","blob","fetch","resolveFileRead","reject","reader","FileReader","onloadend","result","onerror","readAsDataURL","replaceBlobUrls","node","all","childNodes","map","childNode","tagName","attributes","src","startsWith","base64Url","length","then","Commands","add","name","config","cy","document","wrap","takeChromaticSnapshot","manualSnapshot","get","snapshots","as","buildChromaticParams","diffThreshold","delay","diffIncludeAntiAliasing","forcedColors","pauseAnimationAtEnd","prefersReducedMotion","cropToViewport","ignoreSelectors","beforeEach","task","action","payload","allowedDomains","afterEach","automaticSnapshot","manualSnapshots","testTitlePath","spec","relativeToCommonRoot","currentTest","titlePath","domSnapshots","chromaticStorybookParams","pageUrl","viewport","height","width","outputDir"],"mappings":"+EAAA,OAA+BA,YAAAA,MAAgB,2BAGxC,IAAMC,EAAeC,EAAA,CAC1BC,EACAC,IAEO,IAAIC,QAASC,GAAAA,CACd,CAACF,GAAoBG,QAAQC,IAAI,qBAAA,GACnCF,EAAQ,IAAA,EAGV,IAAMG,EAAcT,EAASG,CAAAA,EAEvBO,EAAYR,EAAA,MAAOS,GAAAA,CAGvB,IAAMC,EAAO,MADI,MAAMC,MAAMF,CAAAA,GACDC,KAAI,EAChC,OAAO,IAAIP,QAAQ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C,OAAQlE,QAAQ+B,OAAO,gBAAA,EACvBoC,MAAOnE,QAAQ+B,OAAO,eAAA,CACxB,EACAqC,UAAWpE,QAAQ+B,OAAO,iBAAA,CAC5B,CACF,CAAA,CACF,CAAA,CACF,CAAA,CACF,CAAA,CACF,CAAA,CACF,CAAA","sourcesContent":["import { serializedNodeWithId, snapshot } from '@chromaui/rrweb-snapshot';\nimport { CypressSnapshot } from './types';\n\nexport const takeSnapshot = (\n doc: Document,\n isManualSnapshot?: boolean\n): Promise<CypressSnapshot | null> => {\n return new Promise((resolve) => {\n if (!isManualSnapshot && Cypress.env('disableAutoSnapshot')) {\n resolve(null);\n }\n\n const domSnapshot = snapshot(doc);\n // do some post-processing on the snapshot\n const toDataURL = async (url: string) => {\n // read contents of the blob URL\n const response = await fetch(url);\n const blob = await response.blob();\n return new Promise((resolveFileRead, reject) => {\n const reader = new FileReader();\n reader.onloadend = () => resolveFileRead(reader.result);\n reader.onerror = reject;\n // convert the blob to base64 string\n reader.readAsDataURL(blob);\n });\n };\n\n const replaceBlobUrls = async (node: serializedNodeWithId) => {\n await Promise.all(\n // @ts-expect-error we assume childNodes will be on there\n node.childNodes.map(async (childNode) => {\n if (childNode.tagName === 'img' && childNode.attributes.src?.startsWith('blob:')) {\n const base64Url = await toDataURL(childNode.attributes.src);\n // eslint-disable-next-line no-param-reassign\n childNode.attributes.src = base64Url;\n }\n\n if (childNode.childNodes?.length) {\n await replaceBlobUrls(childNode);\n }\n })\n );\n };\n\n replaceBlobUrls(domSnapshot).then(() => {\n resolve({ snapshot: domSnapshot });\n });\n });\n};\n","import { takeSnapshot as takeChromaticSnapshot } from './takeSnapshot';\nimport { CypressSnapshot } from './types';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace Cypress {\n interface Chainable {\n /**\n * Method for taking a manual snapshot with Chromatic\n *\n *\n * @param {string} name - Use to apply a custom name to the snapshot (optional)\n */\n takeSnapshot(name?: string): Chainable<any>;\n }\n }\n}\n\nCypress.Commands.add('takeSnapshot', (name?: string) => {\n // don't take snapshots when running `cypress open`\n if (!Cypress.config('isTextTerminal')) {\n return;\n }\n\n cy.document().then((doc) => {\n // here, handle the source map\n\n cy.wrap(takeChromaticSnapshot(doc, true)).then((manualSnapshot: CypressSnapshot) => {\n // reassign manualSnapshots so it includes this new snapshot\n cy.get('@manualSnapshots')\n // @ts-expect-error will fix when Cypress has its own package\n .then((snapshots: CypressSnapshot[]) => {\n return [...snapshots, { ...manualSnapshot, name }];\n })\n .as('manualSnapshots');\n });\n });\n});\n","import './commands';\nimport { takeSnapshot } from './takeSnapshot';\nimport { CypressSnapshot } from './types';\n\nconst buildChromaticParams = (env: Cypress.Cypress['env']) => ({\n ...(env('diffThreshold') && {\n diffThreshold: env('diffThreshold'),\n }),\n ...(env('delay') && { delay: env('delay') }),\n ...(env('diffIncludeAntiAliasing') && {\n diffIncludeAntiAliasing: env('diffIncludeAntiAliasing'),\n }),\n ...(env('diffThreshold') && {\n diffThreshold: env('diffThreshold'),\n }),\n ...(env('forcedColors') && { forcedColors: env('forcedColors') }),\n ...(env('pauseAnimationAtEnd') && {\n pauseAnimationAtEnd: env('pauseAnimationAtEnd'),\n }),\n ...(env('prefersReducedMotion') && {\n prefersReducedMotion: env('prefersReducedMotion'),\n }),\n ...(env('cropToViewport') && {\n cropToViewport: env('cropToViewport'),\n }),\n ...(env('ignoreSelectors') && {\n ignoreSelectors: env('ignoreSelectors'),\n }),\n});\n\n// these client-side lifecycle hooks will be added to the user's Cypress suite\nbeforeEach(() => {\n // don't take snapshots when running `cypress open`\n if (!Cypress.config('isTextTerminal')) {\n return;\n }\n // this \"manualSnapshots\" variable will be available before, during, and after the test,\n // then cleaned up before the next test is run\n // (see https://docs.cypress.io/guides/core-concepts/variables-and-aliases#Aliases)\n cy.wrap([]).as('manualSnapshots');\n cy.task('prepareArchives', {\n action: 'setup-network-listener',\n payload: { allowedDomains: Cypress.env('assetDomains') },\n });\n});\n\nafterEach(() => {\n // don't take snapshots when running `cypress open`\n if (!Cypress.config('isTextTerminal')) {\n return;\n }\n // can we be sure this always fires after all the requests are back?\n cy.document().then((doc) => {\n cy.wrap(takeSnapshot(doc)).then((automaticSnapshot: CypressSnapshot) => {\n // @ts-expect-error will fix when Cypress has its own package\n cy.get('@manualSnapshots').then((manualSnapshots = []) => {\n cy.url().then((url) => {\n // pass the snapshot to the server to write to disk\n cy.task('prepareArchives', {\n action: 'save-archives',\n payload: {\n // @ts-expect-error relativeToCommonRoot is on spec (but undocumented)\n testTitlePath: [Cypress.spec.relativeToCommonRoot, ...Cypress.currentTest.titlePath],\n domSnapshots: [...manualSnapshots, ...(automaticSnapshot ? [automaticSnapshot] : [])],\n chromaticStorybookParams: buildChromaticParams(Cypress.env),\n pageUrl: url,\n viewport: {\n height: Cypress.config('viewportHeight'),\n width: Cypress.config('viewportWidth'),\n },\n outputDir: Cypress.config('downloadsFolder'),\n },\n });\n });\n });\n });\n });\n});\n"]}
1
+ {"version":3,"sources":["../src/takeSnapshot.ts","../src/commands.ts","../src/support.ts"],"names":["snapshot","takeSnapshot","__name","doc","isManualSnapshot","Promise","resolve","Cypress","env","domSnapshot","recordCanvas","toDataURL","url","blob","fetch","resolveFileRead","reject","reader","FileReader","onloadend","result","onerror","readAsDataURL","replaceBlobUrls","node","all","childNodes","map","childNode","tagName","attributes","src","startsWith","base64Url","length","then","Commands","add","name","config","cy","document","wrap","takeChromaticSnapshot","manualSnapshot","get","snapshots","as","buildChromaticParams","diffThreshold","delay","diffIncludeAntiAliasing","forcedColors","pauseAnimationAtEnd","prefersReducedMotion","cropToViewport","ignoreSelectors","beforeEach","task","action","payload","allowedDomains","afterEach","automaticSnapshot","manualSnapshots","testTitlePath","spec","relativeToCommonRoot","currentTest","titlePath","domSnapshots","chromaticStorybookParams","pageUrl","viewport","height","width","outputDir"],"mappings":"+EAAA,OAA+BA,YAAAA,MAAgB,2BAGxC,IAAMC,EAAeC,EAAA,CAC1BC,EACAC,IAEO,IAAIC,QAASC,G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KAAK,kBAAmB,CACzBC,OAAQ,gBACRC,QAAS,CAEPK,cAAe,CAAC1D,QAAQ2D,KAAKC,wBAAyB5D,QAAQ6D,YAAYC,WAC1EC,aAAc,IAAIN,KAAqBD,EAAoB,CAACA,GAAqB,CAAA,GACjFQ,yBAA0BvB,EAAqBzC,QAAQC,GAAG,EAC1DgE,QAAS5D,EACT6D,SAAU,CACRC,OAAQnE,QAAQgC,OAAO,gBAAA,EACvBoC,MAAOpE,QAAQgC,OAAO,eAAA,CACxB,EACAqC,UAAWrE,QAAQgC,OAAO,iBAAA,CAC5B,CACF,CAAA,CACF,CAAA,CACF,CAAA,CACF,CAAA,CACF,CAAA,CACF,CAAA","sourcesContent":["import { serializedNodeWithId, snapshot } from '@chromaui/rrweb-snapshot';\nimport { CypressSnapshot } from './types';\n\nexport const takeSnapshot = (\n doc: Document,\n isManualSnapshot?: boolean\n): Promise<CypressSnapshot | null> => {\n return new Promise((resolve) => {\n if (!isManualSnapshot && Cypress.env('disableAutoSnapshot')) {\n resolve(null);\n }\n\n const domSnapshot = snapshot(doc, { recordCanvas: true });\n // do some post-processing on the snapshot\n const toDataURL = async (url: string) => {\n // read contents of the blob URL\n const response = await fetch(url);\n const blob = await response.blob();\n return new Promise((resolveFileRead, reject) => {\n const reader = new FileReader();\n reader.onloadend = () => resolveFileRead(reader.result);\n reader.onerror = reject;\n // convert the blob to base64 string\n reader.readAsDataURL(blob);\n });\n };\n\n const replaceBlobUrls = async (node: serializedNodeWithId) => {\n await Promise.all(\n // @ts-expect-error we assume childNodes will be on there\n node.childNodes.map(async (childNode) => {\n if (childNode.tagName === 'img' && childNode.attributes.src?.startsWith('blob:')) {\n const base64Url = await toDataURL(childNode.attributes.src);\n // eslint-disable-next-line no-param-reassign\n childNode.attributes.src = base64Url;\n }\n\n if (childNode.childNodes?.length) {\n await replaceBlobUrls(childNode);\n }\n })\n );\n };\n\n replaceBlobUrls(domSnapshot).then(() => {\n resolve({ snapshot: domSnapshot });\n });\n });\n};\n","import { takeSnapshot as takeChromaticSnapshot } from './takeSnapshot';\nimport { CypressSnapshot } from './types';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace Cypress {\n interface Chainable {\n /**\n * Method for taking a manual snapshot with Chromatic\n *\n *\n * @param {string} name - Use to apply a custom name to the snapshot (optional)\n */\n takeSnapshot(name?: string): Chainable<any>;\n }\n }\n}\n\nCypress.Commands.add('takeSnapshot', (name?: string) => {\n // don't take snapshots when running `cypress open`\n if (!Cypress.config('isTextTerminal')) {\n return;\n }\n\n cy.document().then((doc) => {\n // here, handle the source map\n\n cy.wrap(takeChromaticSnapshot(doc, true)).then((manualSnapshot: CypressSnapshot) => {\n // reassign manualSnapshots so it includes this new snapshot\n cy.get('@manualSnapshots')\n // @ts-expect-error will fix when Cypress has its own package\n .then((snapshots: CypressSnapshot[]) => {\n return [...snapshots, { ...manualSnapshot, name }];\n })\n .as('manualSnapshots');\n });\n });\n});\n","import './commands';\nimport { takeSnapshot } from './takeSnapshot';\nimport { CypressSnapshot } from './types';\n\nconst buildChromaticParams = (env: Cypress.Cypress['env']) => ({\n ...(env('diffThreshold') && {\n diffThreshold: env('diffThreshold'),\n }),\n ...(env('delay') && { delay: env('delay') }),\n ...(env('diffIncludeAntiAliasing') && {\n diffIncludeAntiAliasing: env('diffIncludeAntiAliasing'),\n }),\n ...(env('diffThreshold') && {\n diffThreshold: env('diffThreshold'),\n }),\n ...(env('forcedColors') && { forcedColors: env('forcedColors') }),\n ...(env('pauseAnimationAtEnd') && {\n pauseAnimationAtEnd: env('pauseAnimationAtEnd'),\n }),\n ...(env('prefersReducedMotion') && {\n prefersReducedMotion: env('prefersReducedMotion'),\n }),\n ...(env('cropToViewport') && {\n cropToViewport: env('cropToViewport'),\n }),\n ...(env('ignoreSelectors') && {\n ignoreSelectors: env('ignoreSelectors'),\n }),\n});\n\n// these client-side lifecycle hooks will be added to the user's Cypress suite\nbeforeEach(() => {\n // don't take snapshots when running `cypress open`\n if (!Cypress.config('isTextTerminal')) {\n return;\n }\n // this \"manualSnapshots\" variable will be available before, during, and after the test,\n // then cleaned up before the next test is run\n // (see https://docs.cypress.io/guides/core-concepts/variables-and-aliases#Aliases)\n cy.wrap([]).as('manualSnapshots');\n cy.task('prepareArchives', {\n action: 'setup-network-listener',\n payload: { allowedDomains: Cypress.env('assetDomains') },\n });\n});\n\nafterEach(() => {\n // don't take snapshots when running `cypress open`\n if (!Cypress.config('isTextTerminal')) {\n return;\n }\n // can we be sure this always fires after all the requests are back?\n cy.document().then((doc) => {\n cy.wrap(takeSnapshot(doc)).then((automaticSnapshot: CypressSnapshot) => {\n // @ts-expect-error will fix when Cypress has its own package\n cy.get('@manualSnapshots').then((manualSnapshots = []) => {\n cy.url().then((url) => {\n // pass the snapshot to the server to write to disk\n cy.task('prepareArchives', {\n action: 'save-archives',\n payload: {\n // @ts-expect-error relativeToCommonRoot is on spec (but undocumented)\n testTitlePath: [Cypress.spec.relativeToCommonRoot, ...Cypress.currentTest.titlePath],\n domSnapshots: [...manualSnapshots, ...(automaticSnapshot ? [automaticSnapshot] : [])],\n chromaticStorybookParams: buildChromaticParams(Cypress.env),\n pageUrl: url,\n viewport: {\n height: Cypress.config('viewportHeight'),\n width: Cypress.config('viewportWidth'),\n },\n outputDir: Cypress.config('downloadsFolder'),\n },\n });\n });\n });\n });\n });\n});\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chromatic-com/cypress",
3
- "version": "0.10.1",
3
+ "version": "0.11.0",
4
4
  "description": "Chromatic Visual Regression Testing for Cypress",
5
5
  "repository": {
6
6
  "type": "git",