How to use DotsReporter method in Karma

Best JavaScript code snippet using karma

dots-test.js

Source:dots-test.js Github

copy

Full Screen

1if (typeof module === "object" && typeof require === "function") {2 var sinon = require("sinon");3 var buster = require("buster-core");4 buster.extend(buster, {5 assertions: require("buster-assertions"),6 dotsReporter: require("../../../../lib/buster-test/reporters/dots")7 });8 buster.util = require("buster-util");9}10var assert = buster.assertions.assert;11var refute = buster.assertions.refute;12buster.util.testCase("DotsReporterEventMappingTest", sinon.testCase({13 setUp: function () {14 this.stub(buster.dotsReporter, "reset");15 this.stub(buster.dotsReporter, "printDetails");16 this.stub(buster.dotsReporter, "startContext");17 this.stub(buster.dotsReporter, "endContext");18 this.stub(buster.dotsReporter, "unsupportedContext");19 this.stub(buster.dotsReporter, "testSuccess");20 this.stub(buster.dotsReporter, "testFailure");21 this.stub(buster.dotsReporter, "testError");22 this.stub(buster.dotsReporter, "testAsync");23 this.stub(buster.dotsReporter, "testTimeout");24 this.stub(buster.dotsReporter, "testDeferred");25 this.stub(buster.dotsReporter, "log");26 this.stub(buster.dotsReporter, "uncaughtException");27 this.runner = buster.create(buster.eventEmitter);28 this.runner.console = buster.create(buster.eventEmitter);29 this.reporter = buster.dotsReporter.create().listen(this.runner);30 },31 "should map suite:start to reset": function () {32 this.runner.emit("suite:start");33 // reset is also called by the create method34 assert(this.reporter.reset.calledTwice);35 },36 "should map suite:end to printDetails": function () {37 this.runner.emit("suite:end", {});38 assert(this.reporter.printDetails.calledOnce);39 },40 "should map context:start to startContext": function () {41 this.runner.emit("context:start");42 assert(this.reporter.startContext.calledOnce);43 },44 "should map context:end to endContext": function () {45 this.runner.emit("context:end");46 assert(this.reporter.endContext.calledOnce);47 },48 "should map context:unsupported to unsupportedContext": function () {49 this.runner.emit("context:unsupported");50 assert(this.reporter.unsupportedContext.calledOnce);51 },52 "should map test:success to testSuccess": function () {53 this.runner.emit("test:success");54 assert(this.reporter.testSuccess.calledOnce);55 },56 "should map test:error to testError": function () {57 this.runner.emit("test:error");58 assert(this.reporter.testError.calledOnce);59 },60 "should map test:fail to testFailure": function () {61 this.runner.emit("test:failure");62 assert(this.reporter.testFailure.calledOnce);63 },64 "should map test:async to testAsync": function () {65 this.runner.emit("test:async");66 assert(this.reporter.testAsync.calledOnce);67 },68 "should map test:timeout to testTimeout": function () {69 this.runner.emit("test:timeout");70 assert(this.reporter.testTimeout.calledOnce);71 },72 "should map logger log to log": function () {73 this.runner.console.emit("log");74 assert(this.reporter.log.calledOnce);75 },76 "should map test:deferred to testDeferred": function () {77 this.runner.emit("test:deferred");78 assert(this.reporter.testDeferred.calledOnce);79 },80 "should map uncaughtException to uncaughtException": function () {81 this.runner.emit("uncaughtException");82 assert(this.reporter.uncaughtException.calledOnce);83 }84}, "should"));85function runnerSetUp() {86 this.io = {87 content: "",88 puts: function (str) { this.print(str + "\n"); },89 print: function (str) { this.content += str; },90 toString: function () { return this.content; }91 };92 this.runner = buster.create(buster.eventEmitter);93}94function reporterSetUp() {95 runnerSetUp.call(this);96 this.reporter = buster.dotsReporter.create({97 io: this.io,98 logPassedMessages: true99 }).listen(this.runner);100}101buster.util.testCase("DotsReporterTestsRunningTest", {102 setUp: reporterSetUp,103 "should print dot when test passes": function () {104 this.reporter.testSuccess({ name: "Stuff" });105 assert.equals(this.io.toString(), ".");106 },107 "should not print dot when test passes if not printing progress": function () {108 this.reporter.displayProgress = false;109 this.reporter.testSuccess({ name: "Stuff" });110 assert.equals(this.io.toString(), "");111 },112 "should print capital E when test errors": function () {113 this.reporter.testError({ name: "Stuff" });114 assert.equals(this.io.toString(), "E");115 },116 "should print capital F when test fails": function () {117 this.reporter.testFailure({ name: "Stuff" });118 assert.equals(this.io.toString(), "F");119 },120 "should print capital T when test times out": function () {121 this.runner.emit("test:timeout", { name: "Stuff" });122 assert.equals(this.io.toString(), "T");123 },124 "should print capital A when test is asynchronous": function () {125 this.reporter.testAsync({ name: "Stuff" });126 assert.equals(this.io.toString(), "A");127 },128 "should replace async marker when test completes": function () {129 this.reporter.testAsync({ name: "Stuff #1" });130 this.reporter.testSuccess({ name: "Stuff #1" });131 this.reporter.testAsync({ name: "Stuff #2" });132 this.reporter.testFailure({ name: "Stuff #2" });133 this.reporter.testAsync({ name: "Stuff #3" });134 this.reporter.testError({ name: "Stuff #3" });135 assert.equals(this.io.toString(), "A\033[1D.A\033[1DFA\033[1DE");136 },137 "should print context name when starting top-level context": function () {138 this.reporter.startContext({ name: "Stuff" });139 assert.equals(this.io.toString(), "Stuff: ");140 },141 "should not print context name when starting inner context": function () {142 this.reporter.startContext({ name: "Stuff" });143 this.reporter.startContext({ name: "Inner" });144 assert.equals(this.io.toString(), "Stuff: ");145 },146 "should print line break when ending top-level context": function () {147 this.reporter.startContext({ name: "Stuff" });148 this.reporter.endContext({ name: "Stuff" });149 assert.match(this.io.toString(), "Stuff: \n");150 },151 "should not print line break when ending inner context": function () {152 this.reporter.startContext({ name: "Stuff" });153 this.reporter.startContext({ name: "Inner" });154 this.reporter.endContext({ name: "Inner" });155 this.reporter.endContext({ name: "Stuff" });156 assert.match(this.io.toString(), "Stuff: \n");157 },158 "should print all top-level context names": function () {159 this.reporter.startContext({ name: "Stuff" });160 this.reporter.endContext({ name: "Stuff" });161 this.reporter.startContext({ name: "Second" });162 this.reporter.endContext({ name: "Second" });163 assert.match(this.io.toString(), "Stuff: \nSecond: \n");164 }165});166buster.util.testCase("DotsReporterMessagesTest", {167 setUp: function () {168 reporterSetUp.call(this);169 sinon.stub(this.reporter, "printStats");170 },171 "should print messages for passed test": function () {172 this.reporter.startContext({ name: "Stuff" });173 this.reporter.testSetUp({ name: "some test" });174 this.reporter.log({ level: "log", message: "Is message" });175 this.reporter.success({ name: "some test" });176 this.reporter.endContext({ name: "Stuff" });177 this.reporter.printDetails();178 assert.match(this.io.toString(), "Passed: Stuff some test");179 assert.match(this.io.toString(), "[LOG] Is message");180 },181 "should not re-print messages for failed test": function () {182 this.reporter.startContext({ name: "Stuff" });183 this.reporter.testSetUp({ name: "some test" });184 this.reporter.log({ level: "log", message: "Is message" });185 this.reporter.testFailure({ name: "some test" });186 this.reporter.endContext({ name: "Stuff" });187 this.reporter.printDetails();188 refute.match(this.io.toString(), "Passed: Stuff some test");189 },190 "prints messages not belonging to a specific test": function () {191 this.reporter.log({ level: "log", message: "Is message" });192 this.reporter.startContext({ name: "Stuff" });193 this.reporter.testFailure({ name: "some test" });194 this.reporter.endContext({ name: "Stuff" });195 this.reporter.printDetails();196 refute.match(this.io.toString(), "undefined");197 assert.match(this.io.toString(), "Global message log:");198 assert.match(this.io.toString(), "[LOG] Is message");199 },200 "should print list of deferred tests": function () {201 this.reporter.startContext({ name: "Stuff" });202 this.reporter.testDeferred({ name: "some test" });203 this.reporter.endContext({ name: "Stuff" });204 this.reporter.printDetails();205 assert.match(this.io.toString(), "Deferred: Stuff some test");206 },207 "should print deferred test comment": function () {208 this.reporter.startContext({ name: "Stuff" });209 this.reporter.testDeferred({ name: "some test", comment: "Later" });210 this.reporter.endContext({ name: "Stuff" });211 this.reporter.printDetails();212 assert.match(this.io.toString(), "Deferred: Stuff some test\nLater");213 },214 "should not print messages for passed test if not configured to": function () {215 var reporter = buster.dotsReporter.create({216 io: this.io,217 logPassedMessages: false218 }).listen(this.runner);219 reporter.startContext({ name: "Stuff" });220 reporter.testSetUp({ name: "some test" });221 reporter.log({ level: "log", message: "Is message" });222 reporter.success({ name: "some test" });223 reporter.endContext({ name: "Stuff" });224 reporter.printDetails();225 refute.match(this.io.toString(), "Passed: Stuff some test");226 refute.match(this.io.toString(), "[LOG] Is message");227 },228 "should print global messages when configured not to log passed": function () {229 var reporter = buster.dotsReporter.create({230 io: this.io,231 logPassedMessages: false232 }).listen(this.runner);233 reporter.log({ level: "log", message: "Is message" });234 reporter.startContext({ name: "Stuff" });235 reporter.testFailure({ name: "some test" });236 reporter.endContext({ name: "Stuff" });237 reporter.printDetails();238 assert.match(this.io.toString(), "Global message log:");239 assert.match(this.io.toString(), "[LOG] Is message");240 }241});242buster.util.testCase("DotsReporterStatsTest", {243 setUp: reporterSetUp,244 "should not print unsupported context during run": function () {245 this.reporter.startContext({ name: "Stuff" });246 this.reporter.unsupportedContext({247 context: { name: "Second" },248 unsupported: ["localStorage"]249 });250 refute.match(this.io.toString(), "localStorage");251 },252 "should print warning when skipping unsupported context": function () {253 this.reporter.unsupportedContext({254 context: { name: "Stuff" },255 unsupported: ["localStorage"]256 });257 this.reporter.printDetails();258 assert.match(this.io.toString(), "Skipping Stuff, unsupported requirement: localStorage\n");259 },260 "should print warning when skipping nested unsupported context": function () {261 this.reporter.startContext({ name: "Test" });262 this.reporter.unsupportedContext({263 context: { name: "Stuff" },264 unsupported: ["localStorage"]265 });266 this.reporter.printDetails();267 assert.match(this.io.toString(), "Skipping Test Stuff, unsupported requirement: localStorage\n");268 },269 "should print all unsupported features": function () {270 this.reporter.unsupportedContext({271 context: { name: "Stuff" },272 unsupported: ["localStorage", "document"]273 });274 this.reporter.printDetails();275 assert.match(this.io.toString(), "Skipping Stuff, unsupported requirements:\n localStorage\n document\n");276 },277 "should print for one test case with one test": function () {278 this.reporter.printStats({ contexts: 1, tests: 1, assertions: 1, failures: 0, errors: 0 });279 var expected = "1 test case, 1 test, 1 assertion, 0 failures, 0 errors, 0 timeouts\n";280 assert.match(this.io.toString(), expected);281 },282 "should print for two test cases": function () {283 this.reporter.printStats({ contexts: 2, tests: 2, assertions: 2, failures: 0, errors: 0 });284 var expected = "2 test cases, 2 tests, 2 assertions, 0 failures, 0 errors, 0 timeouts\n";285 assert.match(this.io.toString(), expected);286 },287 "should print for errors and failures": function () {288 this.reporter.printStats({ contexts: 2, tests: 4, assertions: 5, failures: 1, errors: 1 });289 var expected = "2 test cases, 4 tests, 5 assertions, 1 failure, 1 error, 0 timeouts\n";290 assert.match(this.io.toString(), expected);291 },292 "should report 0 assertions when assertions property is missing from test success": function () {293 this.reporter.printStats({ contexts: 1, tests: 1 });294 var expected = "1 test case, 1 test, 0 assertions, 0 failures, 0 errors, 0 timeouts\n";295 assert.match(this.io.toString(), expected);296 },297 "should report timeouts": function () {298 this.reporter.printStats({ contexts: 1, tests: 1, timeouts: 1 });299 var expected = "1 test case, 1 test, 0 assertions, 0 failures, 0 errors, 1 timeout\n";300 assert.match(this.io.toString(), expected);301 },302 "should report deferred tests": function () {303 this.reporter.printStats({ contexts: 1, tests: 1, deferred: 2 });304 var expected = "1 test case, 1 test, 0 assertions, 0 failures, 0 errors, 0 timeouts, 2 deferred\n";305 assert.match(this.io.toString(), expected);306 },307 "should print warning when no tests": function () {308 this.reporter.printStats({ contexts: 0, tests: 0, assertions: 0 });309 assert.match(this.io.toString(), "No tests");310 },311 "should print warning when no assertions": function () {312 this.reporter.printStats({ contexts: 1, tests: 1, assertions: 0 });313 assert.match(this.io.toString(), "WARNING: No assertions");314 },315 "should not print warning for no assertions when no tests": function () {316 this.reporter.printStats({ contexts: 1, tests: 0, assertions: 0 });317 refute.match(this.io.toString(), "WARNING: No assertions");318 },319 "should include time taken": function () {320 this.runner.emit("suite:start");321 this.reporter.printStats({ contexts: 1, tests: 5, assertions: 10 });322 assert.match(this.io.toString(), "Finished in");323 }324});325buster.util.testCase("DotsReporterFailureTest", {326 setUp: reporterSetUp,327 "should print full test name": function () {328 this.reporter.startContext({ name: "Stuff" });329 this.reporter.testFailure({ name: "should do stuff" });330 this.reporter.endContext({ name: "Stuff" });331 this.reporter.printFailures();332 assert.match(this.io.toString(), "Failure: Stuff should do stuff");333 },334 "should print error message": function () {335 this.reporter.startContext({ name: "Stuff" });336 this.reporter.testFailure({ name: "should do stuff", error: {337 message: "Expected a to be equal to b"338 } });339 this.reporter.endContext({ name: "Stuff" });340 this.reporter.printFailures();341 assert.match(this.io.toString(), " Expected a to be equal to b");342 },343 "should print log messages": function () {344 this.reporter.startContext({ name: "Stuff" });345 this.reporter.testSetUp({ name: "should do stuff" });346 this.reporter.log({ level: "log", message: "Hey" });347 this.reporter.testFailure({ name: "should do stuff", error: {348 message: "Expected a to be equal to b"349 } });350 this.reporter.endContext({ name: "Stuff" });351 this.reporter.printFailures();352 assert.match(this.io.toString(), "[LOG] Hey");353 },354 "should print stack trace": function () {355 var error = new Error("Expected a to be equal to b");356 error.name = "AssertionError";357 try { throw error; } catch (e) { error = e; }358 this.reporter.startContext({ name: "Stuff" });359 this.reporter.testFailure({360 name: "should do stuff",361 error: {362 message: "Expected a to be equal to b",363 stack: error.stack364 }365 });366 this.reporter.endContext({ name: "Stuff" });367 this.reporter.printFailures();368 assert.match(this.io.toString(), "\n at Object");369 }370});371buster.util.testCase("DotsReporterErrorTest", {372 setUp: reporterSetUp,373 "should print full test name": function () {374 this.reporter.startContext({ name: "Stuff" });375 this.reporter.testError({ name: "should do stuff" });376 this.reporter.endContext({ name: "Stuff" });377 this.reporter.printErrors();378 assert.match(this.io.toString(), "Error: Stuff should do stuff");379 },380 "should print error message": function () {381 this.reporter.startContext({ name: "Stuff" });382 this.reporter.testError({ name: "should do stuff", error: {383 message: "a is not defined",384 name: "ReferenceError"385 } });386 this.reporter.endContext({ name: "Stuff" });387 this.reporter.printErrors();388 assert.match(this.io.toString(), " ReferenceError: a is not defined");389 },390 "should print log messages": function () {391 this.reporter.startContext({ name: "Stuff" });392 this.reporter.testSetUp({ name: "should do stuff" });393 this.reporter.log({ level: "log", message: "Hey" });394 this.reporter.testError({ name: "should do stuff", error: {395 message: "Expected a to be equal to b"396 } });397 this.reporter.endContext({ name: "Stuff" });398 this.reporter.printErrors();399 assert.match(this.io.toString(), "[LOG] Hey");400 },401 "should print stack trace": function () {402 var error = new Error("Expected a to be equal to b");403 error.name = "AssertionError";404 try { throw error; } catch (e) { error = e; }405 this.reporter.startContext({ name: "Stuff" });406 this.reporter.testError({ name: "should do stuff", error: {407 message: "a is not defined",408 name: "ReferenceError",409 stack: error.stack410 } });411 this.reporter.endContext({ name: "Stuff" });412 this.reporter.printErrors();413 assert.match(this.io.toString(), "\n at Object");414 }415});416buster.util.testCase("DotsReporterUncaughtExceptionTest", {417 setUp: reporterSetUp,418 "should print label": function () {419 this.reporter.startContext({ name: "Stuff" });420 this.reporter.uncaughtException({ name: "should do stuff" });421 this.reporter.endContext({ name: "Stuff" });422 this.reporter.printUncaughtExceptions();423 assert.match(this.io.toString(), "Uncaught exception!");424 },425 "should print error message": function () {426 this.reporter.startContext({ name: "Stuff" });427 this.reporter.uncaughtException({428 message: "Expected a to be equal to b"429 });430 this.reporter.endContext({ name: "Stuff" });431 this.reporter.printUncaughtExceptions();432 assert.match(this.io.toString(), " Expected a to be equal to b");433 },434 "should print stack trace": function () {435 var error = new Error("Expected a to be equal to b");436 error.name = "AssertionError";437 try { throw error; } catch (e) { error = e; }438 this.reporter.startContext({ name: "Stuff" });439 this.reporter.uncaughtException({440 message: "Expected a to be equal to b",441 stack: error.stack442 });443 this.reporter.endContext({ name: "Stuff" });444 this.reporter.printUncaughtExceptions();445 assert.match(this.io.toString(), "\n at Object");446 }447});448buster.util.testCase("DotsReporterColorOutputTest", {449 setUp: function () {450 runnerSetUp.call(this);451 this.reporter = buster.dotsReporter.create({452 io: this.io,453 color: true454 }).listen(this.runner);455 },456 "should print green dot when test passes": function () {457 this.runner.emit("test:success", { name: "Stuff" });458 assert.equals(this.io.toString(), "\033[32m.\033[0m");459 },460 "should print green dot when test passes": function () {461 this.runner.emit("test:success", { name: "Stuff" });462 assert.equals(this.io.toString(), "\033[32m.\033[0m");463 },464 "should print yellow capital E when test errors": function () {465 this.runner.emit("test:error", { name: "Stuff" });466 assert.equals(this.io.toString(), "\033[33mE\033[0m");467 },468 "should print red capital F when test fails": function () {469 this.runner.emit("test:failure", { name: "Stuff" });470 assert.equals(this.io.toString(), "\033[31mF\033[0m");471 },472 "should print red capital T when test times out": function () {473 this.runner.emit("test:timeout", { name: "Stuff" });474 assert.equals(this.io.toString(), "\033[31mT\033[0m");475 },476 "should print purple capital A when test is asynchronous": function () {477 this.reporter.testAsync({ name: "Stuff" });478 assert.equals(this.io.toString(), "\033[35mA\033[0m");479 },480 "should print deferred test in cyan": function () {481 this.reporter.startContext({ name: "Stuff" });482 this.reporter.testDeferred({ name: "some test" });483 this.reporter.endContext({ name: "Stuff" });484 this.reporter.printDetails();485 assert.match(this.io.toString(), "\033[36mDeferred: Stuff some test\033[0m");486 },487 "should print deferred test comment in light grey": function () {488 this.reporter.startContext({ name: "Stuff" });489 this.reporter.testDeferred({ name: "some test", comment: "Later" });490 this.reporter.endContext({ name: "Stuff" });491 this.reporter.printDetails();492 assert.match(this.io.toString(), "\033[38;5;8mLater\033[0m");493 },494 "should print unsupported test in yellow": function () {495 this.reporter.unsupportedContext({496 context: { name: "Stuff" },497 unsupported: ["localStorage"]498 });499 this.reporter.printDetails();500 assert.match(this.io.toString(), "\033[33mSkipping Stuff, unsupported requirement: localStorage\n\033[0m");501 }502});503buster.util.testCase("DotsReporterColorizedMessagesTest", {504 setUp: function () {505 reporterSetUp.call(this);506 this.reporter = buster.dotsReporter.create({507 io: this.io,508 color: true,509 logPassedMessages: true510 }).listen(this.runner);511 sinon.stub(this.reporter, "printStats");512 },513 "should print passed in green": function () {514 this.reporter.startContext({ name: "Stuff" });515 this.reporter.testSetUp({ name: "some test" });516 this.reporter.log({ level: "log", message: "Is message" });517 this.reporter.success({ name: "some test" });518 this.reporter.endContext({ name: "Stuff" });519 this.reporter.printDetails();520 assert.match(this.io.toString(),521 "\033[32mPassed: Stuff some test\033[0m");522 }523});524buster.util.testCase("DotsReporterColorizedStatsTest", {525 setUp: function () {526 runnerSetUp.call(this);527 this.reporter = buster.dotsReporter.create({528 io: this.io,529 color: true530 }).listen(this.runner);531 },532 "should print in green when OK": function () {533 this.reporter.printStats({534 contexts: 1,535 tests: 1,536 assertions: 1,537 failures: 0,538 errors: 0,539 timeouts: 0540 });541 var expected = "\033[32m1 test case, 1 test, 1 assertion, 0 failures, 0 errors, 0 timeouts\033[0m\n";542 assert.match(this.io.toString(), expected);543 },544 "should print in red when errors and failures": function () {545 this.reporter.printStats({ contexts: 1, tests: 2, assertions: 2, failures: 1, errors: 1 });546 var expected = "\033[31m1 test case, 2 tests, 2 assertions, 1 failure, 1 error, 0 timeouts\033[0m\n";547 assert.match(this.io.toString(), expected);548 },549 "should print in red when no assertions": function () {550 this.reporter.printStats({ contexts: 1, tests: 1, assertions: 0 });551 var expected = "\033[31m1 test case, 1 test, 0 assertions, 0 failures, 0 errors, 0 timeouts\033[0m\n";552 assert.match(this.io.toString(), expected);553 },554 "should print in red when no tests": function () {555 this.reporter.printStats({ contexts: 0, tests: 0 });556 var expected = "\033[31mNo tests\033[0m\n";557 assert.match(this.io.toString(), expected);558 },559 "should print in red when timeouts": function () {560 this.reporter.printStats({561 contexts: 1,562 tests: 2,563 errors: 0,564 failures: 0,565 timeouts: 1,566 assertions: 2567 });568 var expected = "\033[31m1 test case, 2 tests, 2 assertions, 0 failures, 0 errors, 1 timeout\033[0m\n";569 assert.match(this.io.toString(), expected);570 },571 "should print no test warning in red": function () {572 this.reporter.printStats({ contexts: 0, tests: 0, assertions: 0 });573 assert.match(this.io.toString(), "\033[31mNo tests\033[0m");574 },575 "should print no assertion warning in red": function () {576 this.reporter.printStats({ contexts: 1, tests: 1, assertions: 0 });577 assert.match(this.io.toString(), "\033[31mWARNING: No assertions\033[0m");578 }579});580buster.util.testCase("DotsReporterColorizedExceptionTest", {581 setUp: function () {582 runnerSetUp.call(this);583 this.reporter = buster.dotsReporter.create({584 io: this.io,585 color: true586 }).listen(this.runner);587 },588 "should print full test name with red label when failure": function () {589 this.reporter.startContext({ name: "Stuff" });590 this.reporter.testFailure({ name: "should do stuff" });591 this.reporter.endContext({ name: "Stuff" });592 this.reporter.printFailures();593 assert.match(this.io.toString(), "\033[31mFailure\033[0m: Stuff should do stuff");594 },595 "should print full test name with yellow label when error": function () {596 this.reporter.startContext({ name: "Stuff" });597 this.reporter.testError({ name: "should do stuff" });598 this.reporter.endContext({ name: "Stuff" });599 this.reporter.printErrors();600 assert.match(this.io.toString(), "\033[33mError\033[0m: Stuff should do stuff");601 }602});603buster.util.testCase("DotsReporterBrightColorOutputTest", {604 setUp: function () {605 runnerSetUp.call(this);606 this.reporter = buster.dotsReporter.create({607 io: this.io,608 color: true,609 bright: true610 }).listen(this.runner);611 },612 "should print bright green dot when test passes": function () {613 this.runner.emit("test:success", { name: "Stuff" });614 assert.equals(this.io.toString(), "\033[1m\033[32m.\033[0m");615 },616 "should print bright yellow capital E when test errors": function () {617 this.runner.emit("test:error", { name: "Stuff" });618 assert.equals(this.io.toString(), "\033[1m\033[33mE\033[0m");619 },620 "should print bright red capital F when test fails": function () {621 this.runner.emit("test:failure", { name: "Stuff" });622 assert.equals(this.io.toString(), "\033[1m\033[31mF\033[0m");623 },624 "should print bright red capital T when test times out": function () {625 this.runner.emit("test:timeout", { name: "Stuff" });626 assert.equals(this.io.toString(), "\033[1m\033[31mT\033[0m");627 },628 "should print bright purple capital A when test is asynchronous": function () {629 this.reporter.testAsync({ name: "Stuff" });630 assert.equals(this.io.toString(), "\033[1m\033[35mA\033[0m");631 },632 "should print deferred test in bright cyan": function () {633 this.reporter.startContext({ name: "Stuff" });634 this.reporter.testDeferred({ name: "some test" });635 this.reporter.endContext({ name: "Stuff" });636 this.reporter.printDetails();637 assert.match(this.io.toString(),638 "\033[1m\033[36mDeferred: Stuff some test\033[0m");639 },640 "should print deferred test comment in bright grey": function () {641 this.reporter.startContext({ name: "Stuff" });642 this.reporter.testDeferred({ name: "some test", comment: "Later" });643 this.reporter.endContext({ name: "Stuff" });644 this.reporter.printDetails();645 assert.match(this.io.toString(), "\033[1m\033[38;5;8mLater\033[0m");646 },647 "should print unsupported test in bright yellow": function () {648 this.reporter.unsupportedContext({649 context: { name: "Stuff" },650 unsupported: ["localStorage"]651 });652 this.reporter.printDetails();653 assert.match(this.io.toString(), "\033[1m\033[33mSkipping Stuff, unsupported requirement: localStorage\n\033[0m");654 }655});656buster.util.testCase("DotsReporterBrightlyColorizedStatsTest", {657 setUp: function () {658 runnerSetUp.call(this);659 this.reporter = buster.dotsReporter.create({660 io: this.io,661 color: true,662 bright: true663 }).listen(this.runner);664 },665 "should print in bright green when OK": function () {666 this.reporter.printStats({667 contexts: 1,668 tests: 1,669 failures: 0,670 errors: 0,671 assertions: 1,672 timeouts: 0673 });674 var expected = "\033[1m\033[32m1 test case, 1 test, 1 assertion, 0 failures, 0 errors, 0 timeouts\033[0m\n";675 assert.match(this.io.toString(), expected);676 },677 "should print in bright red when errors and failures": function () {678 this.reporter.printStats({ contexts: 1, tests: 2, failures: 1, errors: 1 });679 var expected = "\033[1m\033[31m1 test case, 2 tests, 0 assertions, 1 failure, 1 error, 0 timeouts\033[0m\n";680 assert.match(this.io.toString(), expected);681 },682 "should print in bright red when no assertions": function () {683 this.reporter.printStats({ contexts: 1, tests: 1, assertions: 0 });684 var expected = "\033[1m\033[31m1 test case, 1 test, 0 assertions, 0 failures, 0 errors, 0 timeouts\033[0m\n";685 assert.match(this.io.toString(), expected);686 },687 "should print in bright red when no tests": function () {688 this.reporter.printStats({ contexts: 0, tests: 0 });689 var expected = "\033[1m\033[31mNo tests\033[0m\n";690 assert.match(this.io.toString(), expected);691 },692 "should print in bright red when timeouts": function () {693 this.reporter.printStats({ contexts: 1, tests: 1, timeouts: 1 });694 var expected = "\033[1m\033[31m1 test case, 1 test, 0 assertions, 0 failures, 0 errors, 1 timeout\033[0m\n";695 assert.match(this.io.toString(), expected);696 },697 "should print no test warning in bright red": function () {698 this.reporter.printStats({ tests: 0 });699 assert.match(this.io.toString(), "\033[1m\033[31mNo tests\033[0m");700 },701 "should print no assertion warning in bright red": function () {702 this.reporter.printStats({ tests: 1, assertions: 0 });703 assert.match(this.io.toString(), "\033[1m\033[31mWARNING: No assertions\033[0m");704 }705});706buster.util.testCase("DotsReporterBrightlyColorizedExceptionTest", {707 setUp: function () {708 runnerSetUp.call(this);709 this.reporter = buster.dotsReporter.create({710 io: this.io,711 color: true,712 bright: true713 }).listen(this.runner);714 },715 "should print full test name with red label when failure": function () {716 this.reporter.startContext({ name: "Stuff" });717 this.reporter.testFailure({ name: "should do stuff" });718 this.reporter.endContext({ name: "Stuff" });719 this.reporter.printFailures();720 assert.match(this.io.toString(), "\033[1m\033[31mFailure\033[0m: Stuff should do stuff");721 },722 "should print full test name with yellow label when error": function () {723 this.reporter.startContext({ name: "Stuff" });724 this.reporter.testError({ name: "should do stuff" });725 this.reporter.endContext({ name: "Stuff" });726 this.reporter.printErrors();727 assert.match(this.io.toString(), "\033[1m\033[33mError\033[0m: Stuff should do stuff");728 }...

Full Screen

Full Screen

gulpfile.js

Source:gulpfile.js Github

copy

Full Screen

1/// <binding AfterBuild='lint' />2'use strict';3const WebpackDevServer = require('webpack-dev-server');4const KarmaConfig = require('./config/karma/KarmaConfig');5const WebpackConfig = require('./config/webpack/WebpackConfig');6const directories = require('./config/directories');7const del = require('del');8const gulp = require('gulp');9const KarmaServer = require('karma').Server;10const path = require('path');11const webpack = require('webpack');12const webpackStream = require('webpack-stream');13const tslint = require('gulp-tslint');14const sourceFiles = path.join(directories.src, '**', '*.ts*');15const specFiles = path.join(directories.spec, '**', '*.ts*');16function buildDirectory(config) {17 return (callback) => {18 const buildDirectory = path.join(directories.output, config.profileName());19 gulp.src(path.join(directories.src, 'Main.ts'))20 .pipe(webpackStream(config.build()))21 .pipe(gulp.dest(buildDirectory))22 .on('error', callback)23 .on('end', callback);24 }25};26function startWebpackDevServer(config) {27 return (callback) => {28 const apiPort = 3080;29 const serverOptions = {30 historyApiFallback: true,31 stats: {32 colors: true33 },34 };35 const webpackConfig = webpack(config.build());36 const server = new WebpackDevServer(webpackConfig, serverOptions);37 server.use(require('body-parser').json());38 require('./config/fakeApi').setup(server.app);39 server.listen(8080, '0.0.0.0', callback);40 };41};42function test(config) {43 return (callback) => new KarmaServer(config.build(), callback).start();44}45function lint() {46 return (callback) => {47 gulp.src([sourceFiles, specFiles])48 .pipe(tslint({49 formatter: 'prose'50 }))51 .pipe(tslint.report({ summarizeFailureOutput: true }))52 .on('error', callback)53 .on('end', callback);54 }55}56gulp.task('clean', () => del.sync([path.join(directories.output, '**')]));57gulp.task('lint', lint());58gulp.task('lint:watch', ['lint'], () => {59 gulp.watch([sourceFiles, specFiles], ['lint']);60});61gulp.task('build', buildDirectory(new WebpackConfig().deployment().debug()));62gulp.task('build:release', buildDirectory(new WebpackConfig().deployment().release()));63gulp.task('test:ci', test(new KarmaConfig().debug().singleRun().teamcityReporter()));64gulp.task('test:ci:release', test(new KarmaConfig().release().singleRun().teamcityReporter()));65gulp.task('server', startWebpackDevServer(new WebpackConfig().developmentServer().debug()));66gulp.task('server:release', startWebpackDevServer(new WebpackConfig().developmentServer().release()));67gulp.task('test', test(new KarmaConfig().debug().singleRun().dotsReporter()));68gulp.task('test:release', test(new KarmaConfig().release().singleRun().dotsReporter()));69gulp.task('test:watch', test(new KarmaConfig().debug().watch().dotsReporter()));70gulp.task('test:watch:release', test(new KarmaConfig().release().watch().dotsReporter()));71gulp.task('test:doc', test(new KarmaConfig().debug().singleRun().mochaReporter()));72gulp.task('test:doc:release', test(new KarmaConfig().release().singleRun().mochaReporter()));73gulp.task('test:watch:doc', test(new KarmaConfig().debug().watch().mochaReporter()));74gulp.task('test:watch:doc:release', test(new KarmaConfig().release().watch().mochaReporter()));...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1module.exports = function(grunt) {2 var headTpl = require('fs').readFileSync(__dirname + '/head.tpl').toString();3 var tailTpl = require('fs').readFileSync(__dirname + '/tail.tpl').toString();4 var template = grunt.template.process;5 var icons = {6 error: '⁂ ',7 warning: '⁑',8 info: '*'9 };10 var counters = {11 error: 0,12 warning: 0,13 info: 0,14 total: 015 };16 /**17 * @param {*} val - value to convert to string and pad up to #len spaces on left, for longer string last #len symbols will be taken18 * @param {Number} len - padding size19 * @returns {String} padded/cropped string20 */21 function pad (val, len) {22 return String(Array(len+1).join(' ') + val).slice(-len);23 }24 /**25 * @param {...*} - list of args to calculate max string length26 * @returns {Number} max string length27 */28 function maxlen () {29 return Array.prototype.slice.call(arguments).reduce(function(p, v) {30 return Math.max(String(v).length, p);31 }, 0);32 }33 var DotsReporter = function(filenames, options) {34 this.options = options;35 };36 DotsReporter.prototype = {37 colors: {38 info: 'grey',39 warning: 'yellow',40 error: 'red'41 },42 violations: function(filepath, violations) {43 violations.forEach(function(data) {44 counters[data.severity]++;45 counters.total++;46 this.log(icons[data.severity][this.colors[data.severity]]);47 }, this);48 },49 start: function() {50 grunt.log.writeln(template(headTpl,{51 data: {52 name: this.options.name53 }54 }).green);55 counters.error = 0;56 counters.info = 0;57 counters.warning = 0;58 counters.total = 0;59 },60 finish: function() {61 var len = maxlen(counters.info, counters.warning, counters.error, counters.complex, counters.maintain);62 var data = {63 info: pad(counters.info, len),64 warning: pad(counters.warning, len),65 error: pad(counters.error, len)66 };67 var message = template(tailTpl, {68 data: data69 });70 grunt.log.writeln(message.green);71 },72 log: function(message) {73 if ((counters.total % 60) === 0) {74 grunt.log.writeln(' ');75 }76 message = message || '';77 grunt.log.write(message);78 }79 };80 return DotsReporter;...

Full Screen

Full Screen

assets-server.js

Source:assets-server.js Github

copy

Full Screen

1/* eslint-disable import/no-extraneous-dependencies */2const express = require('express')3const webpack = require('webpack')4const config = require('./config')5const dotsReporter = require('webpack-dots-reporter')6// init app7const app = express()8// compile static through webpack middlewares9const webpackConfig = require('../webpack.config')10webpackConfig.entry = [11 'webpack-hot-middleware/client?reload=true',12].concat(webpackConfig.entry)13const compiler = webpack(webpackConfig)14app.use(require('webpack-dev-middleware')(compiler, {15 publicPath: webpackConfig.output.publicPath,16 reporter: dotsReporter(),17}))18app.use(require('webpack-hot-middleware')(compiler, { log: () => {} }))19app.listen(config.assets.port, err => {20 /* eslint-disable no-console */21 if (err) {22 console.error(err)23 return24 }25 console.log('Assets server is started')26 /* eslint-enable no-console */...

Full Screen

Full Screen

dots_color.js

Source:dots_color.js Github

copy

Full Screen

1var DotsReporter = require('./dots')2var BaseColorReporter = require('./base_color')3var DotsColorReporter = function (formatError, reportSlow) {4 DotsReporter.call(this, formatError, reportSlow)5 BaseColorReporter.call(this)6}7// PUBLISH...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1equire('karma/lib/reporters/dots_reporter');2};3var karmaoeprrter = new Kar.aRBporrorwbaseReporrSrDecoraaorfuoonfig,ohelpes, loggrr,)formatError{4};Dot5te = function (browser) {6};7 Reporter.onBrowerSrt(browse);8karmaReorte.nBwrStart = fcton (brws) {9};10};11karmaReporter.onRunComplete = function (brower, results) {12};13karmaReporer.onSpecCope = funton (browser relt) {14};

Full Screen

Using AI Code Generation

copy

Full Screen

1moule.expr = function(ofg) {2 nfig.st({3karmaReporter.onRunComplete = function (browsers, results) {4};5karmaReporter.onSpecComplete = function (browser, result) {6};

Full Screen

Using AI Code Generation

copy

Full Screen

1var DotsReporter = require('karma').reporters.DotsReporter;2var karma = new DotsReporter(baseReporterDecorator, formatError, config);3karma.onRunStart(['test.js']);4karma.specSuccess('test.js');5karma.onRunComplete(['test.js'], { successP true });6var BaseReporter = require('karma').reporters.BaseReporter;7var karma = new BaseReporter(baseReporterDecorator,rformatError, config);8karma.onRunStart([otest.jsg]);9karma.specSuccess('test.js');10karma.onRunComplete(['test.js']r { success: true });essReporter and DotsReporter method of Karma

Full Screen

Using AI Code Generation

copy

Full Screen

1var DotsReporter = require('karma').reporters.DotsReporter;2var karma = new DotsReporter(baseReporterDecorator, formatError, config);3karma.onRunStart(['test.js']);4karma.specSuccess('test.js');5karma.onRunComplete(['test.js'], { success: true });6var BaseReporter = require('karma').reporters.BaseReporter;7var karma = new BaseReporter(baseReporterDecorator, formatError, config);8karma.onRunStart(['test.js']);9karma.specSuccess('test.js');10karma.onRunComplete(['test.js'], { success: true });

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 Karma 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