Coder Social home page Coder Social logo

Comments (9)

msteller-connyun avatar msteller-connyun commented on June 20, 2024

I found a workaround with https://www.npmjs.com/package/query-selector-shadow-dom

const showroom = require('showroom/puppeteer')();
const path = require('path');

describe('Calendar graph', async () => {

  beforeAll(async () => {
    await showroom.start();
    await showroom.page.addScriptTag({
      path: path.join(process.cwd(), 'node_modules/query-selector-shadow-dom/dist/querySelectorShadowDom.js')
    })
  });

  beforeEach(async () => {
    await showroom.utils.setTestSubject('calendar-graph');
  });

  afterAll(async ()=>{
    await showroom.stop();
  });

  test('should show data', async () => {
    await showroom.utils.trigger('initStatusMapping');
    await showroom.utils.trigger('initData');

    const foo = await showroom.page.evaluate(()=>querySelectorShadowDom.querySelectorAllDeep('calendar-graph .css-td').map(item=>item.innerText));

    expect(foo).toBe(['hello', 'world']);
  });
});

``

from showroom.

eavichay avatar eavichay commented on June 20, 2024

@msteller-connyun I'm glad you found a workaround. If I would add findAll with shadow path then the recursive search would be very laggy and might take too much time.

Showroom is meant for running unit-tests on a single-component level.
If you would like to add utils I would be happy for PRs or suggestions (via issues).

Happy testing.

P.S. I have started working on findAll with one major limitation: until the last '//' shadow path in the search it performs showroom.find and then concatenates the rest of the query as querySelectorAll. Will branch this pretty soon.

from showroom.

msteller-connyun avatar msteller-connyun commented on June 20, 2024

I think your major limitation is fine for me, because I need findAll for unit testing data strucutres, like tables.

from showroom.

eavichay avatar eavichay commented on June 20, 2024

@msteller-connyun I would like to know what was your technique of injecting the deep-query script. Was it in the .showroom/config.js file?

from showroom.

msteller-connyun avatar msteller-connyun commented on June 20, 2024

Hello @eavichay

I did it this way

  beforeAll(async () => {
    await showroom.start();
    await loadLibs();
  });

  test('should show banner', async () => {
    const expectedResult = ['no-display'];
    await showroom.utils.trigger('init');
    const result = await showroom.page.evaluate(() => [...querySelectorShadowDom.querySelectorDeep('cy-google-analytics .ga-banner').classList]);
    expect(result).toEqual(expect.not.arrayContaining(expectedResult));
  });

async function loadLibs() {
  return new Promise(async (resolve) => {
    await showroom.page.addScriptTag({
      path: path.join(process.cwd(), 'node_modules/query-selector-shadow-dom/dist/querySelectorShadowDom.js')
    });
    resolve();
  });
}


from showroom.

eavichay avatar eavichay commented on June 20, 2024

Awesome.
Basically any utils/scripts can be loaded using the config.js file. You can declare script sources that will be added as tags in the HTML.

I know there are yet undocumented features, but this eventually will be fully documented, perhaps with help from the community.

Thanks for the heads-up.

from showroom.

msteller-connyun avatar msteller-connyun commented on June 20, 2024

yeahh... but it’s still painful to use for the selectors an evaluate().
The load a third party library for the findAll is just a workaround.

from showroom.

eavichay avatar eavichay commented on June 20, 2024

πŸ‘

from showroom.

msteller-connyun avatar msteller-connyun commented on June 20, 2024

So.. you closed that ticket. Does this mean there will be no native findAll support in showroom?

from showroom.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.