Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ghost opened this issue Sep 23, 2018 · 11 comments
Labels
STATE: Auto-locked An issue has been automatically locked by the Lock bot. TYPE: question The issue contains a question that won't be addressed.

Comments

@ghost
Copy link

ghost commented Sep 23, 2018

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

  • operating system:10.13.6
  • testcafe version:"^0.22.0",
  • node.js version:10.9.0
@ghost
Copy link
Author

ghost commented Sep 23, 2018

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();

@ljowen
Copy link

ljowen commented Sep 24, 2018

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

@ghost
Copy link
Author

ghost commented Sep 24, 2018

Helpful thanks

@AlexKamaev
Copy link
Contributor

@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.

@AndreyBelym AndreyBelym added the TYPE: question The issue contains a question that won't be addressed. label Sep 26, 2018
@Jgshirley
Copy link

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

@AlexKamaev
Copy link
Contributor

@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.

@dirkrooijakkers
Copy link

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. 👍

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Mar 6, 2019
@AlexKamaev AlexKamaev removed the STATE: Need response An issue that requires a response or attention from the team. label Mar 6, 2019
@icfantv
Copy link

icfantv commented Mar 19, 2019

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.

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Mar 19, 2019
@AndreyBelym
Copy link
Contributor

@icfantv this issue is covered by #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 😄

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Mar 20, 2019
@icfantv
Copy link

icfantv commented Mar 20, 2019

@AndreyBelym ah, thanks for the reference.

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Mar 20, 2019
@AndreyBelym AndreyBelym removed the STATE: Need response An issue that requires a response or attention from the team. label Mar 21, 2019
@lock
Copy link

lock bot commented Mar 31, 2019

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.

@lock lock bot added the STATE: Auto-locked An issue has been automatically locked by the Lock bot. label Mar 31, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Mar 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
STATE: Auto-locked An issue has been automatically locked by the Lock bot. TYPE: question The issue contains a question that won't be addressed.
Projects
None yet
Development

No branches or pull requests

6 participants