All files / src mocha-bootstrap.ts

92.31% Statements 24/26
66.67% Branches 4/6
100% Functions 5/5
92.31% Lines 24/26
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48  1x   1x   1x   1x   51x 51x       51x       43x 43x       41x 41x 41x 41x 41x 2x   39x         141x 141x 141x   141x     1x 1x 1x 1x    
import { Report } from './reporter';
import { Token, TokenType } from 'lexer';
 
const chai = require('chai');
 
chai.use(require('chai-subset'));
 
chai.use(function(chai: any, utils: any){
	function expectValid(){
		const report = utils.flag(this, 'object') as Report;
		Iif (!report.valid){
			const actual = report.results[0].messages[0].message;
			new chai.Assertion(actual, 'Result should not contain error').to.be.undefined;
		}
		new chai.Assertion(report.valid, 'Result should be successful').to.be.true;
	}
 
	function expectInvalid(){
		const report = utils.flag(this, 'object') as Report;
		new chai.Assertion(report.valid, 'Result should be failure').to.be.false;
	}
 
	function expectError(expectedRule: string, expectedMessage: string|RegExp){
		const report = utils.flag(this, 'object') as Report;
		new chai.Assertion(report.results, 'Result should contain an error').to.have.lengthOf(1);
		const actual = report.results[0].messages[0];
		new chai.Assertion(actual.ruleId).to.be.equal(expectedRule);
		if (expectedMessage instanceof RegExp){
			new chai.Assertion(actual.message).to.match(expectedMessage);
		} else {
			new chai.Assertion(actual.message).to.be.equal(expectedMessage);
		}
	}
 
	function expectToken(expected: any){
		const actual = utils.flag(this, 'object').value as Token;
		Eif (expected.type){
			new chai.Assertion(TokenType[actual.type]).to.be.equal(TokenType[expected.type]);
		}
		new chai.Assertion(actual).to.containSubset(expected);
	}
 
	chai.Assertion.addProperty('valid', expectValid);
	chai.Assertion.addProperty('invalid', expectInvalid);
	chai.Assertion.addMethod('error', expectError);
	chai.Assertion.addMethod('token', expectToken);
});