@chromaui/test-archiver
Advanced tools
@@ -0,1 +1,13 @@ | ||
# v0.0.5 (Tue Apr 11 2023) | ||
#### ⚠️ Pushed to `main` | ||
- Don't capture outside of Chromium ([@tmeasday](https://github.com/tmeasday)) | ||
#### Authors: 1 | ||
- Tom Coleman ([@tmeasday](https://github.com/tmeasday)) | ||
--- | ||
# v0.0.4 (Sat Apr 08 2023) | ||
@@ -2,0 +14,0 @@ |
@@ -13,6 +13,6 @@ 'use strict'; | ||
var w=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,o)=>(typeof require<"u"?require:e)[o]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw new Error('Dynamic require of "'+t+'" is not supported')});var r=process.env.LOG?console:{log:(...t)=>{}};var g=class{constructor(e){this.page=e;this.archive={};this.closed=!1;}async watch(){this.client=await this.page.context().newCDPSession(this.page),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(){await new Promise(e=>setTimeout(e,1e3)),r.log("Watcher closing"),this.closed=!0;}setResponse(e,o){this.archive[e]=o;}requestWillBeSent(e){r.log("requestWillBeSent"),r.log(e);}responseReceived(e){r.log("responseReceived"),r.log(e);}async requestPaused({requestId:e,request:o,responseStatusCode:s,responseStatusText:i,responseErrorReason:a}){if(r.log("requestPaused",o.url,s||a?"response":"request"),this.closed&&r.log("Watcher closed, ignoring"),a)throw "TODO";if(s){let{body:c,base64Encoded:m}=await this.client.send("Fetch.getResponseBody",{requestId:e});return this.archive[o.url]={statusCode:s,statusText:i,body:Buffer.from(c,m?"base64":"utf8")},await this.client.send("Fetch.continueRequest",{requestId:e})}let n=this.archive[o.url];if(n)return r.log("pausing request we've seen before, sending previous response"),r.log({requestId:e,responseCode:n.statusCode,responsePhrase:n.statusText}),await this.client.send("Fetch.fulfillRequest",{requestId:e,responseCode:n.statusCode,...n.statusText&&{responsePhrase:n.statusText},body:n.body.toString("base64")});await this.client.send("Fetch.continueRequest",{requestId:e,interceptResponse:!0});}};async function y(t){let e=new g(t);return await e.watch(),async()=>(await e.idle(),e.archive)}var p=t=>t.toLowerCase().replace(/[ ’–—―′¿'`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi,"-").replace(/-+/g,"-").replace(/^-+/,"").replace(/-+$/,""),{OUTPUT_DIR:D="./test-archives"}=process.env,f=path.resolve(D),P=path.join(f,"latest"),j=p(new Date().toLocaleString()),h=path.join(f,j),R=path.join(h,"archive");async function T(t,e,o){await fsExtra.ensureDir(f),await fsExtra.ensureDir(h),await fsExtra.remove(P),await fsExtra.ensureSymlink(h,P),r.log(`Writing test results for "${t}"`),await Promise.all(Object.entries(o).map(async([s,i])=>{let{pathname:a}=new URL(s);await fsExtra.outputFile(path.join(R,a==="/"?`${p(t)}.html`:a),i.body);})),await Object.entries(e).map(async([s,i])=>{await fsExtra.outputFile(path.join(R,`${p(t)}-${p(s)}.snapshot.json`),i);}),await B(path.join(h,`${p(t)}.stories.json`),t,e);}async function B(t,e,o){r.log(`Writing ${t}`),await fsExtra.outputJson(t,{title:e,stories:Object.keys(o).map(s=>({name:s,parameters:{server:{id:`${p(e)}-${p(s)}.snapshot.json`}}}))});}var F=fs.readFileSync(w.resolve("@chromaui/rrweb-snapshot/dist/rrweb-snapshot.js"),"utf8"),u="application/rrweb.snapshot+json";async function d(t,e,o){let s,i;if(typeof e=="string"){if(!o)throw new Error("Incorrect usage");i=o,s=e;}else i=e,s=`Snapshot #${i.attachments.filter(c=>c.contentType===u).length+1}`;t.on("console",n=>{r.log(`CONSOLE: "${n.text()}"`);});let a=await t.evaluate(C__default.default` | ||
var d=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,o)=>(typeof require<"u"?require:e)[o]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw new Error('Dynamic require of "'+t+'" is not supported')});var r=process.env.LOG?console:{log:(...t)=>{}};var g=class{constructor(e){this.page=e;this.archive={};this.closed=!1;}async watch(){this.client=await this.page.context().newCDPSession(this.page),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(){await new Promise(e=>setTimeout(e,1e3)),r.log("Watcher closing"),this.closed=!0;}setResponse(e,o){this.archive[e]=o;}requestWillBeSent(e){r.log("requestWillBeSent"),r.log(e);}responseReceived(e){r.log("responseReceived"),r.log(e);}async requestPaused({requestId:e,request:o,responseStatusCode:s,responseStatusText:i,responseErrorReason:a}){if(r.log("requestPaused",o.url,s||a?"response":"request"),this.closed&&r.log("Watcher closed, ignoring"),a)throw "TODO";if(s){let{body:c,base64Encoded:m}=await this.client.send("Fetch.getResponseBody",{requestId:e});return this.archive[o.url]={statusCode:s,statusText:i,body:Buffer.from(c,m?"base64":"utf8")},await this.client.send("Fetch.continueRequest",{requestId:e})}let n=this.archive[o.url];if(n)return r.log("pausing request we've seen before, sending previous response"),r.log({requestId:e,responseCode:n.statusCode,responsePhrase:n.statusText}),await this.client.send("Fetch.fulfillRequest",{requestId:e,responseCode:n.statusCode,...n.statusText&&{responsePhrase:n.statusText},body:n.body.toString("base64")});await this.client.send("Fetch.continueRequest",{requestId:e,interceptResponse:!0});}};async function y(t){let e=new g(t);return await e.watch(),async()=>(await e.idle(),e.archive)}var p=t=>t.toLowerCase().replace(/[ ’–—―′¿'`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi,"-").replace(/-+/g,"-").replace(/^-+/,"").replace(/-+$/,""),{OUTPUT_DIR:D="./test-archives"}=process.env,f=path.resolve(D),P=path.join(f,"latest"),j=p(new Date().toLocaleString()),h=path.join(f,j),R=path.join(h,"archive");async function T(t,e,o){await fsExtra.ensureDir(f),await fsExtra.ensureDir(h),await fsExtra.remove(P),await fsExtra.ensureSymlink(h,P),r.log(`Writing test results for "${t}"`),await Promise.all(Object.entries(o).map(async([s,i])=>{let{pathname:a}=new URL(s);await fsExtra.outputFile(path.join(R,a==="/"?`${p(t)}.html`:a),i.body);})),await Object.entries(e).map(async([s,i])=>{await fsExtra.outputFile(path.join(R,`${p(t)}-${p(s)}.snapshot.json`),i);}),await B(path.join(h,`${p(t)}.stories.json`),t,e);}async function B(t,e,o){r.log(`Writing ${t}`),await fsExtra.outputJson(t,{title:e,stories:Object.keys(o).map(s=>({name:s,parameters:{server:{id:`${p(e)}-${p(s)}.snapshot.json`}}}))});}var F=fs.readFileSync(d.resolve("@chromaui/rrweb-snapshot/dist/rrweb-snapshot.js"),"utf8"),u="application/rrweb.snapshot+json";async function w(t,e,o){let s,i;if(typeof e=="string"){if(!o)throw new Error("Incorrect usage");i=o,s=e;}else i=e,s=`Snapshot #${i.attachments.filter(c=>c.contentType===u).length+1}`;t.on("console",n=>{r.log(`CONSOLE: "${n.text()}"`);});let a=await t.evaluate(C__default.default` | ||
${F}; | ||
rrwebSnapshot.snapshot(document, { noAbsolute: true }); | ||
`);i.attach(s,{contentType:u,body:JSON.stringify(a)});}var x=t=>t.extend({save:[async({page:e},o,s)=>{let i=await y(e);await o(),await d(e,s);let a=await i(),n=Object.fromEntries(s.attachments.filter(c=>c.contentType===u&&!!c.body).map(({name:c,body:m})=>[c,m]));await T(s.title,n,a);},{auto:!0}]});var se=x(test.test); | ||
`);i.attach(s,{contentType:u,body:JSON.stringify(a)});}var x=t=>t.extend({save:[async({page:e},o,s)=>{if(e.context().browser().browserType().name()!=="chromium"){await o();return}let i=await y(e);await o(),await w(e,s);let a=await i(),n=Object.fromEntries(s.attachments.filter(c=>c.contentType===u&&!!c.body).map(({name:c,body:m})=>[c,m]));await T(s.title,n,a);},{auto:!0}]});var se=x(test.test); | ||
@@ -23,5 +23,5 @@ Object.defineProperty(exports, 'expect', { | ||
}); | ||
exports.takeArchive = d; | ||
exports.takeArchive = w; | ||
exports.test = se; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@chromaui/test-archiver", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Archive end-to-end tests to be replayed in Storybook and Chromatic", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -17,2 +17,2 @@ ## @storybook/test-archiver | ||
[MIT](https://github.com/storybookjs/@chromaui/test-archiver/blob/main/LICENSE) | ||
[MIT](https://github.com/chromaui/test-archiver/blob/main/LICENSE) |
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
44785
3.1%