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.

85 lines (70 loc) 2.31 kB
const expect = require('expect.js'); const fixtures = require('../fixtures'); const helpers = require('../helpers'); const BaseReporter = require('../../lib/reporters/base'); const Inspector = require('../../lib/inspector'); // A simple TestReporter for testing the BaseReporter class TestReporter extends BaseReporter { constructor(inspector) { super(inspector); this._registerSummary(); } _getOutput() {} } describe('BaseReporter', function() { let inspector, reporter; beforeEach(function() { helpers.captureOutput(); inspector = new Inspector([fixtures.intersection], { threshold: 15 }); reporter = new TestReporter(inspector); }); afterEach(function() { helpers.restoreOutput(); }); describe('constructor', function() { it('accepts an inspector as an argument', function() { expect(reporter._inspector).to.be(inspector); }); it('registers a listener for the match event', function() { expect(inspector.listeners('match')).to.have.length(1); }); }); describe('given a match', function() { it('increments the number found', function() { inspector.emit('match', {}); helpers.restoreOutput(); expect(reporter._found).to.be(1); }); it('invokes _getOutput', function() { reporter._getOutput = function(match) { return match; }; inspector.emit('match', 'invoked'); helpers.restoreOutput(); expect(helpers.getOutput()).to.be('invoked'); }); }); describe('summary', function() { it('can be printed on inspector end', function() { inspector.run(); helpers.restoreOutput(); expect(helpers.getOutput()).to.not.be(null); }); it('prints the correct results if no matches were found', function() { inspector = new Inspector([fixtures.intersection], { threshold: 40 }); const reporter = new TestReporter(inspector); inspector.run(); helpers.restoreOutput(); expect(helpers.getOutput()).to.be('\nNo matches found across 1 file\n'); }); it('prints the correct results if matches were found', function() { inspector.run(); helpers.restoreOutput(); expect(helpers.getOutput()).to.be('\n1 match found across 1 file\n'); }); }); });