testing-library / pptr-testing-library

puppeteer + dom-testing-library = 💖
MIT License
287 stars 29 forks source link

"RangeError: invalid string length" while processing query in Chrome context #60

Open maddy-jo opened 3 years ago

maddy-jo commented 3 years ago

Description

First: a disclaimer that I am not sure at all where this issue originates but am asking here to see if anyone has any thoughts on where to keep looking if it isn't with Puppeteer Testing Library.

I am trying to write some integration tests for my app and am getting an Evaluation failed: RangeError: Invalid string length error from Puppeteer. Here is the gist of the test:

describe('MyPage', () => {
  beforeEach(async () => {
    await page.goto(`${puppeteerHost}/my-page`);
  });

  describe('keyboard focus on step change', () => {
    describe('for step 1 = Verification', () => {
      const isYesRadioButtonFocused = async (): Promise<void> => {
        const $document = await getDocument(page);
        const radioButtonGroup = await queries.getByRole($document, 'group', {
          name: /^Are you a US\-based company\?/,
        }); // fails executing this query

        const yesButton = await queries.getByRole(radioButtonGroup, 'radio', { name: 'Yes' });
        const isFocused = await yesButton.evaluate(radioButton => radioButton === document.activeElement);
        expect(isFocused).toBe(true);
      };

      describe('is on the Yes radio button for the US-based company question', () => {
        it('when the form is initially loaded', isYesRadioButtonFocused);
        // is on the Yes radio button at some other time, etc
      });
    });
  });
});

Here is the stack trace from Jest:

  ● MyPage › keyboard focus on step change › for step 1 = Verification › is on the Yes radio button for the US-based company question › when the form is initially loaded

    Evaluation failed: RangeError: Invalid string length

      at printObjectProperties (__puppeteer_evaluation_script__:1224:53)
      at printComplexValue (__puppeteer_evaluation_script__:2096:175)
      at printer (__puppeteer_evaluation_script__:2141:16)
      at printObjectProperties (__puppeteer_evaluation_script__:1223:27)
      at printComplexValue (__puppeteer_evaluation_script__:2096:175)
      at printer (__puppeteer_evaluation_script__:2141:16)
      at printObjectProperties (__puppeteer_evaluation_script__:1223:27)
      at printComplexValue (__puppeteer_evaluation_script__:2096:175)
      at printer (__puppeteer_evaluation_script__:2141:16)
      at printObjectProperties (__puppeteer_evaluation_script__:1223:27)
      at printComplexValue (__puppeteer_evaluation_script__:2096:175)
      at printer (__puppeteer_evaluation_script__:2141:16)
      at printObjectProperties (__puppeteer_evaluation_script__:1223:27)
      at printComplexValue (__puppeteer_evaluation_script__:2096:175)
      at printer (__puppeteer_evaluation_script__:2141:16)
      at printObjectProperties (__puppeteer_evaluation_script__:1223:27)
      at printComplexValue (__puppeteer_evaluation_script__:2096:175)
      at printer (__puppeteer_evaluation_script__:2141:16)
      at printObjectProperties (__puppeteer_evaluation_script__:1223:27)
      at printComplexValue (__puppeteer_evaluation_script__:2096:175)
      at printer (__puppeteer_evaluation_script__:2141:16)
      at printObjectProperties (__puppeteer_evaluation_script__:1223:27)
      at printComplexValue (__puppeteer_evaluation_script__:2096:175)
      at printer (__puppeteer_evaluation_script__:2141:16)
      at printObjectProperties (__puppeteer_evaluation_script__:1223:27)
      at printComplexValue (__puppeteer_evaluation_script__:2096:175)
      at printer (__puppeteer_evaluation_script__:2141:16)
      at printObjectProperties (__puppeteer_evaluation_script__:1223:27)
      at printComplexValue (__puppeteer_evaluation_script__:2096:175)
      at printer (__puppeteer_evaluation_script__:2141:16)
      at printObjectProperties (__puppeteer_evaluation_script__:1223:27)
      at printComplexValue (__puppeteer_evaluation_script__:2096:175)
      at printer (__puppeteer_evaluation_script__:2141:16)
      at printObjectProperties (__puppeteer_evaluation_script__:1223:27)
      at printComplexValue (__puppeteer_evaluation_script__:2096:175)
      at printer (__puppeteer_evaluation_script__:2141:16)
      at printObjectProperties (__puppeteer_evaluation_script__:1223:27)
      at printComplexValue (__puppeteer_evaluation_script__:2096:175)
      at printer (__puppeteer_evaluation_script__:2141:16)
      at __puppeteer_evaluation_script__:1447:203
          at Array.map (<anonymous>)
      at printChildren (__puppeteer_evaluation_script__:1447:94)
      at Object.serialize (__puppeteer_evaluation_script__:1521:105)
      at printPlugin (__puppeteer_evaluation_script__:2104:50)
      at printer (__puppeteer_evaluation_script__:2135:18)
      at __puppeteer_evaluation_script__:1447:203
          at Array.map (<anonymous>)
      at printChildren (__puppeteer_evaluation_script__:1447:94)
      at Object.serialize (__puppeteer_evaluation_script__:1521:105)
      at printPlugin (__puppeteer_evaluation_script__:2104:50)
      at ExecutionContext._evaluateInternal (node_modules/puppeteer/lib/ExecutionContext.js:122:13)
        -- ASYNC --
      at ExecutionContext.<anonymous> (node_modules/puppeteer/lib/helper.js:111:15)
      at node_modules/pptr-testing-library/lib/index.ts:101:8
      at node_modules/pptr-testing-library/dist/index.js:8:71
      at Object.<anonymous>.__awaiter (node_modules/pptr-testing-library/dist/index.js:4:12)
      at processQuery (node_modules/pptr-testing-library/dist/index.js:94:12)
      at Object.<anonymous> (node_modules/pptr-testing-library/lib/index.ts:143:12)
      at node_modules/pptr-testing-library/dist/index.js:8:71

I sort of doubt that this issue is specifically with Puppeteer Testing Library but wanted to start investigating from the top of the stack. If it's possible to verify this issue isn't with Puppeteer Testing Library, that would be helpful, and if anyone has insight into whether this might be user error on my part or if I should dig further into Puppeteer and/or Jest Puppeteer, that would also be much appreciated. I'm wondering if it is straightforwardly a memory issue and I need to reconfigure the Chrome instance to have more available memory, or whether there's an issue either with my usage or with one of these tools that I need to address. Thank you for any guidance you're able to provide.

Environment

Here are the package versions + Node + OS I was using. Note that for some of the out of date packages I upgraded to more recent versions than were currently in our project and still got the same issue, so I'm not sure that it's something that would be fixed by upgrading.

Thanks for your help and for your work on this library.