UNPKG

jsinspect-plus

Version:

Detect copy-pasted and structurally similar code. Supports ES2020 standard (and most proposed features), TS and TSX files. Using Babel 8's parser.

72 lines (58 loc) 1.87 kB
const expect = require('expect.js'); const fixtures = require('../fixtures'); const helpers = require('../helpers'); const DefaultReporter = require('../../lib/reporters/default'); const Inspector = require('../../lib/inspector'); describe('DefaultReporter', function() { afterEach(function() { helpers.restoreOutput(); }); describe('constructor', function() { it('accepts an inspector as an argument', function() { const inspector = new Inspector(['']); const reporter = new DefaultReporter(inspector); expect(reporter._inspector).to.be(inspector); }); }); it('prints the summary on end', function() { helpers.captureOutput(); const inspector = new Inspector([fixtures.intersection], { threshold: 40 }); const reporter = new DefaultReporter(inspector); inspector.run(); helpers.restoreOutput(); expect(helpers.getOutput()).to.be('\nNo matches found across 1 file\n'); }); describe('given a match', function() { beforeEach(function() { helpers.captureOutput(); }); it('prints the instances', function() { const inspector = new Inspector([fixtures.intersection], { threshold: 15 }); const reporter = new DefaultReporter(inspector); inspector.removeAllListeners('end'); inspector.run(); helpers.restoreOutput(); const expected = ` ------------------------------------------------------------ Match - 2 instances spec/fixtures/intersection.js:1,5 function intersectionA(array1, array2) { array1.filter(function(n) { return array2.indexOf(n) != -1; }); } spec/fixtures/intersection.js:7,11 function intersectionB(arrayA, arrayB) { arrayA.filter(function(n) { return arrayB.indexOf(n) != -1; }); } `; expect(helpers.getOutput()).to.be(expected); }); }); });