无法让npm运行启动testcafe的脚本

时间:2019-07-08 04:53:20

标签: reactjs npm automated-tests testcafe shelljs

我有一个React项目。我正在尝试使用将使用testcafe运行测试的npm脚本。此测试使用yargsshelljs。当我在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);
});

1 个答案:

答案 0 :(得分:0)

此刻我正在做类似的事情,但把

testcafe chrome:headless login-test.js

命令直接进入package.json的脚本部分。