首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >承诺中的Testcafe Runner

承诺中的Testcafe Runner
EN

Stack Overflow用户
提问于 2019-08-02 23:12:42
回答 1查看 125关注 0票数 1

我是Promise的新手,所以我需要知道如何将此测试运行程序放入Promise函数中,以便以后可以使用它来调用Promise.race

代码语言:javascript
复制
  const createTestCafe = require('testcafe');
    let testcafe         = null;

    createTestCafe('localhost', 1337, 1338)
        .then((tc) => {
            testcafe       = tc;
            const runner   = testcafe.createRunner();


            return runner
                .src(['test.ts'])
                .browsers(['chrome'])
                 .run({skipJsErrors:true});


    })

    .catch(failedCount => {
        console.log('Tests failed: ' + failedCount);
        testcafe.close();
    })
    .then(successCount => {
            console.log('Tests success: ' + successCount);
            testcafe.close();
    });

我需要testcafe runner作为Promise函数运行,我该怎么做?

EN

回答 1

Stack Overflow用户

发布于 2019-08-05 20:39:53

TestCafe类的run方法返回一个promise,因此您可以像处理TestCafe实例一样将其存储在变量中:

代码语言:javascript
复制
const createTestCafe = require('testcafe');
let testcafe = null;

const testRunPromise = createTestCafe('localhost', 1337, 1338)
    .then(tc => {
        testcafe = tc;
        const runner = testcafe.createRunner();


        return runner
            .src(['test.ts'])
            .browsers(['chrome'])
            .run({ skipJsErrors: true });
    });

testRunPromise
    .catch(failedCount => {
        console.log('Tests failed: ' + failedCount);
        testcafe.close();
    })
    .then(successCount => {
        console.log('Tests success: ' + successCount);
        testcafe.close();
    });

Promise.race([testRunPromise/*, yourAnotherPromise*/]);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57329243

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档