Best JavaScript code snippet using stryker-parent
index.test.ts
Source:index.test.ts
1import { createHtmlReport } from '../src';2import { defaultReportFileName } from '../src/util/saveHtmlReport';3import fs from 'fs';4import path from 'path';5const axeRawViolations = require('./rawViolations.json');6const axeRawPassed = require('./rawPasses.json');7const axeRawIncomplete = require('./rawIncomplete.json');8const axeRawInapplicable = require('./rawInapplicable.json');9const rawAxeResults = require('./rawAxeResults.json');10function getPathToCreatedReport(customFileName?: string, customOutputDir?: string) {11 return path.resolve(12 process.cwd(),13 customOutputDir ? customOutputDir : 'artifacts',14 customFileName ? customFileName : defaultReportFileName15 );16}17describe('Error handling', () => {18 it('Verify throwing an error if required parameters are not passed', async () => {19 expect(() => {20 createHtmlReport({21 // @ts-ignore22 results: {23 passes: [],24 },25 });26 }).toThrow(27 "'violations' is required for HTML accessibility report. Example: createHtmlReport({ results : { violations: Result[] } })"28 );29 });30});31describe('Successful tests', () => {32 // Verifies report with empty violations33 it('Empty violations', async () => {34 const reportFileName = 'tcAllPassedOnlyViolations.html';35 createHtmlReport({36 results: {37 violations: [],38 },39 options: {40 reportFileName,41 },42 });43 expect(44 fs.readFileSync(getPathToCreatedReport(reportFileName), {45 encoding: 'utf8',46 })47 ).toMatchSnapshot();48 });49 // Verifies report is created with default name in default directory with violations(passes and incomplete are not provided).50 // Creates html report file with name 'accessibilityReport.html' in default directory 'artifacts'51 it('Violations and URL with default report file name', async () => {52 createHtmlReport({53 results: {54 violations: axeRawViolations,55 url: 'https://dequeuniversity.com/demo/mars/',56 },57 });58 expect(fs.readFileSync(getPathToCreatedReport(), { encoding: 'utf8' })).toMatchSnapshot();59 });60 // Verifies report with if violations are not empty61 it('Violations', async () => {62 const reportFileName = 'urlIsNotPassed.html';63 createHtmlReport({64 results: {65 violations: axeRawViolations,66 },67 options: { reportFileName },68 });69 expect(70 fs.readFileSync(getPathToCreatedReport(reportFileName), { encoding: 'utf8' })71 ).toMatchSnapshot();72 });73 // Verifies report is created with violations and passes74 it('Violations, passes and url', async () => {75 const reportFileName = 'tcPassesAndViolations.html';76 createHtmlReport({77 results: {78 violations: axeRawViolations,79 passes: axeRawPassed,80 url: 'https://dequeuniversity.com/demo/mars/',81 },82 options: { reportFileName },83 });84 expect(85 fs.readFileSync(getPathToCreatedReport(reportFileName), { encoding: 'utf8' })86 ).toMatchSnapshot();87 });88 // Verifies report is created with violations, passes and incomplete with optional reportFileName and outputDir params89 it('Violations, passes, incomplete, url with reportFileName & outputDir', async () => {90 const reportFileName = 'tcPassesViolationsIncomplete.html';91 const outputDir = 'temp';92 createHtmlReport({93 results: {94 violations: axeRawViolations,95 passes: axeRawPassed,96 incomplete: axeRawIncomplete,97 url: 'https://dequeuniversity.com/demo/mars/',98 },99 options: {100 reportFileName,101 outputDir,102 },103 });104 expect(105 fs.readFileSync(getPathToCreatedReport(reportFileName, outputDir), {106 encoding: 'utf8',107 })108 ).toMatchSnapshot();109 });110 // Verifies report is created with violations, passes, incomplete url with optional111 // reportFileName and projectKey112 it('No violations found, passes, incomplete, url + reportFileName & projectKey', async () => {113 const reportFileName = 'tcWithTheKey.html';114 createHtmlReport({115 results: {116 violations: [],117 passes: axeRawPassed,118 incomplete: axeRawIncomplete,119 url: 'https://dequeuniversity.com/demo/mars/',120 },121 options: {122 reportFileName,123 projectKey: 'DEQUE',124 },125 });126 expect(127 fs.readFileSync(getPathToCreatedReport(reportFileName), { encoding: 'utf8' })128 ).toMatchSnapshot();129 });130 // Verifies report with inapplicable present in 'results'131 it('Inapplicable present', async () => {132 const reportFileName = 'tcInapplicablePresent.html';133 createHtmlReport({134 results: {135 violations: axeRawViolations,136 passes: axeRawPassed,137 incomplete: axeRawIncomplete,138 inapplicable: axeRawInapplicable,139 url: 'https://dequeuniversity.com/demo/mars/',140 },141 options: { reportFileName },142 });143 expect(144 fs.readFileSync(getPathToCreatedReport(reportFileName), { encoding: 'utf8' })145 ).toMatchSnapshot();146 });147 // Verifies report with empty violations, empty passes, empty incomplete, empty inapplicable148 it('Empty all: violation, passes, incomplete, inapplicable', async () => {149 const reportFileName = 'tcOnlyPasses.html';150 createHtmlReport({151 results: {152 violations: [],153 passes: [],154 incomplete: [],155 inapplicable: [],156 url: 'https://dequeuniversity.com/demo/mars/',157 },158 options: { reportFileName },159 });160 expect(161 fs.readFileSync(getPathToCreatedReport(reportFileName), { encoding: 'utf8' })162 ).toMatchSnapshot();163 });164 // Verify report is created with violations and custom summary165 it('Custom Summary present', async () => {166 const reportFileName = 'tcIncludingCustomSummary.html';167 const customSummary = `Test Case: Full page analysis168 <br>Steps:</br>169 <ol style="margin: 0">170 <li>Open https://dequeuniversity.com/demo/mars/</li>171 <li>Analyze full page with all rules enabled</li>172 </ol>`;173 createHtmlReport({174 results: {175 violations: axeRawViolations,176 url: 'https://dequeuniversity.com/demo/mars/',177 },178 options: { reportFileName, customSummary },179 });180 expect(181 fs.readFileSync(getPathToCreatedReport(reportFileName), { encoding: 'utf8' })182 ).toMatchSnapshot();183 });184 // Verifies report with all optional parameters185 it('All optional parameters present', async () => {186 const reportFileName = 'tsAllOptionalParametersPresent.html';187 const customSummary = `Test Case: Full page analysis188 <br>Steps:</br>189 <ol style="margin: 0">190 <li>Open https://dequeuniversity.com/demo/mars/</li>191 <li>Analyze full page with all rules enabled</li>192 </ol>`;193 createHtmlReport({194 results: {195 violations: axeRawViolations,196 passes: axeRawPassed,197 incomplete: [],198 inapplicable: axeRawInapplicable,199 url: 'https://dequeuniversity.com/demo/mars/',200 },201 options: { projectKey: 'DEQUE', customSummary, reportFileName },202 });203 expect(204 fs.readFileSync(getPathToCreatedReport(reportFileName), {205 encoding: 'utf8',206 })207 ).toMatchSnapshot();208 });209 it('Raw AxeResults passed and all optional params', async () => {210 const customSummary = `Test Case: Full page analysis211 <br>Steps:</br>212 <ol style="margin: 0">213 <li>Open https://dequeuniversity.com/demo/mars/</li>214 <li>Analyze full page with all rules enabled</li>215 </ol>`;216 const reportFileName = 'index.html';217 const outputDir = 'docs';218 createHtmlReport({219 results: rawAxeResults,220 options: { projectKey: 'DEQUE', customSummary, outputDir, reportFileName },221 });222 expect(223 fs.readFileSync(getPathToCreatedReport(reportFileName, outputDir), {224 encoding: 'utf8',225 })226 ).toMatchSnapshot();227 });228 it('File will not be created and raw HTML result will be returned', async () => {229 const customSummary = `Test Case: Full page analysis230 <br>Steps:</br>231 <ol style="margin: 0">232 <li>Open https://dequeuniversity.com/demo/mars/</li>233 <li>Analyze full page with all rules enabled</li>234 </ol>`;235 const reportHTML = createHtmlReport({236 results: rawAxeResults,237 options: {238 projectKey: 'I need only raw HTML',239 customSummary,240 doNotCreateReportFile: true,241 reportFileName: 'shouldNotBeSaved.html',242 },243 });244 expect(reportHTML).toMatchSnapshot();245 const isReportFileExist = fs.existsSync(getPathToCreatedReport('shouldNotBeSaved.html'));246 expect(isReportFileExist).toBe(false);247 });...
index.spec.js
Source:index.spec.js
1'use strict';2var assert = require('chai').assert,3 expect = require('chai').expect,4 chai = require('chai'),5 sinon = require('sinon'),6 Jasmine2ScreenShotReporter = require('./../index.js'),7 rimraf = require('rimraf'),8 fs = require('fs'),9 destinationPath = 'test/testdirectory',10 reportFileName = 'my-custom-report.html',11 suiteInfo = {totalSpecsDefined : 2};12describe('Jasmine2ScreenShotReporter tests', function(){13 beforeEach(function(done) {14 chai.use(require('chai-fs'));15 fs.mkdir(destinationPath, function(){done();});16 //Jasmine afterAll mock global function.17 global.afterAll = function() {};18 //Global version property.19 global.jasmine = {20 version: 'mockJasmineVersion'21 };22 //Jasmine browser global object.23 global.browser = {24 getCapabilities: function () {25 var p = Promise.resolve(26 { get: function(el) {27 return el + 'mockValue';28 }}29 );30 return p;31 },32 takeScreenshot: function() {33 var p = Promise.resolve('mockJPGImage');34 return p;35 }36 };37 });38 it('beforeLaunch should create initial report', function(done){39 var reporter = new Jasmine2ScreenShotReporter({40 dest: destinationPath,41 filename: reportFileName});42 assert.equal(typeof reporter.beforeLaunch, 'function'); //Public method beforeLaunch should be defined43 reporter.beforeLaunch(function() {44 var contents = fs.readFileSync(destinationPath + '/' + reportFileName, 'utf8');45 expect(destinationPath + '/' + reportFileName).to.be.a.path('no path');46 expect(contents).to.contain('<body><h1>Report</h1>');47 expect(contents).to.contain('<div id="summary" class="passed"><h4>Summary</h4>' +48 '<ul>' +49 '<li id="summaryTotalSpecs">Total specs tested: </li>' +50 '<li id="summaryTotalFailed">Total failed: </li>' +51 '</ul></div>');52 done();53 });54 });55 it('beforeLaunch should add custom CSS', function(done){56 var reporter = new Jasmine2ScreenShotReporter({57 dest: destinationPath,58 filename: reportFileName,59 userCss: 'myCSSFile.css'});60 assert.equal(typeof reporter.beforeLaunch, 'function'); //Public method beforeLaunch should be defined61 reporter.beforeLaunch(function() {62 var contents = fs.readFileSync(destinationPath + '/' + reportFileName, 'utf8');63 expect(contents).to.contain('<link type="text/css" rel="stylesheet" href="myCSSFile.css">');64 done();65 });66 });67 it('beforeLaunch should add custom JS', function(done){68 var reporter = new Jasmine2ScreenShotReporter({69 dest: destinationPath,70 filename: reportFileName,71 userJs: ['myJSFile.js', 'myJSFile2.js']});72 assert.equal(typeof reporter.beforeLaunch, 'function'); //Public method beforeLaunch should be defined73 reporter.beforeLaunch(function() {74 var contents = fs.readFileSync(destinationPath + '/' + reportFileName, 'utf8');75 expect(contents).to.contain('<script src="myJSFile.js"></script>');76 expect(contents).to.contain('<script src="myJSFile2.js"></script>');77 done();78 });79 });80 it('afterLaunch should close down report', function(done){81 var reporter = new Jasmine2ScreenShotReporter({82 dest: destinationPath,83 filename: reportFileName});84 assert.equal(typeof reporter.afterLaunch , 'function'); //Public method afterLaunch should be defined85 fs.writeFileSync(destinationPath + '/' + reportFileName, ''); //create empty file86 reporter.afterLaunch (function() {87 var contents = fs.readFileSync(destinationPath + '/' + reportFileName, 'utf8');88 assert.equal(contents, '</body></html>');89 done();90 });91 });92 it('jasmineStarted is calling browser getCapabilities', function(done){93 var reporter = new Jasmine2ScreenShotReporter({94 dest: destinationPath,95 filename: reportFileName}),96 save;97 assert.equal(typeof reporter.jasmineStarted , 'function'); //Public method jasmineStarted should be defined98 save = sinon.spy(global.browser, 'getCapabilities');99 fs.writeFileSync(destinationPath + '/' + reportFileName, ''); //create empty report file100 reporter.jasmineStarted(suiteInfo);101 sinon.assert.calledOnce(save);102 done();103 });104 it('report is being generated for failed', function(done){105 //@TODO: Need to elaborate this test.106 var reporter = new Jasmine2ScreenShotReporter({107 dest: destinationPath,108 filename: reportFileName});109 assert.equal(typeof reporter.suiteStarted , 'function'); //Public method suiteStarted should be defined110 assert.equal(typeof reporter.specStarted , 'function'); //Public method specStarted should be defined111 assert.equal(typeof reporter.specDone , 'function'); //Public method specDone should be defined112 assert.equal(typeof reporter.suiteDone , 'function'); //Public method suiteDone should be defined113 assert.equal(typeof reporter.jasmineDone , 'function'); //Public method suiteDone should be defined114 fs.writeFileSync(destinationPath + '/' + reportFileName, ''); //create empty report file115 reporter.jasmineStarted(suiteInfo);116 //setTimeout is needed because jasmineStarted contain promise that need to be fullfilled117 setTimeout(function(){118 reporter.suiteStarted({description : 'mockSuiteDescription', fullName: 'mockSuiteFullName'});119 reporter.specStarted({description : 'mockSpecDescription', fullName: 'mockSpecFullName'});120 reporter.specDone({description : 'mockSpecDescription', fullName: 'mockSpecFullName', status: 'failed',121 failedExpectations: [{message: 'mockFailedMessage', stack: 'mockStackMessage'}]122 });123 reporter.suiteDone({description : 'mockSuiteDescription', fullName: 'mockSuiteFullName'});124 reporter.jasmineDone();125 fs.readFile(destinationPath + '/' + reportFileName, 'utf8', function(error, contents) {126 expect(contents).to.contain('<h4>mockSuiteDescription');127 expect(contents).to.contain('mockSpecFullName');128 expect(contents).to.contain('<li>Jasmine version: mockJasmineVersion</li>');129 expect(contents).to.contain('<li>Browser name: browserNamemockValue</li>');130 expect(contents).to.contain('<li>Platform: platformmockValue</li>');131 expect(contents).to.contain('<li>Javascript enabled: javascriptEnabledmockValue</li>');132 expect(contents).to.contain('<li>Css selectors enabled: cssSelectorsEnabledmockValue</li>');133 expect(contents).to.contain('mockFailedMessage');134 expect(contents).to.contain('mockStackMessage');135 done();136 });137 }, 1);138 });139 140 it('report is being generated for failed with illegal chars', function(done){141 var reporter = new Jasmine2ScreenShotReporter({142 dest: destinationPath,143 filename: 'illegalchars-' + reportFileName });144 fs.writeFileSync(destinationPath + '/' + 'illegalchars-' + reportFileName , ''); //create empty report file145 reporter.jasmineStarted(suiteInfo);146 //setTimeout is needed because jasmineStarted contain promise that need to be fullfilled147 setTimeout(function(){148 reporter.suiteStarted({description : 'mockSuiteDescriptionWithIllegalChars', fullName: 'mockSuiteFullNameWithIllegalChars'});149 reporter.specStarted({description : 'mockSpecDescriptionWithIllegalChars & < > " \' | : \\ /', fullName: 'mockSpecFullNameWithIllegalChars & < > " \' | : \\ /'});150 reporter.specDone({description : 'mockSpecDescriptionWithIllegalChars & < > " \' | : \\ /', fullName: 'mockSpecFullNameWithIllegalChars & < > " \' | : \\ /', status: 'failed',151 failedExpectations: [{message: 'mockFailedMessage', stack: 'mockStackMessage'}]152 });153 reporter.suiteDone({description : 'mockSuiteDescriptionWithIllegalChars', fullName: 'mockSuiteFullNameWithIllegalChars'});154 reporter.jasmineDone();155 fs.readFile(destinationPath + '/' + 'illegalchars-' + reportFileName, 'utf8', function(error, contents) {156 expect(contents).to.contain('<h4>mockSuiteDescriptionWithIllegalChars');157 expect(contents).to.contain('mockSpecFullNameWithIllegalChars & < > " ' | : \\ /"');158 expect(contents).to.contain('mockFailedMessage');159 expect(contents).to.contain('mockStackMessage');160 done();161 });162 }, 1);163 });164 afterEach(function(done) {165 // clean folder166 rimraf(destinationPath, function(err) {167 if(err) {168 console.error('Could not delete ' + destinationPath + 'directory');169 }170 done();171 });172 });...
diagnostics_functions.js
Source:diagnostics_functions.js
1const process = require('process');2const util = require('./shared_utils');3const config = require('./config').config;4const request = require('superagent');5const fs = require('fs');6const resolve = require('path').resolve;7module.exports.dispatcher = function (args) {8 if (args.length === 0) {9 printModuleHelp();10 process.exit(1);11 }12 switch (args[0].toLowerCase()) {13 case 'run': {14 const options = util.optionsFromArgs(args.splice(1), ['output', 'reportFileName']);15 runDiagnostics(options['output'], options['reportFileName']);16 break;17 }18 case 'help':19 printModuleHelp();20 break;21 default:22 util.printErrorAndExit("Unknown operation");23 }24}25function runDiagnostics(outputFolder, fileName) {26 const endPoint = config.server + '/api/v1/diagnostics';27 let reportFileName = "diagnostics.zip";28 if (outputFolder) {29 if (!fs.existsSync(outputFolder)) {30 fs.mkdirSync(outputFolder, {recursive: true});31 }32 }33 reportFileName = (outputFolder ? outputFolder + '/' : '') + (fileName ? fileName : reportFileName);34 if(!reportFileName.endsWith(".zip")) {35 reportFileName += ".zip";36 }37 const stream = fs.createWriteStream(reportFileName);38 const req = request.get(endPoint)39 .auth(config.username, config.password)40 .accept("application/zip")41 .on('response', function (response) {42 if (response.status !== 200) {43 util.printErrorAndExit(`Status code: ${response.status}`);44 } else {45 util.output('Diagnostics report ' + resolve(reportFileName) + ' created successfully');46 }47 })48 .on('error', function (err) {49 util.error("Error: " + err.message);50 process.exit(1);51 }).send();52 req.pipe(stream);53}54function printModuleHelp() {55 util.error("Usage: testengine diagnostics <command>");56 util.error("Commands: ");57 util.error(" run [output=<directory>] [reportFileName=<filename>]");58 util.error(" help");...
Using AI Code Generation
1var strykerParent = require('stryker-parent');2console.log(strykerParent.reportFileName);3var strykerParent = require('stryker-parent');4console.log(strykerParent.reportFileName);5var strykerParent = require('stryker-parent');6console.log(strykerParent.reportFileName);7var strykerParent = require('stryker-parent');8console.log(strykerParent.reportFileName);9var strykerParent = require('stryker-parent');10console.log(strykerParent.reportFileName);11var strykerParent = require('stryker-parent');12console.log(strykerParent.reportFileName);13var strykerParent = require('stryker-parent');14console.log(strykerParent.reportFileName);15var strykerParent = require('stryker-parent');16console.log(strykerParent.reportFileName);17var strykerParent = require('stryker-parent');18console.log(strykerParent.reportFileName);19var strykerParent = require('stryker-parent');20console.log(strykerParent.reportFileName);21var strykerParent = require('stryker-parent');22console.log(strykerParent.reportFileName);23var strykerParent = require('stryker-parent');24console.log(strykerParent.reportFileName);25var strykerParent = require('stryker-parent');26console.log(strykerParent.report
Using AI Code Generation
1var strykerParent = require('stryker-parent');2console.log(strykerParent.reportFileName('foo'));3var strykerParent = require('stryker-parent');4console.log(strykerParent.reportFileName('foo'));5var strykerParent = require('stryker-parent');6console.log(strykerParent.reportFileName('foo'));7var strykerParent = require('stryker-parent');8console.log(strykerParent.reportFileName('foo'));9var strykerParent = require('stryker-parent');10console.log(strykerParent.reportFileName('foo'));11var strykerParent = require('stryker-parent');12console.log(strykerParent.reportFileName('foo'));13var strykerParent = require('stryker-parent');14console.log(strykerParent.reportFileName('foo'));15var strykerParent = require('stryker-parent');16console.log(strykerParent.reportFileName('foo'));17var strykerParent = require('stryker-parent');18console.log(strykerParent.reportFileName('foo'));19var strykerParent = require('stryker-parent');20console.log(strykerParent.reportFileName('foo'));21var strykerParent = require('stryker-parent');22console.log(strykerParent.reportFileName('foo'));23var strykerParent = require('stryker-parent');24console.log(strykerParent.reportFileName('foo'));
Using AI Code Generation
1const { reportFileName } = require('stryker-parent');2console.log(reportFileName('mutation.json'));3const { reportFileName } = require('stryker-parent');4console.log(reportFileName('mutation.json'));5const { reportFileName } = require('stryker-parent');6console.log(reportFileName('mutation.json'));7const { reportFileName } = require('stryker-parent');8console.log(reportFileName('mutation.json'));9const { reportFileName } = require('stryker-parent');10console.log(reportFileName('mutation.json'));11const { reportFileName } = require('stryker-parent');12console.log(reportFileName('mutation.json'));13const { reportFileName } = require('stryker-parent');14console.log(reportFileName('mutation.json'));15const { reportFileName } = require('stryker-parent');16console.log(reportFileName('mutation.json'));17const { reportFileName } = require('stryker-parent');18console.log(reportFileName('mutation.json'));19const { reportFileName } = require('stryker-parent');20console.log(reportFileName('mutation.json'));21const { reportFileName } = require('stryker-parent');22console.log(reportFileName('mutation.json'));23const { reportFileName
Using AI Code Generation
1var reportFileName = require('stryker-parent').reportFileName;2var report = reportFileName('test-report.html');3console.log(report);4var reportFileName = require('stryker-parent').reportFileName;5var report = reportFileName('test-report.html');6console.log(report);
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!!