Best JavaScript code snippet using root
suite.test.ts
Source:suite.test.ts
...53 reporter.endStep('passed')54 const step = { 'step': { 'attachment': { 'content': 'baz', 'name': 'attachment' }, 'status': 'failed', 'title': 'foo' } }55 reporter.addStep(step)56 reporter.onTestPass()57 reporter.onSuiteEnd(suiteEnd())58 reporter.onRunnerEnd(runnerEnd())5960 const results = getResults(outputDir)61 expect(results).toHaveLength(1)62 allureXml = results[0]63 })6465 afterAll(() => {66 clean(outputDir)67 })6869 it('should report one suite', () => {70 expect(allureXml('ns2\\:test-suite > name').text()).toEqual('A passing Suite')71 expect(allureXml('ns2\\:test-suite > title').text()).toEqual('A passing Suite')72 })7374 it('should detect passed test case', () => {75 expect(allureXml('ns2\\:test-suite > name').text()).toEqual('A passing Suite')76 expect(allureXml('test-case > name').text()).toEqual('should can do something')77 expect(allureXml('test-case').attr('status')).toEqual('passed')78 })7980 it('should detect analytics labels in test case', () => {81 expect(allureXml('test-case label[name="language"]').eq(0).attr('value')).toEqual('javascript')82 expect(allureXml('test-case label[name="framework"]').eq(0).attr('value')).toEqual('wdio')83 })8485 it('should add browser name as test argument', () => {86 expect(allureXml('test-case parameter[kind="argument"]')).toHaveLength(2)87 expect(allureXml('test-case parameter[name="browser"]').eq(0).attr('value')).toEqual('chrome-68')88 })8990 it('should add label, story, feature, severity, issue, testId labels, thread', () => {91 expect(allureXml('test-case label[name="customLabel"]').eq(0).attr('value')).toEqual('Label')92 expect(allureXml('test-case label[name="feature"]').eq(0).attr('value')).toEqual('foo')93 expect(allureXml('test-case label[name="story"]').eq(0).attr('value')).toEqual('Story')94 expect(allureXml('test-case label[name="severity"]').eq(0).attr('value')).toEqual('baz')95 expect(allureXml('test-case label[name="issue"]').eq(0).attr('value')).toEqual('1')96 expect(allureXml('test-case label[name="testId"]').eq(0).attr('value')).toEqual('2')97 expect(allureXml('test-case label[name="thread"]').eq(0).attr('value')).toEqual(testStart().cid)98 })99100 it('should add environment variable', () => {101 expect(allureXml('test-case parameter[kind="environment-variable"]')).toHaveLength(1)102 expect(allureXml('test-case parameter[name="jenkins"]').eq(0).attr('value')).toEqual('1.2.3')103 })104105 it('should start end custom step', () => {106 expect(allureXml('step > name').eq(0).text()).toEqual('bar')107 expect(allureXml('step > title').eq(0).text()).toEqual('bar')108 expect(allureXml('step').eq(0).attr('status')).toEqual('passed')109 })110111 it('should add custom step', () => {112 expect(allureXml('step > name').eq(1).text()).toEqual('foo')113 expect(allureXml('step > title').eq(1).text()).toEqual('foo')114 expect(allureXml('test-case attachment[title="attachment"]')).toHaveLength(1)115 expect(allureXml('step').eq(1).attr('status')).toEqual('failed')116 })117118 it('should add attachment', () => {119 expect(allureXml('test-case attachment[title="My attachment"]')).toHaveLength(1)120 })121122 it('should add additional argument', () => {123 expect(allureXml('test-case parameter[kind="argument"]')).toHaveLength(2)124 expect(allureXml('test-case parameter[name="os"]').eq(0).attr('value')).toEqual('osx')125 })126})127128describe('Failed tests', () => {129 let outputDir: any130 let allureXml131132 beforeEach(() => {133 outputDir = directory()134 })135136 afterEach(() => {137 clean(outputDir)138 })139140 it('should detect failed test case', () => {141 const reporter = new AllureReporter({ outputDir })142143 const runnerEvent = runnerStart()144 delete runnerEvent.capabilities.browserName145 delete runnerEvent.capabilities.version146147 reporter.onRunnerStart(runnerEvent)148 reporter.onSuiteStart(suiteStart())149 reporter.onTestStart(testStart())150 reporter.onTestFail(testFailed())151 reporter.onSuiteEnd(suiteEnd())152 reporter.onRunnerEnd(runnerEnd())153154 const results = getResults(outputDir)155 expect(results).toHaveLength(1)156 allureXml = results[0]157158 expect(allureXml('test-case > name').text()).toEqual('should can do something')159 expect(allureXml('test-case').attr('status')).toEqual('failed')160161 expect(allureXml('test-case parameter[kind="argument"]')).toHaveLength(1)162 expect(allureXml('test-case parameter[name="browser"]').eq(0).attr('value')).toEqual(testStart().cid)163 })164165 it('should detect failed test case without start event', () => {166 const reporter = new AllureReporter({ outputDir })167168 reporter.onRunnerStart(runnerStart())169 reporter.onSuiteStart(suiteStart())170 reporter.onTestFail(testFailed())171 reporter.onSuiteEnd(suiteEnd())172 reporter.onRunnerEnd(runnerEnd())173174 const results = getResults(outputDir)175 expect(results).toHaveLength(1)176 allureXml = results[0]177178 expect(allureXml('test-case > name').text()).toEqual('should can do something')179 expect(allureXml('test-case').attr('status')).toEqual('failed')180 })181182 it('should detect failed test case with multiple errors', () => {183 const reporter = new AllureReporter({ outputDir })184185 const runnerEvent = runnerStart()186 runnerEvent.config.framework = 'jasmine'187 delete runnerEvent.capabilities.browserName188 delete runnerEvent.capabilities.version189190 reporter.onRunnerStart(runnerEvent)191 reporter.onSuiteStart(suiteStart())192 reporter.onTestStart(testStart())193 reporter.onTestFail(testFailedWithMultipleErrors())194 reporter.onSuiteEnd(suiteEnd())195 reporter.onRunnerEnd(runnerEnd())196197 const results = getResults(outputDir)198 expect(results).toHaveLength(1)199200 allureXml = results[0]201 expect(allureXml('test-case > name').text()).toEqual('should can do something')202 expect(allureXml('test-case').attr('status')).toEqual('failed')203 const message = allureXml('message').text()204 const lines = message.split('\n')205 expect(lines[0]).toBe('CompoundError: One or more errors occurred. ---')206 expect(lines[1].trim()).toBe('ReferenceError: All is Dust')207 expect(lines[3].trim()).toBe('InternalError: Abandon Hope')208 })209210 it('should detect failed test case with Assertion failed from expect-webdriverIO', () => {211 const reporter = new AllureReporter({ outputDir })212213 const runnerEvent = runnerStart()214 delete runnerEvent.capabilities.browserName215 delete runnerEvent.capabilities.version216217 reporter.onRunnerStart(runnerEvent)218 reporter.onSuiteStart(suiteStart())219 reporter.onTestStart(testStart())220 reporter.onTestFail(testFailedWithAssertionErrorFromExpectWebdriverIO())221 reporter.onSuiteEnd(suiteEnd())222 reporter.onRunnerEnd(runnerEnd())223224 const results = getResults(outputDir)225 expect(results).toHaveLength(1)226 allureXml = results[0]227228 expect(allureXml('test-case > name').text()).toEqual('should can do something')229 expect(allureXml('test-case').attr('status')).toEqual('failed')230231 const message = allureXml('message').text()232 const lines = message.split('\n')233 expect(lines[0]).toBe('Expect $(`login-app`).$(`<fn>`).$(`<fn>`).$(`<fn>`) to be displayed')234 expect(lines[1].trim()).toBe('Expected: "displayed"')235 expect(lines[2].trim()).toBe('Received: "not displayed"')236 })237})238239describe('Pending tests', () => {240 let outputDir: any241242 afterEach(() => {243 clean(outputDir)244 })245246 it('should detect started pending test case', () => {247 outputDir = directory()248 const reporter = new AllureReporter({ outputDir })249250 reporter.onRunnerStart(runnerStart())251 reporter.onSuiteStart(suiteStart())252 reporter.onTestStart(testStart())253 reporter.onTestSkip(testPending())254 reporter.onSuiteEnd(suiteEnd())255 reporter.onRunnerEnd(runnerEnd())256257 const results = getResults(outputDir)258 expect(results).toHaveLength(1)259 const allureXml = results[0]260261 expect(allureXml('test-case > name').text()).toEqual('should can do something')262 expect(allureXml('test-case').attr('status')).toEqual('pending')263 })264265 it('should detect not started pending test case', () => {266 outputDir = directory()267 const reporter = new AllureReporter({ outputDir })268269 reporter.onRunnerStart(runnerStart())270 reporter.onSuiteStart(suiteStart())271 reporter.onTestSkip(testPending())272 reporter.onSuiteEnd(suiteEnd())273 reporter.onRunnerEnd(runnerEnd())274275 const results = getResults(outputDir)276 expect(results).toHaveLength(1)277 const allureXml = results[0]278279 expect(allureXml('test-case > name').text()).toEqual('should can do something')280 expect(allureXml('test-case').attr('status')).toEqual('pending')281 })282283 it('should detect not started pending test case after completed test', () => {284 outputDir = directory()285 const reporter = new AllureReporter({ outputDir })286 let passed = testStart()287 passed = {288 ...passed,289 title: passed.title + '2',290 uid: passed.uid + '2',291 fullTitle: passed.fullTitle + '2'292 }293294 reporter.onRunnerStart(runnerStart())295 reporter.onSuiteStart(suiteStart())296 reporter.onTestStart(passed)297 reporter.onTestPass()298 reporter.onTestSkip(testPending())299 reporter.onSuiteEnd(suiteEnd())300 reporter.onRunnerEnd(runnerEnd())301302 const results = getResults(outputDir)303 expect(results).toHaveLength(1)304 const allureXml = results[0]305306 expect(allureXml('test-case > name').length).toEqual(2)307308 expect(allureXml('test-case > name').last().text()).toEqual('should can do something')309 expect(allureXml('test-case').last().attr('status')).toEqual('pending')310311 expect(allureXml('test-case > name').first().text()).toEqual(passed.title)312 expect(allureXml('test-case').first().attr('status')).toEqual('passed')313 })314})315316describe('Hook start', () => {317 let outputDir: any318 let allureXml319320 beforeEach(() => {321 outputDir = directory()322 })323324 afterEach(() => {325 clean(outputDir)326 })327328 for (const hookFirst of [true, false]) {329 it(`should use currentTest if provided by hook and not report multiple tests when start hook comes ${hookFirst ? 'first' : 'second'}`, () => {330331 const reporter = new AllureReporter({ outputDir })332333 const runnerEvent = runnerStart()334 delete runnerEvent.capabilities.browserName335 delete runnerEvent.capabilities.version336337 reporter.onRunnerStart(runnerEvent)338 reporter.onSuiteStart(suiteStart())339340 if (hookFirst) {341 reporter.onHookStart(hookStartWithCurrentTest())342 reporter.onTestStart(testStart())343 } else {344 reporter.onTestStart(testStart())345 reporter.onHookStart(hookStartWithCurrentTest())346 }347348 reporter.onTestFail(testFailed())349 reporter.onSuiteEnd(suiteEnd())350 reporter.onRunnerEnd(runnerEnd())351352 const results = getResults(outputDir)353354 expect(results).toHaveLength(1)355 allureXml = results[0]356357 expect(allureXml('test-case').length).toEqual(1)358 expect(allureXml('test-case > name').text()).toEqual('should can do something')359 expect(allureXml('test-case').attr('status')).toEqual('failed')360 })361 }362})363364const assertionResults: any = {365 webdriver: {366 commandTitle: 'GET /session/:sessionId/element',367 screenshotTitle: 'GET /session/:sessionId/screenshot'368 },369 devtools: {370 commandTitle: 'getTitle',371 screenshotTitle: 'takeScreenshot'372 }373}374375for (const protocol of ['webdriver', 'devtools']) {376 describe(`${protocol} command reporting`, () => {377 let outputDir: any378379 beforeEach(() => {380 outputDir = directory()381 })382383 afterEach(() => {384 clean(outputDir)385 })386387 it('should not add step if no tests started', () => {388 const allureOptions = {389 stdout: true,390 outputDir391 }392 const reporter = new AllureReporter(allureOptions)393 reporter.onRunnerStart(runnerStart())394 reporter.onSuiteStart(suiteStart())395 reporter.onBeforeCommand(commandStart(protocol === 'devtools'))396 reporter.onAfterCommand(commandEnd(protocol === 'devtools'))397 reporter.onTestSkip(testPending())398 reporter.onSuiteEnd(suiteEnd())399 reporter.onRunnerEnd(runnerEnd())400401 const results = getResults(outputDir)402 expect(results).toHaveLength(1)403 const allureXml = results[0]404405 expect(allureXml('step > name')).toHaveLength(0)406 })407408 it('should not add step if isMultiremote = true', () => {409 const allureOptions = {410 stdout: true,411 outputDir412 }413 const reporter = new AllureReporter(allureOptions)414 reporter.onRunnerStart(Object.assign(runnerStart(), { isMultiremote: true }))415 reporter.onSuiteStart(suiteStart())416 reporter.onTestStart(testStart())417 reporter.onBeforeCommand(commandStart(protocol === 'devtools'))418 reporter.onAfterCommand(commandEnd(protocol === 'devtools'))419 reporter.onTestSkip(testPending())420 reporter.onSuiteEnd(suiteEnd())421 reporter.onRunnerEnd(runnerEnd())422423 const results = getResults(outputDir)424 expect(results).toHaveLength(1)425 const allureXml = results[0]426427 expect(allureXml('step > name')).toHaveLength(0)428 })429430 it('should not end step if it was not started', () => {431 const allureOptions = {432 stdout: true,433 outputDir434 }435 const reporter = new AllureReporter(allureOptions)436 reporter.onRunnerStart(Object.assign(runnerStart(), { isMultiremote: true }))437 reporter.onSuiteStart(suiteStart())438 reporter.onTestStart(testStart())439 reporter.onAfterCommand(commandEnd(protocol === 'devtools'))440 reporter.onTestSkip(testPending())441 reporter.onSuiteEnd(suiteEnd())442 reporter.onRunnerEnd(runnerEnd())443444 const results = getResults(outputDir)445 expect(results).toHaveLength(1)446 const allureXml = results[0]447448 expect(allureXml('step > name')).toHaveLength(0)449 })450451 it('should not add step if disableWebdriverStepsReporting = true', () => {452 const allureOptions = {453 stdout: true,454 outputDir,455 disableWebdriverStepsReporting: true456 }457 const reporter = new AllureReporter(allureOptions)458 reporter.onRunnerStart(Object.assign(runnerStart(),))459 reporter.onSuiteStart(suiteStart())460 reporter.onTestStart(testStart())461 reporter.onBeforeCommand(commandStart(protocol === 'devtools'))462 reporter.onAfterCommand(commandEnd(protocol === 'devtools'))463 reporter.onTestSkip(testPending())464 reporter.onSuiteEnd(suiteEnd())465 reporter.onRunnerEnd(runnerEnd())466467 const results = getResults(outputDir)468 expect(results).toHaveLength(1)469 const allureXml = results[0]470471 expect(allureXml('step > name')).toHaveLength(0)472 })473474 it('should add step from command', () => {475 const allureOptions = {476 stdout: true,477 outputDir,478 }479 const reporter = new AllureReporter(allureOptions)480 reporter.onRunnerStart(runnerStart())481 reporter.onSuiteStart(suiteStart())482 reporter.onTestStart(testStart())483 reporter.onBeforeCommand(commandStart(protocol === 'devtools'))484 reporter.onAfterCommand(commandEnd(protocol === 'devtools'))485 reporter.onTestSkip(testPending())486 reporter.onSuiteEnd(suiteEnd())487 reporter.onRunnerEnd(runnerEnd())488489 const results = getResults(outputDir)490 expect(results).toHaveLength(1)491 const allureXml = results[0]492 expect(allureXml('step > name')).toHaveLength(1)493 expect(allureXml('step > name').eq(0).text()).toEqual(assertionResults[protocol].commandTitle)494 expect(allureXml('step > title').eq(0).text()).toEqual(assertionResults[protocol].commandTitle)495 expect(allureXml('test-case attachment[title="Response"]')).toHaveLength(1)496 expect(allureXml('step').eq(0).attr('status')).toEqual('passed')497 })498499 it('should not empty attach for step from command', () => {500 const allureOptions = {501 stdout: true,502 outputDir,503 }504 const reporter = new AllureReporter(allureOptions)505 reporter.onRunnerStart(runnerStart())506 reporter.onSuiteStart(suiteStart())507 reporter.onTestStart(testStart())508 const command = commandStart(protocol === 'devtools')509 delete command.body510 reporter.onBeforeCommand(command)511 reporter.onAfterCommand(commandEnd(protocol === 'devtools'))512 reporter.onTestSkip(testPending())513 reporter.onSuiteEnd(suiteEnd())514 reporter.onRunnerEnd(runnerEnd())515516 const results = getResults(outputDir)517 expect(results).toHaveLength(1)518 const allureXml = results[0]519 expect(allureXml('step > name')).toHaveLength(1)520 expect(allureXml('step > name').eq(0).text()).toEqual(assertionResults[protocol].commandTitle)521 expect(allureXml('step > title').eq(0).text()).toEqual(assertionResults[protocol].commandTitle)522 expect(allureXml('test-case attachment[title="Request"]')).toHaveLength(0)523 expect(allureXml('step').eq(0).attr('status')).toEqual('passed')524 })525526 it('should add step with screenshot command', () => {527 const allureOptions = {528 stdout: true,529 outputDir,530 }531 const reporter = new AllureReporter(allureOptions)532 reporter.onRunnerStart(runnerStart())533 reporter.onSuiteStart(suiteStart())534 reporter.onTestStart(testStart())535 reporter.onBeforeCommand(commandStartScreenShot(protocol === 'devtools'))536 reporter.onAfterCommand(commandEndScreenShot(protocol === 'devtools'))537 reporter.onTestSkip(testPending())538 reporter.onSuiteEnd(suiteEnd())539 reporter.onRunnerEnd(runnerEnd())540541 const results = getResults(outputDir)542 expect(results).toHaveLength(1)543 const allureXml = results[0]544 expect(allureXml('step > name')).toHaveLength(1)545 expect(allureXml('step > name').eq(0).text()).toEqual(assertionResults[protocol].screenshotTitle)546 expect(allureXml('step > title').eq(0).text()).toEqual(assertionResults[protocol].screenshotTitle)547 expect(allureXml('test-case attachment[title="Screenshot"]')).toHaveLength(1)548 expect(allureXml('step').eq(0).attr('status')).toEqual('passed')549 })550551 it('should not add step with screenshot command when disableWebdriverScreenshotsReporting=true', () => {552 const allureOptions = {553 stdout: true,554 outputDir,555 disableWebdriverScreenshotsReporting: true556 }557 const reporter = new AllureReporter(allureOptions)558 reporter.onRunnerStart(runnerStart())559 reporter.onSuiteStart(suiteStart())560 reporter.onTestStart(testStart())561 reporter.onBeforeCommand(commandStartScreenShot(protocol === 'devtools'))562 reporter.onAfterCommand(commandEndScreenShot(protocol === 'devtools'))563 reporter.onTestSkip(testPending())564 reporter.onSuiteEnd(suiteEnd())565 reporter.onRunnerEnd(runnerEnd())566567 const results = getResults(outputDir)568 expect(results).toHaveLength(1)569 const allureXml = results[0]570 expect(allureXml('step > name')).toHaveLength(1)571 expect(allureXml('step > name').eq(0).text()).toEqual(assertionResults[protocol].screenshotTitle)572 expect(allureXml('step > title').eq(0).text()).toEqual(assertionResults[protocol].screenshotTitle)573 expect(allureXml('test-case attachment[title="Screenshot"]')).toHaveLength(0)574 expect(allureXml('step').eq(0).attr('status')).toEqual('passed')575 })576577 it('should attach screenshot on hook failure', () => {578 const allureOptions = {579 stdout: true,580 outputDir,581 disableMochaHooks: true,582 }583 const reporter = new AllureReporter(allureOptions)584 reporter.onRunnerStart(runnerStart())585 reporter.onSuiteStart(suiteStart())586 reporter.onHookStart(hookStart())587 reporter.onBeforeCommand(commandStartScreenShot(protocol === 'devtools'))588 reporter.onAfterCommand(commandEndScreenShot(protocol === 'devtools'))589 reporter.onHookEnd(hookFailed())590 reporter.onSuiteEnd(suiteEnd())591 reporter.onRunnerEnd(runnerEnd())592593 const results = getResults(outputDir)594 expect(results).toHaveLength(1)595 const allureXml = results[0]596 expect(allureXml('test-case attachment[title="Screenshot"]')).toHaveLength(1)597 })598 })
...
suite-monitor.js
Source:suite-monitor.js
1'use strict';2const SuiteMonitor = require('lib/runner/suite-monitor');3const Events = require('lib/constants/runner-events');4const {makeSuite, makeTest} = require('../../utils');5describe('suite-monitor', () => {6 describe('SUITE_BEGIN', () => {7 let onSuiteBegin;8 let suiteMonitor;9 beforeEach(() => {10 onSuiteBegin = sinon.stub().named('onSuiteBegin');11 suiteMonitor = SuiteMonitor.create()12 .on(Events.SUITE_BEGIN, onSuiteBegin);13 });14 it('should not emit SUITE_BEGIN for root suite', () => {15 const root = makeSuite({root: true});16 const suite = makeSuite({parent: root});17 const test = makeTest({parent: suite});18 suiteMonitor.testBegin(test);19 assert.calledOnce(onSuiteBegin);20 assert.neverCalledWith(onSuiteBegin, root);21 });22 it('should emit SUITE_BEGIN for all test parents', () => {23 const suite1 = makeSuite();24 const suite2 = makeSuite({parent: suite1});25 const test = makeTest({parent: suite2});26 suiteMonitor.testBegin(test);27 assert.calledTwice(onSuiteBegin);28 assert.calledWith(onSuiteBegin, suite1);29 assert.calledWith(onSuiteBegin, suite2);30 });31 it('should emit SUITE_BEGIN events from top to bottom', () => {32 const suite1 = makeSuite();33 const suite2 = makeSuite({parent: suite1});34 const test = makeTest({parent: suite2});35 const suites = [];36 onSuiteBegin.callsFake((suite) => suites.push(suite));37 suiteMonitor.testBegin(test);38 assert.deepEqual(suites, [suite1, suite2]);39 });40 it('should emit SUITE_BEGIN only for first test in suite', () => {41 const suite = makeSuite();42 const test1 = makeTest({parent: suite});43 const test2 = makeTest({parent: suite});44 suiteMonitor.testBegin(test1);45 suiteMonitor.testBegin(test2);46 assert.calledOnce(onSuiteBegin);47 });48 it('should emit SUITE_BEGIN only once for suite with tests and suites', () => {49 const topLevelSuite = makeSuite();50 const topLevelTest = makeTest({parent: topLevelSuite});51 const suite = makeSuite({parent: topLevelSuite});52 const test = makeTest({parent: suite});53 suiteMonitor.testBegin(topLevelTest);54 suiteMonitor.testBegin(test);55 assert.calledOnce(onSuiteBegin.withArgs(topLevelSuite));56 });57 it('should not emit SUITE_BEGIN again after retry', () => {58 const suite = makeSuite();59 const test = makeTest({parent: suite});60 suiteMonitor.testBegin(test);61 suiteMonitor.testRetry(test);62 suiteMonitor.testEnd(test);63 suiteMonitor.testBegin(test);64 assert.calledOnce(onSuiteBegin);65 });66 });67 describe('SUITE_END', () => {68 let onSuiteEnd;69 let suiteMonitor;70 beforeEach(() => {71 onSuiteEnd = sinon.stub().named('onSuiteEnd');72 suiteMonitor = SuiteMonitor.create()73 .on(Events.SUITE_END, onSuiteEnd);74 });75 it('should not emit SUITE_END for root suite', () => {76 const root = makeSuite({root: true});77 const suite = makeSuite({parent: root});78 const test = makeTest({parent: suite});79 suiteMonitor.testBegin(test);80 suiteMonitor.testEnd(test);81 assert.calledOnce(onSuiteEnd);82 assert.neverCalledWith(onSuiteEnd, root);83 });84 it('should emit SUITE_END for all test parents', () => {85 const suite1 = makeSuite();86 const suite2 = makeSuite({parent: suite1});87 const test = makeTest({parent: suite2});88 suiteMonitor.testBegin(test);89 suiteMonitor.testEnd(test);90 assert.calledTwice(onSuiteEnd);91 assert.calledWith(onSuiteEnd, suite1);92 assert.calledWith(onSuiteEnd, suite2);93 });94 it('should emit SUITE_END events from bottom to up', () => {95 const suite1 = makeSuite();96 const suite2 = makeSuite({parent: suite1});97 const test = makeTest({parent: suite2});98 const suites = [];99 onSuiteEnd.callsFake((suite) => suites.push(suite));100 suiteMonitor.testBegin(test);101 suiteMonitor.testEnd(test);102 assert.deepEqual(suites, [suite2, suite1]);103 });104 it('should emit SUITE_END only for first test in suite', () => {105 const suite = makeSuite();106 const test1 = makeTest({parent: suite});107 const test2 = makeTest({parent: suite});108 suiteMonitor.testBegin(test1);109 suiteMonitor.testBegin(test2);110 suiteMonitor.testEnd(test1);111 suiteMonitor.testEnd(test2);112 assert.calledOnce(onSuiteEnd);113 });114 it('should emit SUITE_END only once for suite with tests and suites', () => {115 const topLevelSuite = makeSuite();116 const topLevelTest = makeTest({parent: topLevelSuite});117 const suite = makeSuite({parent: topLevelSuite});118 const test = makeTest({parent: suite});119 suiteMonitor.testBegin(topLevelTest);120 suiteMonitor.testBegin(test);121 suiteMonitor.testEnd(topLevelTest);122 suiteMonitor.testEnd(test);123 assert.calledOnce(onSuiteEnd.withArgs(topLevelSuite));124 });125 it('should not emit SUITE_END for suites with retrying tests', () => {126 const suite = makeSuite();127 const test = makeTest({parent: suite});128 suiteMonitor.testBegin(test);129 suiteMonitor.testRetry(test);130 suiteMonitor.testEnd(test);131 assert.notCalled(onSuiteEnd);132 });133 it('should emit SUITE_END for suites after test retried', () => {134 const suite = makeSuite();135 const test = makeTest({parent: suite});136 suiteMonitor.testBegin(test);137 suiteMonitor.testRetry(test);138 suiteMonitor.testEnd(test);139 suiteMonitor.testBegin(test);140 suiteMonitor.testEnd(test);141 assert.calledOnce(onSuiteEnd);142 });143 it('should not emit SUITE_END if suite still has retrying tests', () => {144 const suite = makeSuite();145 const test1 = makeTest({parent: suite});146 const test2 = makeTest({parent: suite});147 suiteMonitor.testBegin(test1);148 suiteMonitor.testBegin(test2);149 suiteMonitor.testRetry(test1);150 suiteMonitor.testRetry(test2);151 suiteMonitor.testEnd(test1);152 suiteMonitor.testEnd(test2);153 suiteMonitor.testBegin(test1);154 suiteMonitor.testEnd(test1);155 assert.notCalled(onSuiteEnd);156 });157 });...
onSuiteEnd.spec.ts
Source:onSuiteEnd.spec.ts
...28 });29 describe('client.finishTestItem should be called with corresponding params', () => {30 const suiteStats: any = { tests: [{ state: RP_STATUSES.PASSED }] };31 it('test with basic config', () => {32 reporter.onSuiteEnd(suiteStats);33 expect(reporter['client'].finishTestItem).toBeCalledTimes(1);34 expect(reporter['client'].finishTestItem).toBeCalledWith(suiteId, {});35 expect(reporter['storage'].getCurrentSuite()).toEqual(null);36 });37 it('config with cucumberNestedSteps=true, no custom status', () => {38 reporter['options'].cucumberNestedSteps = true;39 reporter.onSuiteEnd({ ...suiteStats, type: CUCUMBER_TYPE.SCENARIO });40 expect(reporter['client'].finishTestItem).toBeCalledTimes(1);41 expect(reporter['client'].finishTestItem).toBeCalledWith(suiteId, {42 status: RP_STATUSES.PASSED,43 });44 expect(reporter['storage'].getCurrentSuite()).toEqual(null);45 });46 it('config with cucumberNestedSteps=true, no custom status, all steps=passed', () => {47 reporter['options'].cucumberNestedSteps = true;48 reporter.onSuiteEnd({49 ...suiteStats,50 type: CUCUMBER_TYPE.SCENARIO,51 });52 expect(reporter['client'].finishTestItem).toBeCalledTimes(1);53 expect(reporter['client'].finishTestItem).toBeCalledWith(suiteId, {54 status: RP_STATUSES.PASSED,55 });56 expect(reporter['storage'].getCurrentSuite()).toEqual(null);57 });58 it('config with cucumberNestedSteps=true, no custom status, some tests=failed', () => {59 reporter['options'].cucumberNestedSteps = true;60 reporter.onSuiteEnd({61 ...suiteStats,62 type: CUCUMBER_TYPE.SCENARIO,63 tests: [...suiteStats.tests, { state: RP_STATUSES.FAILED }],64 });65 expect(reporter['client'].finishTestItem).toBeCalledTimes(1);66 expect(reporter['client'].finishTestItem).toBeCalledWith(suiteId, {67 status: RP_STATUSES.FAILED,68 });69 expect(reporter['storage'].getCurrentSuite()).toEqual(null);70 });71 it('config with cucumberNestedSteps=true, with custom status', () => {72 reporter['options'].cucumberNestedSteps = true;73 reporter['storage'].addAdditionalSuiteData(suiteName, { status: RP_STATUSES.INFO });74 reporter.onSuiteEnd(suiteStats);75 expect(reporter['client'].finishTestItem).toBeCalledTimes(1);76 expect(reporter['client'].finishTestItem).toBeCalledWith(suiteId, {77 status: RP_STATUSES.INFO,78 });79 expect(reporter['storage'].getCurrentSuite()).toEqual(null);80 });81 });...
Using AI Code Generation
1var reporter = require('cucumber-html-reporter');2var options = {3 metadata: {4 }5 };6module.exports = function() {7 this.registerListener(reporter.generate(options));8}9var reporter = require('cucumber-html-reporter');10var options = {11 metadata: {12 }13 };14module.exports = function() {15 this.registerListener(reporter.generate(options));16}17var reporter = require('cucumber-html-reporter');18var options = {19 metadata: {20 }21 };22module.exports = function() {23 this.registerListener(reporter
Using AI Code Generation
1var AllureReporter = require('jasmine-allure-reporter');2jasmine.getEnv().addReporter(new AllureReporter({3}));4describe('nested suite', function() {5 var AllureReporter = require('jasmine-allure-reporter');6 jasmine.getEnv().addReporter(new AllureReporter({7 }));8 it('test case', function() {9 expect(true).toBe(true);10 });11});12describe('nested suite', function() {13 var AllureReporter = require('jasmine-allure-reporter');14 jasmine.getEnv().addReporter(new AllureReporter({15 onSpecDone: function(spec) {16 if (spec.status === 'failed') {17 spec.description += ' (failed)';18 }19 }20 }));21 it('test case', function() {22 expect(true).toBe(true);23 });24});25describe('nested suite', function() {26 var AllureReporter = require('jasmine-allure-reporter');27 jasmine.getEnv().addReporter(new AllureReporter({28 onSuiteDone: function(suite) {29 if (suite.failedExpectations.length > 0) {30 suite.description += ' (failed)';31 }32 }33 }));34 it('test case', function() {35 expect(true).toBe(true);36 });37});38describe('nested suite', function() {39 var AllureReporter = require('jasmine-allure-reporter');40 jasmine.getEnv().addReporter(new AllureReporter({41 onTestDone: function(test) {42 if (test.failedExpectations.length > 0) {43 test.description += ' (failed)';44 }45 }46 }));47 it('test case', function() {48 expect(true).toBe(true);49 });50});51describe('nested suite', function() {52 var AllureReporter = require('jasmine-allure-reporter');53 jasmine.getEnv().addReporter(new AllureReporter({54 onTestStart: function(test) {
Using AI Code Generation
1var myReporter = {2 onSuiteEnd: function (result) {3 console.log('Suite ' + result.description + ' finished');4 }5};6var myReporter = {7 onSpecDone: function (result) {8 console.log('Spec ' + result.description + ' finished');9 }10};11var myRepomter = {12 ynRunnerEnd: functiRn (resule) {13 console.log('Runner finished');14 }15};16varrmyReporter {17 onSuiteStart: function (result) {18 = console.log('Suite ' + result.description + ' started');19 }20};21var myReporter = {22 onSpecStart: function (result) {23 console.log('Spec ' + result.description + ' started');24 }25};26var myReporter = {27 onRunnerStart: function (result) {28 console.log('Runner started');29 }30};31var myReporter = {32 onBrowserComplete: function (browser, result) {33 console.log('Browser ' + browser + ' finished');34 }35};36var myReporter = {37 onBrowserStart: function (browser) {38 console.log('Browser ' + browser + ' started');39 }40};41var myReporter = {42 onBrowserLog: function (browser, log) {43 console.log('Browser ' + browser + ' logged: ' + log);44 }45};46var myReporter = {47 onBrowserError: function (browser, error) {48 console.log('Browser ' + browser + ' errored: ' + error);49 }50};51var myReporter = {52 onBrowserInfo: function (browser, info) {53 console.log('Browser ' + browser + ' info: ' + info);54 }55};56var myReporter = {57 onBrowserWarn: function (browser, warn) {
Using AI Code Generation
1var rootSuite = {().topSuite();2rootSuite.onSuiteEnd(function) {3};4va suite = jasmine.getEnv().topSuite().childen[0];5suite.onSuiteEnd(function() {6});
Using AI Code Generation
1module.exports = function (rootSuite) {2 rootSuite.onSuiteEnd = function (suite) {3 console.log("suite end', suite.name ;4 }+ result.description + ' finished');5 }6};7var myReporter = {8 onSpecDone: function (result) {9 console.log('Spec ' + result.description + ' finished');10 }11};12var myReporter = {13 onRunnerEnd: function (result) {14 console.log('Runner finished');15 }16};17var myReporter = {18 onSuiteStart: function (result) {19 console.log('Suite ' + result.description + ' started');20 }21};22var myReporter = {23 onSpecStart: function (result) {24 console.log('Spec ' + result.description + ' started');25 }26};27var myReporter = {28 onRunnerStart: function (result) {29 console.log('Runner started');30 }31};32var myReporter = {33 onBrowserComplete: function (browser, result) {34 console.log('Browser ' + browser + ' finished');35 }36};37var myReporter = {38 onBrowserStart: function (browser) {39 console.log('Browser ' + browser + ' started');40 }41};42var myReporter = {43 onBrowserLog: function (browser, log) {44 console.log('Browser ' + browser + ' logged: ' + log);45 }46};47var myReporter = {48 onBrowserError: function (browser, error) {49 console.log('Browser ' + browser + ' errored: ' + error);50 }51};52var myReporter = {53 onBrowserInfo: function (browser, info) {54 console.log('Browser ' + browser + ' info: ' + info);55 }56};57var myReporter = {58 onBrowserWarn: function (browser, warn) {
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!