Search code examples
automated-testsmetadatae2e-testingweb-testingtestcafe

Is it possible to use the TestCafe .meta object to skip tests running from the cli


I'm using TestCafe to run my integration tests. I know it has the test.skip function, which is great for when I'm testing locally and want to skip a set of tests I don't need/want to run... but I was wondering if there was a way to run ALL TESTS except --test-meta environmentSpecific=true etc?

We have a number of different environments, and I'm looking for a simple way to skip tests via the CLI, depending on the environment we're targeting for the build.


Solution

  • Yes, you can do it using the programmatic way to run TestCafe. See an example:

    const createTestCafe = require('testcafe');
    let testcafe         = null;
    
    createTestCafe('localhost', 1337, 1338)
        .then(tc => {
            testcafe     = tc;
            const runner = testcafe.createRunner();
    
            return runner
                .src('/tests')
                .filter((testName, fixtureName, fixturePath, testMeta, fixtureMeta) => {
                     return !testMeta.environmentSpecific;
                 })
                .browsers(['chrome', 'safari'])
                .run();
        })
        .then(failedCount => {
            console.log('Tests failed: ' + failedCount);
            testcafe.close();
        });
    

    See also: Specify Test Metadata