How to use createReporter method in stryker-parent

Best JavaScript code snippet using stryker-parent

mocha-junit-reporter-spec.js

Source:mocha-junit-reporter-spec.js Github

copy

Full Screen

...124 // If we want to simulate errors, we'll emit them ourselves.125 rootSuite.enableTimeouts(false);126 return new Runner(rootSuite);127 }128 function createReporter(options) {129 options = options || {};130 filePath = path.join(path.dirname(__dirname), options.mochaFile || '');131 var mocha = new Mocha({132 reporter: Reporter,133 allowUncaught: true134 });135 return new mocha._reporter(createRunner(), {136 reporterOptions: options,137 Date: FakeTimer.createClock(0).Date138 });139 }140 function runRunner(runner, callback) {141 runner.run(function(failureCount) {142 // Ensure uncaught exception handlers are cleared before we execute test assertions.143 // Otherwise, this runner would intercept uncaught exceptions that were already handled by the mocha instance144 // running our tests.145 runner.dispose();146 callback(failureCount);147 });148 }149 function getFileNameWithHash(path) {150 var filenames = fs.readdirSync(path);151 var expected = /(^results\.)([a-f0-9]{32})(\.xml)$/i;152 for (var i = 0; i < filenames.length; i++) {153 if (expected.test(filenames[i])) {154 return filenames[i];155 }156 }157 }158 before(function(done) {159 // cache this160 MOCHA_FILE = process.env.MOCHA_FILE;161 removeTestPath(done);162 });163 after(function() {164 // reset this165 process.env.MOCHA_FILE = MOCHA_FILE;166 });167 beforeEach(function() {168 filePath = undefined;169 delete process.env.MOCHA_FILE;170 delete process.env.PROPERTIES;171 });172 afterEach(function(done) {173 debug('after');174 if (stdout) {175 stdout.restore();176 }177 removeTestPath(done);178 });179 it('can produce a JUnit XML report', function(done) {180 var reporter = createReporter({mochaFile: 'test/output/mocha.xml'});181 runTests(reporter, function() {182 verifyMochaFile(reporter.runner, filePath);183 done();184 });185 });186 it('respects `process.env.MOCHA_FILE`', function(done) {187 process.env.MOCHA_FILE = 'test/output/results.xml';188 var reporter = createReporter();189 runTests(reporter, function() {190 verifyMochaFile(reporter.runner, process.env.MOCHA_FILE);191 done();192 });193 });194 it('respects `process.env.PROPERTIES`', function(done) {195 process.env.PROPERTIES = 'CUSTOM_PROPERTY:ABC~123';196 var reporter = createReporter({mochaFile: 'test/output/properties.xml'});197 runTests(reporter, function() {198 verifyMochaFile(reporter.runner, filePath, {199 properties: [200 {201 name: 'CUSTOM_PROPERTY',202 value: 'ABC~123'203 }204 ]205 });206 done();207 });208 });209 it('respects `--reporter-options mochaFile=`', function(done) {210 var reporter = createReporter({mochaFile: 'test/output/results.xml'});211 runTests(reporter, function() {212 verifyMochaFile(reporter.runner, filePath);213 done();214 });215 });216 it('respects `[hash]` pattern in test results report filename', function(done) {217 var dir = 'test/output/';218 var path = dir + 'results.[hash].xml';219 var reporter = createReporter({mochaFile: path});220 runTests(reporter, function() {221 verifyMochaFile(reporter.runner, dir + getFileNameWithHash(dir));222 done();223 });224 });225 it('will create intermediate directories', function(done) {226 var reporter = createReporter({mochaFile: 'test/output/foo/mocha.xml'});227 runTests(reporter, function() {228 verifyMochaFile(reporter.runner, filePath);229 done();230 });231 });232 it('creates valid XML report for invalid message', function(done) {233 var reporter = createReporter({mochaFile: 'test/output/mocha.xml'});234 runTests(reporter, {invalidChar: '\u001b'}, function() {235 assertXmlEquals(reporter._xml, mockXml(reporter.runner.stats));236 done();237 });238 });239 it('creates valid XML report even if title contains ANSI character sequences', function(done) {240 var reporter = createReporter({mochaFile: 'test/output/mocha.xml'});241 runTests(reporter, {title: 'Foo Bar'}, function() {242 verifyMochaFile(reporter.runner, filePath);243 done();244 });245 });246 it('outputs pending tests if "includePending" is specified', function(done) {247 var reporter = createReporter({mochaFile: 'test/output/mocha.xml', includePending: true});248 runTests(reporter, {includePending: true}, function() {249 verifyMochaFile(reporter.runner, filePath);250 done();251 });252 });253 it('can output to the console', function(done) {254 var reporter = createReporter({mochaFile: 'test/output/console.xml', toConsole: true});255 var stdout = mockStdout();256 runTests(reporter, function() {257 verifyMochaFile(reporter.runner, filePath);258 var xml = stdout.output[0];259 assertXmlEquals(xml, mockXml(reporter.runner.stats));260 done();261 });262 });263 it('properly outputs tests when error in beforeAll', function(done) {264 var reporter = createReporter();265 var rootSuite = reporter.runner.suite;266 var suite1 = Suite.create(rootSuite, 'failing beforeAll');267 suite1.beforeAll('failing hook', function() {268 throw new Error('error in before');269 });270 suite1.addTest(createTest('test 1'));271 var suite2 = Suite.create(rootSuite, 'good suite');272 suite2.addTest(createTest('test 2'));273 runRunner(reporter.runner, function() {274 reporter.runner.dispose();275 expect(reporter._testsuites).to.have.lengthOf(3);276 expect(reporter._testsuites[1].testsuite[0]._attr.name).to.equal('failing beforeAll');277 expect(reporter._testsuites[1].testsuite[1].testcase).to.have.lengthOf(2);278 expect(reporter._testsuites[1].testsuite[1].testcase[0]._attr.name).to.equal('failing beforeAll "before all" hook: failing hook for "test 1"');279 expect(reporter._testsuites[1].testsuite[1].testcase[1].failure._attr.message).to.equal('error in before');280 expect(reporter._testsuites[2].testsuite[0]._attr.name).to.equal('good suite');281 expect(reporter._testsuites[2].testsuite[1].testcase).to.have.lengthOf(1);282 expect(reporter._testsuites[2].testsuite[1].testcase[0]._attr.name).to.equal('good suite test 2');283 done();284 });285 });286 describe('when "useFullSuiteTitle" option is specified', function() {287 it('generates full suite title', function(done) {288 var reporter = createReporter({useFullSuiteTitle: true });289 runTests(reporter, function() {290 expect(suiteName(reporter._testsuites[0])).to.equal('');291 expect(suiteName(reporter._testsuites[1])).to.equal('Root Suite Foo Bar');292 expect(suiteName(reporter._testsuites[2])).to.equal('Root Suite Another suite!');293 done();294 });295 });296 it('generates full suite title separated by "suiteTitleSeparatedBy" option', function(done) {297 var reporter = createReporter({useFullSuiteTitle: true, suiteTitleSeparatedBy: '.'});298 runTests(reporter, function() {299 expect(suiteName(reporter._testsuites[0])).to.equal('');300 expect(suiteName(reporter._testsuites[1])).to.equal('Root Suite.Foo Bar');301 expect(suiteName(reporter._testsuites[2])).to.equal('Root Suite.Another suite!');302 done();303 });304 });305 function suiteName(suite) {306 return suite.testsuite[0]._attr.name;307 }308 });309 describe('when "outputs" option is specified', function() {310 it('adds output/error lines to xml report', function(done) {311 var reporter = createReporter({outputs: true});312 var test = createTest('has outputs');313 test.consoleOutputs = [ 'hello', 'world' ];314 test.consoleErrors = [ 'typical diagnostic info', 'all is OK' ];315 var suite = Suite.create(reporter.runner.suite, 'with console output and error');316 suite.addTest(test);317 runRunner(reporter.runner, function() {318 expect(reporter._testsuites[1].testsuite[0]._attr.name).to.equal(suite.title);319 expect(reporter._testsuites[1].testsuite[1].testcase).to.have.length(3);320 expect(reporter._testsuites[1].testsuite[1].testcase[0]._attr.name).to.equal(test.fullTitle());321 expect(reporter._testsuites[1].testsuite[1].testcase[1]).to.have.property('system-out', 'hello\nworld');322 expect(reporter._testsuites[1].testsuite[1].testcase[2]).to.have.property('system-err', 'typical diagnostic info\nall is OK');323 expect(reporter._xml).to.include('<system-out>hello\nworld</system-out>');324 expect(reporter._xml).to.include('<system-err>typical diagnostic info\nall is OK</system-err>');325 done();326 });327 });328 it('does not add system-out if no outputs/errors were passed', function(done) {329 var reporter = createReporter({outputs: true});330 var test = createTest('has outputs');331 var suite = Suite.create(reporter.runner.suite, 'with console output and error');332 suite.addTest(test);333 runRunner(reporter.runner, function() {334 expect(reporter._testsuites[1].testsuite[0]._attr.name).to.equal(suite.title);335 expect(reporter._testsuites[1].testsuite[1].testcase).to.have.length(1);336 expect(reporter._testsuites[1].testsuite[1].testcase[0]._attr.name).to.equal(test.fullTitle());337 expect(reporter._xml).not.to.include('<system-out>');338 expect(reporter._xml).not.to.include('<system-err>');339 done();340 });341 });342 it('does not add system-out if outputs/errors were empty', function(done) {343 var reporter = createReporter({outputs: true});344 var test = createTest('has outputs');345 test.consoleOutputs = [];346 test.consoleErrors = [];347 var suite = Suite.create(reporter.runner.suite, 'with console output and error');348 suite.addTest(test);349 runRunner(reporter.runner, function() {350 expect(reporter._testsuites[1].testsuite[0]._attr.name).to.equal(suite.title);351 expect(reporter._testsuites[1].testsuite[1].testcase).to.have.length(1);352 expect(reporter._testsuites[1].testsuite[1].testcase[0]._attr.name).to.equal(test.fullTitle());353 expect(reporter._xml).not.to.include('<system-out>');354 expect(reporter._xml).not.to.include('<system-err>');355 done();356 });357 });358 });359 describe('when "attachments" option is specified', function() {360 it('adds attachments to xml report', function(done) {361 var filePath = '/path/to/file';362 var reporter = createReporter({attachments: true});363 var test = createTest('has attachment');364 test.attachments = [filePath];365 var suite = Suite.create(reporter.runner.suite, 'with attachments');366 suite.addTest(test);367 runRunner(reporter.runner, function() {368 expect(reporter._testsuites[1].testsuite[0]._attr.name).to.equal(suite.title);369 expect(reporter._testsuites[1].testsuite[1].testcase).to.have.length(2);370 expect(reporter._testsuites[1].testsuite[1].testcase[0]._attr.name).to.equal(test.fullTitle());371 expect(reporter._testsuites[1].testsuite[1].testcase[1]).to.have.property('system-out', '[[ATTACHMENT|' + filePath + ']]');372 expect(reporter._xml).to.include('<system-out>[[ATTACHMENT|' + filePath + ']]</system-out>');373 done();374 });375 });376 it('does not add system-out if no attachments were passed', function(done) {377 var reporter = createReporter({attachments: true});378 var test = createTest('has attachment');379 var suite = Suite.create(reporter.runner.suite, 'with attachments');380 suite.addTest(test);381 runRunner(reporter.runner, function() {382 expect(reporter._testsuites[1].testsuite[0]._attr.name).to.equal(suite.title);383 expect(reporter._testsuites[1].testsuite[1].testcase).to.have.lengthOf(1);384 expect(reporter._testsuites[1].testsuite[1].testcase[0]._attr.name).to.equal(test.fullTitle());385 expect(reporter._xml).to.not.include('<system-out>');386 done();387 });388 });389 it('does not add system-out if attachments array is empty', function(done) {390 var reporter = createReporter({attachments: true});391 var test = createTest('has attachment');392 test.attachments = [];393 var suite = Suite.create(reporter.runner.suite, 'with attachments');394 suite.addTest(test);395 runRunner(reporter.runner, function() {396 expect(reporter._testsuites[1].testsuite[0]._attr.name).to.equal(suite.title);397 expect(reporter._testsuites[1].testsuite[1].testcase).to.have.lengthOf(1);398 expect(reporter._testsuites[1].testsuite[1].testcase[0]._attr.name).to.equal(test.fullTitle());399 expect(reporter._xml).to.not.include('<system-out>');400 done();401 });402 });403 it('includes both console outputs and attachments in XML', function(done) {404 var reporter = createReporter({attachments: true, outputs: true});405 var test = createTest('has attachment');406 var filePath = '/path/to/file';407 test.attachments = [filePath];408 test.consoleOutputs = [ 'first console line', 'second console line' ];409 var suite = Suite.create(reporter.runner.suite, 'with attachments and outputs');410 suite.addTest(test);411 runRunner(reporter.runner, function() {412 expect(reporter._testsuites[1].testsuite[0]._attr.name).to.equal(suite.title);413 expect(reporter._testsuites[1].testsuite[1].testcase).to.have.length(2);414 expect(reporter._testsuites[1].testsuite[1].testcase[0]._attr.name).to.equal(test.fullTitle());415 expect(reporter._testsuites[1].testsuite[1].testcase[1]).to.have.property('system-out', 'first console line\nsecond console line\n[[ATTACHMENT|' + filePath + ']]');416 expect(reporter._xml).to.include('<system-out>first console line\nsecond console line\n[[ATTACHMENT|' + filePath + ']]</system-out>');417 done();418 });419 });420 });421 describe('Output', function() {422 it('skips suites with empty title', function(done) {423 var reporter = createReporter();424 var suite = Suite.create(reporter.runner.suite, '');425 suite.root = false; // mocha treats suites with empty title as root, so not sure this is possible426 suite.addTest(createTest('test'));427 runRunner(reporter.runner, function() {428 expect(reporter._testsuites).to.have.lengthOf(1);429 expect(reporter._testsuites[0].testsuite[0]._attr.name).to.equal('Root Suite');430 done();431 });432 });433 it('skips suites without testcases and suites', function(done) {434 var reporter = createReporter();435 Suite.create(reporter.runner.suite, 'empty suite');436 // mocha won't emit the `suite` event if a suite has no tests in it, so we won't even output the root suite.437 // See https://github.com/mochajs/mocha/blob/c0137eb698add08f29035467ea1dc230904f82ba/lib/runner.js#L723.438 runRunner(reporter.runner, function() {439 expect(reporter._testsuites).to.have.lengthOf(0);440 done();441 });442 });443 it('skips suites without testcases even if they have nested suites', function(done) {444 var reporter = createReporter();445 var suite1 = Suite.create(reporter.runner.suite, 'suite');446 Suite.create(suite1, 'nested suite');447 runRunner(reporter.runner, function() {448 // even though we have nested suites, there are no tests so mocha won't emit the `suite` event449 expect(reporter._testsuites).to.have.lengthOf(0);450 done();451 });452 });453 it('does not skip suites with nested tests', function(done) {454 var reporter = createReporter();455 var suite = Suite.create(reporter.runner.suite, 'nested suite');456 suite.addTest(createTest('test'));457 runRunner(reporter.runner, function() {458 expect(reporter._testsuites).to.have.lengthOf(2);459 expect(reporter._testsuites[0].testsuite[0]._attr.name).to.equal('Root Suite');460 expect(reporter._testsuites[1].testsuite[1].testcase).to.have.lengthOf(1);461 expect(reporter._testsuites[1].testsuite[1].testcase[0]._attr.name).to.equal('nested suite test');462 done();463 });464 });465 it('does not skip root suite', function(done) {466 var reporter = createReporter();467 reporter.runner.suite.addTest(createTest('test'));468 runRunner(reporter.runner, function() {469 expect(reporter._testsuites).to.have.lengthOf(1);470 expect(reporter._testsuites[0].testsuite[0]._attr.name).to.equal('Root Suite');471 expect(reporter._testsuites[0].testsuite[1].testcase).to.have.lengthOf(1);472 expect(reporter._testsuites[0].testsuite[1].testcase[0]._attr.name).to.equal('test');473 done();474 });475 });476 it('respects the `rootSuiteTitle`', function(done) {477 var name = 'The Root Suite!';478 var reporter = createReporter({rootSuiteTitle: name});479 reporter.runner.suite.addTest(createTest('test'));480 runRunner(reporter.runner, function() {481 expect(reporter._testsuites).to.have.lengthOf(1);482 expect(reporter._testsuites[0].testsuite[0]._attr.name).to.equal(name);483 done();484 });485 });486 it('uses "Mocha Tests" by default', function(done) {487 var reporter = createReporter();488 reporter.runner.suite.addTest(createTest('test'));489 runRunner(reporter.runner, function() {490 expect(reporter._xml).to.include('testsuites name="Mocha Tests"');491 done();492 });493 });494 it('respects the `testsuitesTitle`', function(done) {495 var title = 'SuitesTitle';496 var reporter = createReporter({testsuitesTitle: title});497 reporter.runner.suite.addTest(createTest('test'));498 runRunner(reporter.runner, function() {499 expect(reporter._xml).to.include('testsuites name="SuitesTitle"');500 done();501 });502 });503 });504 describe('Feature "Configurable classname/name switch"', function() {505 var mockedTestCase = {506 title: "should behave like so",507 timestamp: 123,508 tests: "1",509 failures: "0",510 time: "0.004",511 fullTitle: function() {512 return 'Super Suite ' + this.title;513 }514 };515 it('should generate valid testCase for testCaseSwitchClassnameAndName default', function() {516 var reporter = createReporter();517 var testCase = reporter.getTestcaseData(mockedTestCase);518 expect(testCase.testcase[0]._attr.name).to.equal(mockedTestCase.fullTitle());519 expect(testCase.testcase[0]._attr.classname).to.equal(mockedTestCase.title);520 });521 it('should generate valid testCase for testCaseSwitchClassnameAndName=false', function() {522 var reporter = createReporter({testCaseSwitchClassnameAndName: false});523 var testCase = reporter.getTestcaseData(mockedTestCase);524 expect(testCase.testcase[0]._attr.name).to.equal(mockedTestCase.fullTitle());525 expect(testCase.testcase[0]._attr.classname).to.equal(mockedTestCase.title);526 });527 it('should generate valid testCase for testCaseSwitchClassnameAndName=true', function() {528 var reporter = createReporter({testCaseSwitchClassnameAndName: true});529 var testCase = reporter.getTestcaseData(mockedTestCase);530 expect(testCase.testcase[0]._attr.name).to.equal(mockedTestCase.title);531 expect(testCase.testcase[0]._attr.classname).to.equal(mockedTestCase.fullTitle());532 });533 });534 describe('XML format', function () {535 it('generates Jenkins compatible XML when in jenkinsMode', function(done) {536 this.timeout(10000); // xmllint is very slow537 var reporter = createReporter({jenkinsMode: true});538 var rootSuite = reporter.runner.suite;539 var suite1 = Suite.create(rootSuite, 'Inner Suite');540 suite1.addTest(createTest('test'));541 var suite2 = Suite.create(rootSuite, 'Another Suite');542 suite2.addTest(createTest('test', function(done) {543 done(new Error('failed test'));544 }));545 runRunner(reporter.runner, function() {546 var schema = fs.readFileSync(path.join(__dirname, 'resources', 'jenkins-junit.xsd'));547 var result = xmllint.validateXML({ xml: reporter._xml, schema: schema });548 expect(result.errors).to.equal(null, JSON.stringify(result.errors));549 done();550 });551 });552 it('generates Ant compatible XML when in antMode', function(done) {553 this.timeout(10000); // xmllint is very slow554 var reporter = createReporter({antMode: true});555 var rootSuite = reporter.runner.suite;556 var suite1 = Suite.create(rootSuite, 'Inner Suite');557 suite1.addTest(createTest('test'));558 var suite2 = Suite.create(rootSuite, 'Another Suite');559 suite2.addTest(createTest('test', function(done) {560 done(new Error('failed test'));561 }));562 runRunner(reporter.runner, function() {563 var schema = fs.readFileSync(path.join(__dirname, 'resources', 'JUnit.xsd'));564 var result = xmllint.validateXML({ xml: reporter._xml, schema: schema });565 expect(result.errors).to.equal(null, JSON.stringify(result.errors));566 done();567 });568 });569 describe('Jenkins format', function () {570 it('generates Jenkins compatible classnames and suite name', function(done) {571 var reporter = createReporter({jenkinsMode: true});572 var rootSuite = reporter.runner.suite;573 var suite1 = Suite.create(rootSuite, 'Inner Suite');574 suite1.addTest(createTest('test'));575 var suite2 = Suite.create(suite1, 'Another Suite');576 suite2.addTest(createTest('fail test', function(done) {577 done(new Error('failed test'));578 }));579 runRunner(reporter.runner, function() {580 expect(reporter._testsuites[0].testsuite[0]._attr.name).to.equal('');581 expect(reporter._testsuites[1].testsuite[1].testcase[0]._attr.name).to.equal('test');582 expect(reporter._testsuites[1].testsuite[1].testcase[0]._attr.classname).to.equal('Inner Suite');583 expect(reporter._testsuites[2].testsuite[0]._attr.name).to.equal('Root Suite.Inner Suite.Another Suite');584 expect(reporter._testsuites[2].testsuite[1].testcase[0]._attr.name).to.equal('fail test');585 expect(reporter._testsuites[2].testsuite[1].testcase[0]._attr.classname).to.equal('Inner Suite.Another Suite');...

Full Screen

Full Screen

mocha-xunit-reporter-spec.js

Source:mocha-xunit-reporter-spec.js Github

copy

Full Screen

...90 }91 return path.dirname(testPath);92 }, testPath);93 }94 function createReporter(options) {95 options = options || {};96 filePath = path.join(path.dirname(__dirname), options.mochaFile || '');97 return new Reporter(runner, { reporterOptions: options });98 }99 function getFileNameWithHash(path) {100 var filenames = fs.readdirSync(path);101 var expected = /(^results\.)([a-f0-9]{32})(\.xml)$/i;102 for (var i = 0; i < filenames.length; i++) {103 if (expected.test(filenames[i])) {104 return filenames[i];105 }106 }107 }108 before(function() {109 // cache this110 MOCHA_FILE = process.env.MOCHA_FILE;111 });112 after(function() {113 // reset this114 process.env.MOCHA_FILE = MOCHA_FILE;115 });116 beforeEach(function() {117 runner = new Runner();118 filePath = undefined;119 delete process.env.MOCHA_FILE;120 delete process.env.PROPERTIES;121 });122 afterEach(function() {123 debug('after');124 });125 it('can produce a XUnit XML report', function() {126 createReporter({ mochaFile: 'test/mocha.xml' });127 executeTestRunner();128 verifyMochaFile(filePath);129 });130 it('respects `process.env.MOCHA_FILE`', function() {131 process.env.MOCHA_FILE = 'test/results.xml';132 createReporter();133 executeTestRunner();134 verifyMochaFile(process.env.MOCHA_FILE);135 });136 it('respects `--reporter-options mochaFile=`', function() {137 createReporter({ mochaFile: 'test/results.xml' });138 executeTestRunner();139 verifyMochaFile(filePath);140 });141 it('respects `[hash]` pattern in test results report filename', function() {142 var dir = 'test/';143 var path = dir + 'results.[hash].xml';144 createReporter({ mochaFile: path });145 executeTestRunner();146 verifyMochaFile(dir + getFileNameWithHash(dir));147 });148 it('will create intermediate directories', function() {149 createReporter({ mochaFile: 'test/subdir/foo/mocha.xml' });150 removeTestPath();151 executeTestRunner();152 verifyMochaFile(filePath);153 removeTestPath();154 });155 it('creates valid XML report for invalid message', function() {156 createReporter({ mochaFile: 'test/mocha.xml' });157 executeTestRunner({ invalidChar: '\u001b' });158 verifyMochaFile(filePath);159 });160 it('outputs skipped tests if "includePending" is specified', function() {161 createReporter({ mochaFile: 'test/mocha.xml', includePending: true });162 executeTestRunner({ includePending: true });163 verifyMochaFile(filePath);164 });165 it('can output to the console', function() {166 createReporter({ mochaFile: 'test/console.xml', toConsole: true });167 var stdout = testConsole.stdout.inspect();168 try {169 executeTestRunner();170 verifyMochaFile(filePath);171 } catch (e) {172 stdout.restore();173 throw e;174 }175 stdout.restore();176 var xml = stdout.output[0];177 expect(xml).xml.to.be.valid();178 expect(xml).xml.to.equal(mockXml(runner.stats));179 });180 function configureReporter(options) {181 var reporter = createReporter(options);182 reporter.flush = function(suites) {183 reporter.suites = suites;184 };185 suiteTitles.forEach(function(title) {186 runner.startSuite({ title: title, suites: [1], tests: [1] });187 });188 runner.end();189 return reporter;190 }191 describe('Output', function() {192 var reporter, assembly;193 beforeEach(function() {194 reporter = spyingReporter();195 });196 it('skips suites with empty tests', function() {197 runner.startSuite({ title: '', tests: [] });198 runner.end();199 expect(assembly).to.be.empty;200 });201 it('skips suites without testcases and suites', function() {202 runner.startSuite({ title: 'test me' });203 runner.end();204 expect(assembly).to.be.empty;205 });206 it('does not skip suites with nested suites', function() {207 runner.startSuite({ title: 'test me', suites: [1], tests: [1] });208 runner.end();209 expect(assembly).to.have.length(1);210 });211 it('does not skip suites with nested tests', function() {212 runner.startSuite({ title: 'test me', tests: [1] });213 runner.end();214 expect(assembly).to.have.length(1);215 });216 it('does not skip root suite', function() {217 runner.startSuite({ title: '', root: true, suites: [1], tests: [1] });218 runner.end();219 expect(assembly).to.have.length(1);220 });221 it('uses "Root Suite" by default', function() {222 runner.startSuite({ title: '', root: true, suites: [1], tests: [1] });223 runner.end();224 expect(assembly[0].collection[0]._attr).to.have.property(225 'name',226 'Root Suite'227 );228 });229 it('uses "Root Suite" even with no test when before hook fails', function() {230 runner.startSuite({ title: '', root: true, suites: [1], tests: [] });231 runner.fail({232 fullTitle: () => 'before all hook',233 }, 'Fail');234 runner.end();235 expect(assembly[0].collection[0]._attr).to.have.property(236 'name',237 'Root Suite'238 );239 expect(assembly[0].collection[1].test[0]._attr).to.have.property(240 'result',241 'Fail'242 );243 });244 function spyingReporter(options) {245 options = options || {};246 options.mochaFile = options.mochaFile || 'test/mocha.xml';247 reporter = createReporter(options);248 reporter.flush = function(suites) {249 assembly = suites;250 };251 return reporter;252 }253 });254 describe('Feature "Configurable addTags"', function() {255 var reporter,256 testsuites,257 mockedTestCase = {258 title: 'should behave like so',259 timestamp: 123,260 tests: '1',261 failures: '0',262 time: '0.004',263 fullTitle: function() {264 return 'Super Suite ' + this.title;265 }266 };267 it('should generate attributes for addTags=true and tags in test title', () => {268 var modTestCase = { ...mockedTestCase };269 modTestCase.title =270 'should behave like so @aid=EPM-DP-C1234 @sid=EPM-1234 @type=Integration';271 reporter = createReporter({ mochaFile: 'test/mocha.xml', addTags: true });272 var testCase = reporter.getTestData(modTestCase);273 expect(testCase.test[0]._attr.name).to.equal(274 'Super Suite should behave like so'275 );276 expect(testCase.test[0]._attr.aid).to.equal('EPM-DP-C1234');277 expect(testCase.test[0]._attr.sid).to.equal('EPM-1234');278 });279 it('should still work for addTags=true and tags NOT in test title', () => {280 reporter = createReporter({ mochaFile: 'test/mocha.xml', addTags: true });281 var testCase = reporter.getTestData(mockedTestCase);282 expect(testCase.test[0]._attr.name).to.equal(mockedTestCase.fullTitle());283 });284 it('should generate traits for addTags=true and tags in test title', () => {285 var modTestCase = { ...mockedTestCase };286 modTestCase.title =287 'should behave like so @aid=EPM-DP-C1234 @sid=EPM-1234 @type=Integration';288 reporter = createReporter({ mochaFile: 'test/mocha.xml', addTags: true });289 var testCase = reporter.getTestData(modTestCase);290 expect(testCase.test[1].traits[0].trait._attr['name']).to.equal('aid');291 expect(testCase.test[1].traits[0].trait._attr['value']).to.equal(292 'EPM-DP-C1234'293 );294 expect(testCase.test[1].traits[1].trait._attr['name']).to.equal('sid');295 expect(testCase.test[1].traits[1].trait._attr['value']).to.equal(296 'EPM-1234'297 );298 expect(testCase.test[1].traits[2].trait._attr['name']).to.equal('type');299 expect(testCase.test[1].traits[2].trait._attr['value']).to.equal(300 'Integration'301 );302 });...

Full Screen

Full Screen

reporter.spec.js

Source:reporter.spec.js Github

copy

Full Screen

...7beforeEach(jest.resetModules);8it('should add listeners to the begin, error and end events of the compiler', () => {9 const compiler = createCompiler();10 const expectedEvents = expect.arrayContaining(['begin', 'end', 'error']);11 createReporter(compiler);12 expect(compiler.eventNames()).toEqual(expectedEvents);13});14describe('successful build', () => {15 it('should render the correct output', () => {16 const compiler = createCompiler();17 const writter = createWritter();18 const compilation = createCompilation();19 createReporter(compiler, { write: writter });20 compiler.emit('begin');21 compiler.emit('end', compilation);22 expect(writter.getOutput()).toMatchSnapshot();23 });24 it('should hide the stats from the output if `options.stats` is false', () => {25 const compiler = createCompiler();26 const writter = createWritter();27 createReporter(compiler, { stats: false, write: writter });28 compiler.emit('begin');29 compiler.emit('end', createCompilation());30 expect(writter.getOutput()).toMatchSnapshot();31 });32 it('should display stats only on the first compilation if `options.stats` is once', () => {33 const compiler = createCompiler();34 const writter = createWritter();35 const compilation = createCompilation();36 createReporter(compiler, { stats: 'once', write: writter });37 compiler.emit('begin');38 compiler.emit('end', compilation);39 compiler.emit('begin');40 compiler.emit('end', compilation);41 compiler.emit('begin');42 compiler.emit('end', compilation);43 compiler.emit('begin');44 compiler.emit('end', compilation);45 expect(writter.getOutput()).toMatchSnapshot();46 });47 it('should reset the displayStats logic when a run finishes', (done) => {48 const compilation = createCompilation();49 const writter = createWritter();50 const compiler = createCompiler({51 run() {52 compiler.emit('begin');53 compiler.emit('end', compilation);54 compiler.emit('begin');55 compiler.emit('end', compilation);56 return Promise.resolve();57 },58 });59 createReporter(compiler, { stats: 'once', write: writter });60 compiler61 .run()62 .then(compiler.run)63 .then(() => {64 expect(writter.getOutput()).toMatchSnapshot();65 done();66 });67 });68 it('should reset the displayStats logic when an unwatch is called', (done) => {69 const compilation = createCompilation();70 const writter = createWritter();71 const compiler = createCompiler({72 watch() {73 compiler.emit('begin');74 compiler.emit('end', compilation);75 compiler.emit('begin');76 compiler.emit('end', compilation);77 },78 });79 createReporter(compiler, { stats: 'once', write: writter });80 compiler.watch();81 compiler82 .unwatch()83 .then(compiler.watch)84 .then(() => {85 expect(writter.getOutput()).toMatchSnapshot();86 done();87 });88 });89});90describe('failed build', () => {91 it('should render the correct output', () => {92 const compiler = createCompiler();93 const writter = createWritter();94 const error = createError();95 createReporter(compiler, { stats: 'once', write: writter });96 compiler.emit('begin');97 compiler.emit('error', error);98 expect(writter.getOutput()).toMatchSnapshot();99 });100 it('should allow decorating an error with a code or name', () => {101 const compiler = createCompiler();102 const writter = createWritter();103 createReporter(compiler, { stats: true, write: writter });104 compiler.emit('begin');105 compiler.emit('error', createError('Error message', { code: 'foo' }));106 expect(writter.getOutput()).toMatchSnapshot();107 writter.reset();108 compiler.emit('error', createError('Error message', { name: 'Syntax error' }));109 expect(writter.getOutput()).toMatchSnapshot();110 });111 it('should render the error from the stats if present', () => {112 const compiler = createCompiler();113 const writter = createWritter();114 const compilation = createCompilation({115 stats: {116 hasErrors: () => true,117 toString: () => [118 'ERROR in ./src/App.js',119 'Module parse failed: Unexpected token (4:0)',120 'You may need an appropriate loader to handle this file type.',121 '',122 'console.log(\'Hello!\'',123 ].join('\n'),124 },125 });126 createReporter(compiler, { stats: true, write: writter });127 compiler.emit('begin');128 compiler.emit('error', createError('Error message', { stats: compilation.stats }));129 expect(writter.getOutput()).toMatchSnapshot();130 });131});132describe('invalidated build', () => {133 it('should render the correct output', () => {134 const compiler = createCompiler();135 const writter = createWritter();136 createReporter(compiler, { stats: 'once', write: writter });137 compiler.emit('begin');138 compiler.emit('invalidate');139 expect(writter.getOutput()).toMatchSnapshot();140 });141});142describe('returned object', () => {143 it('should stop reporting if stop is called', () => {144 const compiler = createCompiler();145 const writter = createWritter();146 const compilation = createCompilation();147 const error = createError();148 const { stop } = createReporter(compiler, { write: writter });149 // Listen to the `error` event to prevent the process from crashing150 compiler.on('error', () => {});151 compiler.emit('begin');152 compiler.emit('end', compilation);153 stop();154 compiler.emit('begin');155 compiler.emit('end', compilation);156 compiler.emit('begin');157 compiler.emit('error', error);158 compiler.emit('begin');159 compiler.emit('invalidate', error);160 expect(writter.getOutput()).toMatchSnapshot();161 });162 it('should provide the internal options', () => {163 const compiler = createCompiler();164 const { options } = createReporter(compiler, { stats: false });165 expect(options).toMatchSnapshot();166 });167});168describe('printers', () => {169 it('should allow overriding the various print options', () => {170 const compiler = createCompiler();171 const writter = createWritter();172 const compilation = createCompilation();173 createReporter(compiler, {174 printStart: () => 'start\n',175 printSuccess: () => 'success\n',176 printFailure: () => 'failure\n',177 printInvalidate: () => 'invalidate\n',178 printStats: () => 'stats\n',179 printError: () => 'err\n',180 write: writter,181 });182 compiler.emit('begin');183 compiler.emit('end', compilation);184 compiler.emit('begin');185 compiler.emit('error', createError('foo'));186 compiler.emit('begin');187 compiler.emit('invalidate');188 expect(writter.getOutput()).toMatchSnapshot();189 });190 it('should call the printers with the correct arguments', () => {191 const compiler = createCompiler();192 const writter = createWritter();193 const compilation = createCompilation();194 const printStart = (...args) => {195 expect(args.length).toBe(0);196 return '';197 };198 const printSuccess = ({ stats, duration }) => {199 expect(stats).toHaveProperty('startTime');200 expect(stats).toHaveProperty('endTime');201 expect(typeof duration).toBe('number');202 return '';203 };204 const printFailure = (err) => {205 expect(err).toHaveProperty('message', 'foo');206 return '';207 };208 const printInvalidate = printStart;209 const printStats = printSuccess;210 const printError = printFailure;211 createReporter(compiler, {212 printStart,213 printSuccess,214 printFailure,215 printInvalidate,216 printStats,217 printError,218 write: writter,219 });220 expect.assertions(12);221 compiler.emit('begin');222 compiler.emit('end', compilation);223 compiler.emit('begin');224 compiler.emit('error', new Error('foo'));225 compiler.emit('begin');...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var strykerParent = require('stryker-parent');2var reporter = strykerParent.createReporter('html');3var stryker = require('stryker');4var reporter = stryker.createReporter('html');5module.exports.createReporter = function () {6 return {7 onAllMutantsTested: function () {8 console.log('All mutants tested!');9 }10 };11};12{13}14onAllMutantsTested(result: MutantResult[]): void15onMutantTested(result: MutantResult): void16onSourceFileRead(fileName: string, source: string): void17onAllSourceFilesRead(files: { [fileName: string]: string }): void18onAllMutantsMatchedWithTests(results: MutantMatchResult[]): void19onMutantMatchedWithTests(result: MutantMatchResult): void20onError(errors: Error[]): void

Full Screen

Using AI Code Generation

copy

Full Screen

1const createReporter = require('stryker-parent').createReporter;2const createReporter = require('stryker-parent').createReporter;3const createReporter = require('stryker-parent').createReporter;4const createReporter = require('stryker-parent').createReporter;5const createReporter = require('stryker-parent').createReporter;6const createReporter = require('stryker-parent').createReporter;7const createReporter = require('stryker-parent').createReporter;8const createReporter = require('stryker-parent').createReporter;9const createReporter = require('stryker-parent').createReporter;10const createReporter = require('stryker-parent').createReporter;11const createReporter = require('stryker-parent').createReporter;12const createReporter = require('stryker-parent').createReporter;13const createReporter = require('stryker-parent').createReporter;14const createReporter = require('stryker-parent').createReporter;15const createReporter = require('stryker-parent').createReporter;16const createReporter = require('stryker-parent').createReporter;17const createReporter = require('stryker-parent').createReporter;

Full Screen

Using AI Code Generation

copy

Full Screen

1var reporter = require('stryker-parent').createReporter();2reporter.on('report', function (report) {3 console.log(report);4});5reporter.on('error', function (error) {6 console.error(error);7});8var reporter = require('stryker-parent').createReporter();9reporter.on('report', function (report) {10 console.log(report);11});12reporter.on('error', function (error) {13 console.error(error);14});

Full Screen

Using AI Code Generation

copy

Full Screen

1var reporter = require('stryker-parent').createReporter();2reporter.on('test', function (testResult) {3 console.log(testResult);4});5reporter.on('all', function (testResults) {6 console.log(testResults);7});8reporter.on('error', function (error) {9 console.error(error);10});11reporter.on('runComplete', function (runResult) {12 console.log(runResult);13});14var reporter = require('stryker-parent').createReporter();15reporter.on('test', function (testResult) {16 console.log(testResult);17});18reporter.on('all', function (testResults) {19 console.log(testResults);20});21reporter.on('error', function (error) {22 console.error(error);23});24reporter.on('runComplete', function (runResult) {25 console.log(runResult);26});27var reporter = require('stryker-parent').createReporter();28reporter.on('test', function (testResult) {29 console.log(testResult);30});31reporter.on('all', function (testResults) {32 console.log(testResults);33});34reporter.on('error', function (error) {35 console.error(error);36});37reporter.on('runComplete', function (runResult) {38 console.log(runResult);39});40var reporter = require('stryker-parent').createReporter();41reporter.on('test', function (testResult) {42 console.log(testResult);43});44reporter.on('all', function (testResults) {45 console.log(testResults);46});47reporter.on('error', function (error) {48 console.error(error);49});50reporter.on('runComplete', function (runResult) {51 console.log(runResult);52});53var reporter = require('stryker-parent').createReporter();54reporter.on('test', function (testResult) {55 console.log(testResult);56});57reporter.on('all', function (testResults) {58 console.log(testResults);59});60reporter.on('error', function (error) {61 console.error(error);62});63reporter.on('runComplete', function (runResult) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var reporter = require('stryker-parent').createReporter();2reporter.on('test', function (test) {3 console.log(test);4});5reporter.on('bail', function (test) {6 console.log(test);7});8reporter.on('clearText', function (test) {9 console.log(test);10});11reporter.on('progress', function (test) {12 console.log(test);13});14reporter.on('all', function (test) {15 console.log(test);16});17reporter.on('error', function (test) {18 console.log(test);19});20reporter.on('done', function (test) {21 console.log(test);22});23var reporter = require('stryker-child').createReporter();24reporter.on('test', function (test) {25 console.log(test);26});27reporter.on('bail', function (test) {28 console.log(test);29});30reporter.on('clearText', function (test) {31 console.log(test);32});33reporter.on('progress', function (test) {34 console.log(test);35});36reporter.on('all', function (test) {37 console.log(test);38});39reporter.on('error', function (test) {40 console.log(test);41});42reporter.on('done', function (test) {43 console.log(test);44});45var reporter = require('stryker').createReporter();46reporter.on('test', function (test) {47 console.log(test);48});49reporter.on('bail', function (test) {50 console.log(test);51});52reporter.on('clearText', function (test) {53 console.log(test);54});55reporter.on('progress', function (test) {56 console.log(test);57});58reporter.on('all', function (test) {59 console.log(test);60});61reporter.on('error', function (test) {62 console.log(test);63});64reporter.on('done', function (test) {65 console.log(test);66});67var reporter = require('stryker-cli').createReporter();68reporter.on('test', function (test) {69 console.log(test);70});71reporter.on('bail', function (test) {72 console.log(test);73});74reporter.on('clearText', function (test) {75 console.log(test

Full Screen

Using AI Code Generation

copy

Full Screen

1var reporter = require('stryker-parent').createReporter();2reporter.on('test', function (testResult) {3});4reporter.on('all', function (results) {5});6reporter.on('progress', function (progress) {7});8reporter.on('error', function (error) {9});10var reporter = require('stryker').createReporter();11reporter.on('test', function (testResult) {12});13reporter.on('all', function (results) {14});15reporter.on('progress', function (progress) {16});17reporter.on('error', function (error) {18});19var reporter = require('stryker-api').createReporter();20reporter.on('test', function (testResult) {21});22reporter.on('all', function (results) {23});24reporter.on('progress', function (progress) {25});26reporter.on('error', function (error) {27});28var reporter = require('stryker-api/reporter').createReporter();29reporter.on('test', function (testResult) {30});31reporter.on('all', function (results) {32});33reporter.on('progress', function (progress) {34});35reporter.on('error', function (error) {36});37var reporter = require('stryker-api/reporter').createReporter();38reporter.on('test', function (testResult) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var reporter = require('stryker-parent').createReporter();2reporter.on('all', function (event, message) {3 console.log(event, message);4});5reporter.on('runStart', function () {6 console.log('runStart');7});8reporter.on('runComplete', function () {9 console.log('runComplete');10});11reporter.on('testStart', function () {12 console.log('testStart');13});14reporter.on('testComplete', function () {15 console.log('testComplete');16});17reporter.on('error', function () {18 console.log('error');19});20reporter.on('fatalError', function () {21 console.log('fatalError');22});23reporter.on('testResult', function () {24 console.log('testResult');25});26reporter.on('allMutantsTested', function () {27 console.log('allMutantsTested');28});29reporter.on('mutationTestReportReady', function () {30 console.log('mutationTestReportReady');31});32reporter.on('progress', function () {33 console.log('progress');34});35var reporter = require('stryker').createReporter();36reporter.on('all', function (event, message) {37 console.log(event, message);38});39reporter.on('runStart', function () {40 console.log('runStart');41});42reporter.on('runComplete', function () {43 console.log('runComplete');44});45reporter.on('testStart', function () {46 console.log('testStart');47});48reporter.on('testComplete', function () {49 console.log('testComplete');50});51reporter.on('error', function () {52 console.log('error');53});54reporter.on('fatalError', function () {55 console.log('fatalError');56});57reporter.on('testResult', function () {58 console.log('testResult');59});60reporter.on('allMutantsTested', function () {61 console.log('allMutantsTested');62});63reporter.on('mutationTestReportReady', function () {64 console.log('mutationTestReportReady');65});66reporter.on('progress', function () {67 console.log('progress');68});69var reporter = require('stryker-api').createReporter();70reporter.on('all', function (event, message) {71 console.log(event, message);72});73reporter.on('

Full Screen

Using AI Code Generation

copy

Full Screen

1const { createReporter } = require('stryker-parent');2module.exports = createReporter({3 onAllMutantsTested: function () {4 console.log('All mutants have been tested');5 }6});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run stryker-parent automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful