Sha256: 53a658adb4e955ef63a16c8c88ab15e4f2b46a64952c1fae43acc7ace5b1564f
Contents?: true
Size: 1.53 KB
Versions: 2
Compression:
Stored size: 1.53 KB
Contents
'use strict'; var esj = require('escomplex-js'); var expect = require('expect.js'); var glob = require('glob'); var path = require('path'); var fs = require('fs'); var options = { 'max_complexity': 6, 'max_cyclomatic_density': 110, 'max_dependencies': 10, 'maintainability': 100 }; describe('Code complexity', function () { // find all source files var codeFiles = glob.sync('lib/**/*.js'); // loop through them codeFiles.forEach(function (file) { describe(file, function () { // get the absolute path file = path.resolve(file); // read the file var code = fs.readFileSync(file, 'utf-8'); // calculate the complexity var analysis = esj.analyse(code); // Halstead // TO-DO: analysis.aggregate.halstead // Complexity describe('functions', function () { var fns = analysis.functions || []; fns.forEach(function (fn) { it(fn.name, function () { // TO-DO: add checks on fn.halstead expect(fn.cyclomatic).to.be.lessThan(options.max_complexity); expect(fn.cyclomaticDensity).to.be.lessThan(options.max_cyclomatic_density); }); }); }); // prevent too many dependencies it('dependencies', function () { expect(analysis.dependencies.length).to.be.lessThan(options.max_dependencies); }); // keep functions maintainable it('maintainability', function () { expect(analysis.maintainability).to.be.greaterThan(options.maintainability); }); }); }); });
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
less-execjs-2.6.0.4 | lib/less/js/image-size/specs/complexity.js |
less-execjs-2.6.0.3 | lib/less/js/image-size/specs/complexity.js |