A
A
Alexey Nikolaev2019-10-19 09:45:43
JavaScript
Alexey Nikolaev, 2019-10-19 09:45:43

Is it possible to manually feed tests to jest?

Good day.
There is nodejs, jest and the desire to run the test manually. What I mean? Usually, jest'a tests are processed automatically by it, and it itself is launched from the command line. I would like it like this:

module.exports = async function checkStatus(browser, { url, status = null }) {
  const page = await browser.newPage();

  describe('Google', () => {
    beforeAll(async () => {
      await page.goto(url);
    });

    it('should be titled "Google"', async () => {
      await expect(page.title()).resolves.toMatch('Google');
    });
  });
};

If I call this function from somewhere, the node says that describe is not defined. I'd like to run this test programmatically, perhaps passing this function to jest or importing describe and it from there. Is it possible? I didn't find anything in the documentation.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xversus, 2019-10-19
@Heian

If I understand your question correctly, then:

const { exec } = require('child_process');
exec('yarn test -t "Google"', (err, stdout, stderr) => {
  if (err) {
    console.error(err);
    return;
  }
  console.log(`stdout: ${stdout}`);
  console.error(`stderr: ${stderr}`);
});

In package.scripts just write "test": "jest".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question