1.1.0 • Published 8 years ago

gardr-validator v1.1.0

Weekly downloads
127
License
-
Repository
github
Last release
8 years ago

garðr-validator

Collect data from a display-ads lifecyle and validate the data. This project tries to give a nice framework for doing this.

Build Status Coverage Status NPM version Dependency Status devDependency Status

Installation

$ npm install

Examples

See the web-gui for this project: https://github.com/gardr/validator-web/blob/master/lib/routes/validate.js#L284

Writing intrumentation and validators

Intrument / Hook example filename: 'someData.js':
module.exports = {
    'onBeforeExit': function (api, config) {
        api.switchToIframe();
        if (config.someConfigBoolean){
            api.set('collectedData', api.evaluate(function(config){
                return window.someData;
            }, config));
        }
    }
};
Preprocessor example filename 'fixSomethingAsync.js'
module.exports = {
    'dependencies': ['someData'],
    'preprocess': function(harvested, output, next, globalOptions){
        output('someKey', {data: harvested.someData||{}});
        setTimeout(next, 1);
    }
};
Validator example filename 'someData.js'
module.exports = {
    'preprocessors': [
        'fixSomethingAsync'
    ],
    'dependencies': [
        'someData'
    ],
    'validate': function(harvested, report, next, globalOptions){
        if (this.someConfigBoolean){
            if (harvested.someData){
                report.error('Some message');
            }
        }
    }
};
Adding instrumentation/hooks etc to a run
var run = require('gardr-validator');
var options = {
    'include': [
        {
            name: 'someData',
            path: '/resolved/path/to/someData.js'
        }
    ],
    'config':{
        'someData': {
            'someConfigBoolean': true
        }
    }
};
run(options, function(phantomError, harvest, report){
    if (phantomError){
        // do something
        return;
    }
    assert(harvest.someData);
    assert(harvest.someKey);
    assert(report.errors.length === 1);
})

Options to runner

{
    instrument: [
        'actions', // defaults to files in /lib/rule/instrument/actions.js
        {name: 'css'},
        {name: 'custom', path: '/absolute/path/to/file'},
        {name: 'custom2', code: 'var someCode = "";'}
    ],
    preprocess: [
        //..
    ],
    validate: [
        //..
    ]
    //rest of runner default options, see /config folder.
}

Contributing

YES, pull requests with tests. Be sure to create a issue and let us know you are working on it - maybe we can help out with insights etc.

Running tests

$ npm test

Configuration options via process.env / ENV variables

- GOOG_PAGESPEED_API_KEY
- GOOG_SAFE_BROWSE_API_KEY
Alternatives

(please let us know of alternatives to this project)

1.1.0

8 years ago

1.0.0

9 years ago

0.10.0

9 years ago

0.9.0

9 years ago

0.8.5

9 years ago

0.8.4

10 years ago

0.8.3

10 years ago

0.8.2

10 years ago

0.8.1

10 years ago

0.8.0

10 years ago

0.7.4

10 years ago

0.7.3

10 years ago

0.7.2

10 years ago

0.7.0

10 years ago

0.6.2

10 years ago

0.6.1

10 years ago

0.6.0

10 years ago

0.5.0

10 years ago

0.4.0

10 years ago

0.3.4

10 years ago

0.3.3

10 years ago

0.3.2

10 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.11

10 years ago

0.1.10

10 years ago

0.1.9

10 years ago

0.1.8

10 years ago

0.1.7

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.12

10 years ago

0.0.11

10 years ago

0.0.10

10 years ago