Testcafe: ERROR No tests to run. Either the test files contain no tests or the filter function is too restrictive.

Created on 23 Sep 2018  路  11Comments  路  Source: DevExpress/testcafe

reporting a bug?

I have written the test in another file and calling it below the fixture, but now I am getting this error.

ERROR No tests to run. Either the test files contain no tests or the filter function is too restrictive.

Test code

---CommonScripts.js---

const commonScripts = {
google() {
test('google', async t => {
await t
.typeText('#tsf > div:nth-child(2) > div.A8SBwf > div.RNNXgb > div > div.a4bIc > input', 'Hello World');
});
}
};
export default commonScripts;

---google.js---

import commonScripts from './commonScripts.js';

fixture('google')
.disablePageReloads
.page('https://google.com');

commonScripts.google();

Specify your

Auto-locked question

Most helpful comment

Seems to be an issue with the static analysis testcafe does to determine testfiles.
As a hacky work around you can try adding a comment in google.js:
// test()

It would be nice to be able to add an annotation to allow importing tests as modules

All 11 comments

It works if there is atleast one test below fixture like this.

import commonScripts from './commonScripts.js';

fixture('google')
.disablePageReloads
.page('https://google.com');

test('wait', async t => {
await t
.wait(1);
});
commonScripts.google();

Seems to be an issue with the static analysis testcafe does to determine testfiles.
As a hacky work around you can try adding a comment in google.js:
// test()

It would be nice to be able to add an annotation to allow importing tests as modules

Helpful thanks

@subbiah2806 @ljowen
Hi
The code analyzer requires use of the test method in the test file, but you can easily bypass this restriction in the following manner:

Create your module with some object which contains a test name and test function:

const commonScripts = {
    testSet1 () {
        return [{
            testName: 'test',
            testFn: async t => {
                await t.click('a');
            }
        }];
    }
};
聽
export default commonScripts;


Import this module and call the test function from the module's resulting object:

import commonScripts from './test-module';
聽
fixture `gh-1312`
    .page `http://example.com`;
聽
function startTesting(testSet) {
    for (let i = 0; i < testSet.length; i++)
        test(testSet[i].testName, testSet[i].testFn);
}
聽
startTesting(commonScripts.testSet1());

It will allow structurizing your tests as you wish and avoid the code analyzer's restrictions.

Hello, I am currently having the same issue and I don't understand how this solution works. Could you please explain.

@Jgshirley
This issue occurs, because the TestCafe static code analyzer requires words test and feature in your test file. My solution is to reorganize the test files structure. I define the array of test names and test functions in a separate module (see commonScripts). Then I import test names and test functions and use them as params of the global test function::

function startTesting(testSet) {
    for (let i = 0; i < testSet.length; i++)
        test(testSet[i].testName, testSet[i].testFn);
}

It allows me to bypass the restrictions of the static analyzer.
I should add that the latest TestCafe version supports the --disable-test-syntax-validation option (http://devexpress.github.io/testcafe/documentation/using-testcafe/command-line-interface.html#--disable-test-syntax-validation) . This option disables checks for test and fixture directives in test files. Use this flag to run dynamically loaded tests.

The same problem occurred to me and i found out it was the .tsx extension that caused the problem. Changing back to .ts fixed it. 馃憤

I just got bit by the same issue as @dirkrooijakkers. Might be worth updating the documentation to indicate that TSX files are not supported or point to documentation that lets you point testcafe to the right tsconfig.json file or just specify your own compiler options. I have jsx: 'react' set in my workspace's tsconfig.json file but it's not being used by testcafe.

@icfantv this issue is covered by https://github.com/DevExpress/testcafe/issues/1845. Don't hesitate to add 馃憤 to it.

We have plans to implement it, but I can't give you any estimates yet. Of course, your PR will be welcomed 馃槃

@andreybelym ah, thanks for the reference.

This thread has been automatically locked since it is closed and there has not been any recent activity. Please open a new issue for related bugs or feature requests. We recommend you ask TestCafe API, usage and configuration inquiries on StackOverflow.

Was this page helpful?
0 / 5 - 0 ratings