Import Third-Party Modules

This example shows how to import a Node.js module to TestCafe tests.

Full Example Code

You can import a module to a test file with the import statement or require function:

import nanoid from 'nanoid';
const nanoid = require('nanoid');

Then you can use this module in test code:

import nanoid from 'nanoid';

fixture `My Fixture`
    .page `https://example.com`;

test(`My Test`, async t => {
    const randomCredentials = {
        username: 'user' + nanoid(),
        email: 'testuser' + nanoid() + '@mycompany.com',
        password: nanoid()
    };

    // ...
});