【问题标题】:Unable to have npm run a script that starts testcafe无法让 npm 运行启动 testcafe 的脚本
【发布时间】:2019-11-17 14:17:17
【问题描述】:

我有一个 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.

我希望能够运行脚本来开始我的测试。下面是我的代码。谢谢你。

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

登录测试.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);
});

【问题讨论】:

  • 能否请您说明login-test.js 文件的完整路径?
  • 没错,就是/Users/name/Development/app/hub/test/features/login-test.js
  • 你使用本地安装的还是全局安装的TestCafe?我遇到了同样的问题,直到我发现由于“此环境变量太大”而无法更改 PATH 环境变量。错误。我在this 线程之后修复了它。

标签: reactjs npm automated-tests testcafe shelljs


【解决方案1】:

我现在正在做类似的事情,但是把

testcafe chrome:headless login-test.js

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

【讨论】:

    猜你喜欢
    • 2018-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-28
    • 2017-09-09
    • 2021-09-27
    • 2014-02-20
    相关资源
    最近更新 更多