Search code examples
node.jsenvironment-variablespuppeteertesting-library

Node Environment variable ignored by testing library


I'm implementing Testing Library with Puppeteer and I was trying to use an environment variable, DEBUG_PRINT_LIMIT, to limit the length of the HTML printed to console in case of failure.

But for some reasons, the variable environment is just ignored by the library...

My project:

package.json

{
  "scripts": {
    "test": "jest --detectOpenHandles"
  },
  "devDependencies": {
    "jest": "^26.6.3",
    "pptr-testing-library": "^0.6.4",
    "puppeteer": "^2.1.1"
  }
}

main.test.js

const puppeteer = require('puppeteer')
require('pptr-testing-library/extend')

test('Should go to the forum', async () => {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    await page.goto("https://mkpc.malahieude.net");
    const $document = await page.getDocument();
    const $forum = await $document.getByText("Forum");
});

Now when I run DEBUG_PRINT_LIMIT=10 npm test, the environment variable is just ignored since it prints me the whole HTML instead of just 10 characters...

I tried many things: setting the environment variable in the package.json file, or directly in the code, but nothing works, the variable is just ignored.

However if I change the code of the library (file node_modules/pptr-testing-library/dom-testing-library.js), and I replace process.env.DEBUG_PRINT_LIMIT || 7000 with process.env.DEBUG_PRINT_LIMIT || 10, then it works! So it seems that for some reason the environment variable is not passed correctly to the library.

I'm using node version 12 on a Debian machine (I think it doesn't change anything though).

Can you tell me what I'm doing wrong?

Thanks


Solution

  • If finally figured it out.

    It's actually a bug in the library itself: https://github.com/testing-library/pptr-testing-library/issues/55