如何使用jest

时间:2018-04-10 12:56:26

标签: batch-file cmd jasmine jestjs frisby.js

在cmd中运行时它没有参数。基本上,它将参数作为参数并在整个文件中搜索该参数,并在所有文件与该参数匹配时运行所有文件,它不限于特定的文件。

类似文件

1.login_account_spec.js

    var frisby = require("frisby");
    const Joi = frisby.Joi;

   console.log(process.argv)

    /**
    * Commandline parameter includes
    */
    /*  
    var name = process.env['name'];
    var password = process.env['password'];
    var dateTime = record.getDateTime();

    frisby.globalSetup({
        request: { 
            headers : { 
                    "accept": "application/json", 
                    "content-type" : "application/json", 
            }
        }
    });

    it("Test login_account" + dateTime, function (done){
        frisby.get(url)
        .expect("status", 200)
        .expect("header", "content-type", "application/json; charset=utf-8")
        .expect("jsonTypes", "data", {
            "message" : Joi.string(),
            })
        .then(function(res) {
            var body = res.body;
            body = JSON.parse(body);
            expect(body.data.message).toBeDefined();

        })
        .then(function(res) {
            record.createLogFile("login_account" + dateTime, null, res);
        })
        .done(done);
    }); 

2.get_device_details_spec.js

 var frisby = require("frisby");
 const Joi = frisby.Joi;

    console.log(process.argv)


    frisby.globalSetup({
        request: { 
            headers : { 
                "Accept": "application/json", 
                "content-type" : "application/json" 
            }
        }
    });

    it("Test get_device_details" + dateTime, function(done){
        frisby.get(url)
        .expect("status", 200)
        .expect("header", "content-type", "application/json; charset=utf-8")
        .expect("jsonTypes", "data", {
            "description": Joi.string(),
        })
            .then(function(res) {
                var body = res.body;
                body = JSON.parse(body);
                expect(body.data.description).toBeDefined();
            })  
        .after(function(res) {
            record.createLogFile("get_device_details" + dateTime, err, res);
        })
        .done(done);
});

Unit_test.bat 包含脚本(此处只有两个)

@echo off
set URL=%1
set NAME=%2
set PASSWORD=%3

set /a var2=1
set /a var=0
set /a varx=0
IF /I "%ITERATION%" NEQ "0" (
    SET var2=%ITERATION%
    SET /a ITERATION=1
)

for /L %%n in (1,%ITERATION%,%var2%) do @(

    jest login_account_spec.js %URL% %NAME% %PASSWORD% 

    REM jest get_device_details_spec.js %URL%  %NAME% %PASSWORD% 

)

在CMD中:

Unit_Test.bat 192.168.1.17:XXXX test1 123

然后它给出了这两个文件的结果,这些js文件与Frisby有关。

所以我想只运行(login_account_spec.js)带有我在cmd中传递的参数的文件。但是,它给出了我不想要的两个脚本的结果,也没有接受我通过的论点。

1 个答案:

答案 0 :(得分:0)

.bat文件

@echo off
set URL=%1
set HTTPMODE=%2
set USERNAME=%3
set PASSWORD=%4
set ENCRYPTION=%5
set ITERATION=%6
set COMPANYID=%7

REM call current_time.bat   
        REM set config={"httpMode": "%HTTPMODE%","url": "%URL%","encryption": "%ENCRYPTION%","username": "%USERNAME%@gmail.com","password": "%PASSWORD%","companyId": "%COMPANYID%","role": "Owner"}

在.js文件中:

var objConfig = JSON.parse(process.env.config);

var username = objConfig.username;
var encryption = objConfig.encryption;

最后一次在cmd上运行: xx.bat用户名密码...

希望对其他人有帮助