2

I have a React project. I am trying to use an npm script that will run a test using testcafe. This test uses yargs and shelljs. When I run the tests outside of the package.json everything works fine, but when I use npm run test:local -- --api=local it does not work and I get an error:

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

I want to be able to run the script to start my tests. Below is my code. Thank you.

Package.json:

"scripts": {
  "test:local": "node ./test/features/index.js",
}

index.js:

const argv = require('yargs').argv;
const shell = require('shelljs');

if (argv.api === 'local') {
  shell.exec('testcafe chrome:headless login-test.js');
}

login-test.js:

/* eslint-disable no-unused-expressions */
import { Selector } from 'testcafe';
import Page from './page-model';

const page = new Page();

fixture`Log In Page`.page(page.loginScreen);

test('Log In', async t => {
  await page.userLogin(t);
});

test('Forgot Password', async t => {
  const forgotLink = Selector('a').withAttribute('href', '/forgot');
  const forgotEmailInput = Selector('input').withAttribute('placeholder', 'Email address');
  const resetModal = Selector('div').withAttribute('class', 'Toast-message').innerText;

  await t
    .click(forgotLink)
    .typeText(forgotEmailInput, 'my@email.co')
    .click(page.submit)
    .expect(resetModal)
    .eql('Password reset sent.');
});

test('Forgot Password - Ready to login link', async t => {
  const forgotLink = Selector('a').withAttribute('href', '/forgot');
  const readyLoginButton = Selector('a').withAttribute('href', '/login');

  await t.click(forgotLink).click(readyLoginButton);
});
Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
Ryan113
  • 676
  • 1
  • 10
  • 27
  • 1
    Would you please clarify the full path for the `login-test.js` file? – mlosev Jul 08 '19 at 15:14
  • Yes, it is /Users/name/Development/app/hub/test/features/login-test.js – Ryan113 Jul 08 '19 at 15:17
  • Do you use the locally or globally installed TestCafe? I had the same problem until I found that I cannot change the PATH environment variable due to the "This environment variable is too large." error. I fixed it following [this](https://stackoverflow.com/questions/34491244/environment-variable-is-too-large-on-windows-10) thread. – Arseniy Rubtsov Jul 10 '19 at 11:33

1 Answers1

0

I am doing something similar at the moment, but putting the

testcafe chrome:headless login-test.js

command directly into the scripts section of package.json.

ds4940
  • 3,382
  • 1
  • 13
  • 20