NimaSoroush / Mockeer

Mocking library for Puppeteer!
MIT License
34 stars 4 forks source link

Filter resource type #11

Open wallynm opened 5 years ago

wallynm commented 5 years ago

Instead of control just one ressourceType it's better to control what each configuration/setup needs, in my case i need to mock document, xhr and other things but i don't need scripts files or styles because once they're cached by the Mockeer, i can't certify that my application it's broken because i'm testing it against a cached JS version.

So to avoid that an filter based into ressourceType listed into Puppteer docs as we can find here: https://pptr.dev/#?product=Puppeteer&version=v1.20.0&show=api-requestresourcetype

You configure what ressourceTypes you wanna to blacklist using

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await mockeer(browser, {
    disallowedResourceTypes: ['image', 'script', 'stylesheet']
  });
  await page.goto('https://www.example.com');
  await page.close();
  await browser.close();
})();

default values as [] empty array so doesn't change anything of the current API that's been used into other projects.

My fixtures sizes was something like 5mb and with this update - allowing you to choose what you be mocking it's down to 50kb each fixture as DO need my CSS files and JS files updated every time through tests.

wallynm commented 5 years ago

Another approach that we can discuss it's an allowedResourceTypes which do include what you wanna record.

Same result, different approach.