3

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.

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
Rob C
  • 662
  • 5
  • 15

2 Answers2

4

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

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
mlosev
  • 5,130
  • 1
  • 19
  • 31
0

I can't comment because I don't have 50 rep...

@mlosev how would you go about filtering through the .testcaferc.json file like you did there with the runner?

I want to run all tests except those with a meta of toDo: 'yes'. Current config file:

{
    "assertionTimeout": 5000,
    "browsers": ["chrome --window-size=1920,1159"],
    "concurrency": 7,
    "pageLoadTimeout": 15000,
    "reporter": {
        "name": "spec",
        "output": "artifacts/reports/test_suite_results"
    },
    "screenshots": {
        "path": "artifacts/screenshots",
        "pathPattern": "${TEST}_${DATE}_${TIME}.png",
        "takeOnFails": true
    },
    "selectorTimeout": 5000,
    "skipJsErrors": false,
    "src": "tests",
    "videoEncodingOptions": {
        "aspect": "16:9",
        "framerate": 30
    },
    "videoOptions": {
        "failedOnly": true,
        "pathPattern": "${TEST}_${DATE}_${TIME}.mp4",
        "singleFile": false
    }, 
    "videoPath": "artifacts/recordings"
}