New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

at-test

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

at-test

基于@Annotation的单元测试框架

latest
npmnpm
Version
1.1.6
Version published
Maintainers
1
Created
Source

#at-test(基于注释的JS单元测试框架)

Base on at-js

##使用方法 ###安装

    npm install at-test --save-dev

###示例一

  • 假设您的module文件结构是这样的:
-myModule
    |-node_modules
    |-test1.js
    |-main.js
    |-package.json
  • 文件test1.js的内容:
var assert = require('assert');

'@test.step';
var t0 = function () {
    var ts = 'aaaaa';
    for (var i = 0; i < 10000; i++) {
        ts += 'aa';
    }
    return ts;
}

'@test.step';
var t1 = function () {
    var t = 900;
    t = 900/9;
    assert.equal(t,100);
}
  • 文件main.js的内容:
require('at-test')(['./test1.js']).then(function(report){
    console.log(report);
});
  • 运行
    node main.js

###示例二:复杂测试 module中的test.js中,代码修改成:

var assert = require('assert');
var ds = null;

'@test.start';
var start = function () {
    ds = {};
}

'@test.step(timeout=2000)';
var test0 = function* () {
    ds.test0 = 'finish';
    var rtn = yield (function(){
        return function(_next){
            setTimeout(function(){
                _next(null,3);
            },2000)
        }
    })();
    assert.equal(rtn,3);
}

'@test.step';
var test1 = function () {
    ds.test1 = 'finish';
    return ds;
}

'@test.finish';
var fh = function () {
    ds = null;
}

module.exports = {
    deleteItem:function*(_itemObj){
        yield dao.del(_itemObj);
        return {suc:true};
    }
}
/**
 * Annotation for dao
 */
'@dao'
var dao = function(){
    throw new Error('No one implement me?oh my God....');
}

###示例三:测试文件自动扫描

  • module文件结构如下:
-myModule
    |-node_modules
    |-folder0
        |-a.test.js
    |-folder1
        |-b.test.js
    |-main.js
    |-package.json

在module的除node_modules外的任意位置, 创建任意名称后缀为.test.js的单元测试文件

  • 文件main.js的内容:
require('at-test')().then(function(report){
    console.log(report);
});
  • 运行
    node main.js

欢迎提issue,或者直接联系作者即时交流(微信号:ALJZJZ)

FAQs

Package last updated on 18 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts