Невозможно, чтобы npm запустил скрипт, запускающий testcafe - PullRequest
1 голос
/ 08 июля 2019

У меня есть проект React.Я пытаюсь использовать скрипт npm, который будет запускать тест с использованием testcafe.В этом тесте используются yargs и shelljs.Когда я запускаю тесты вне package.json, все работает нормально, но когда я использую npm run test:local -- --api=local, это не работает, и я получаю сообщение об ошибке:

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

Я хочу иметь возможность запустить скрипт для запуска моих тестов.Ниже мой код.Спасибо.

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);
});
...