Best JavaScript code snippet using stryker-parent
clear-text-reporter.spec.ts
Source:clear-text-reporter.spec.ts
...61 describe('mutants', () => {62 let report: schema.MutationTestResult;63 let mutant: schema.MutantResult;64 beforeEach(() => {65 mutant = factory.mutationTestReportSchemaMutantResult({66 id: '1',67 location: { start: { line: 2, column: 1 }, end: { line: 2, column: 4 } },68 replacement: 'bar',69 mutatorName: 'Math',70 });71 report = factory.mutationTestReportSchemaMutationTestResult({72 files: {73 'foo.js': factory.mutationTestReportSchemaFileResult({74 source: '\nfoo\n',75 mutants: [mutant],76 }),77 },78 testFiles: {79 'foo.spec.js': factory.mutationTestReportSchemaTestFile({80 tests: [81 factory.mutationTestReportSchemaTestDefinition({ id: '1', name: 'foo should be bar' }),82 factory.mutationTestReportSchemaTestDefinition({ id: '2', name: 'bar should be baz' }),83 factory.mutationTestReportSchemaTestDefinition({ id: '3', name: 'baz should be qux' }),84 factory.mutationTestReportSchemaTestDefinition({ id: '4', name: 'qux should be quux' }),85 factory.mutationTestReportSchemaTestDefinition({ id: '5', name: 'quux should be corge' }),86 ],87 }),88 },89 });90 });91 it('should report a killed mutant to debug', async () => {92 mutant.status = MutantStatus.Killed;93 mutant.killedBy = ['1'];94 act(report);95 expect(testInjector.logger.debug).calledWithMatch(sinon.match('1. [Killed] Math'));96 expect(testInjector.logger.debug).calledWith(`${chalk.red('- foo')}`);97 expect(testInjector.logger.debug).calledWith(`${chalk.green('+ bar')}`);98 expect(testInjector.logger.debug).calledWith('Killed by: foo should be bar');99 });100 it('should report a CompileError mutant to debug', async () => {101 mutant.status = MutantStatus.CompileError;102 mutant.statusReason = 'could not call bar of undefined';103 act(report);104 expect(testInjector.logger.debug).calledWithMatch(sinon.match('1. [CompileError] Math'));105 expect(testInjector.logger.debug).calledWith(`${chalk.red('- foo')}`);106 expect(testInjector.logger.debug).calledWith(`${chalk.green('+ bar')}`);107 expect(testInjector.logger.debug).calledWith('Error message: could not call bar of undefined');108 });109 it('should report a NoCoverage mutant to stdout', async () => {110 mutant.status = MutantStatus.NoCoverage;111 act(report);112 expect(stdoutStub).calledWithMatch(sinon.match('1. [NoCoverage] Math'));113 expect(stdoutStub).calledWith(`${chalk.red('- foo')}${os.EOL}`);114 expect(stdoutStub).calledWith(`${chalk.green('+ bar')}${os.EOL}`);115 });116 it('should report a Survived mutant to stdout', async () => {117 mutant.status = MutantStatus.Survived;118 act(report);119 expect(stdoutStub).calledWithMatch(sinon.match('1. [Survived] Math'));120 });121 it('should report a Timeout mutant to stdout', async () => {122 mutant.status = MutantStatus.Timeout;123 act(report);124 expect(testInjector.logger.debug).calledWithMatch(sinon.match('1. [Timeout] Math'));125 });126 it('should report the tests ran for a Survived mutant to stdout for "perTest" coverage analysis', async () => {127 mutant.coveredBy = ['1', '2', '3'];128 mutant.status = MutantStatus.Survived;129 act(report);130 expect(stdoutStub).calledWithExactly(`Tests ran:${os.EOL}`);131 expect(stdoutStub).calledWithExactly(` foo should be bar${os.EOL}`);132 expect(stdoutStub).calledWithExactly(` bar should be baz${os.EOL}`);133 expect(stdoutStub).calledWithExactly(` baz should be qux${os.EOL}`);134 });135 it('should report the max tests to log and however many more tests', async () => {136 testInjector.options.clearTextReporter.maxTestsToLog = 2;137 mutant.coveredBy = ['1', '2', '3'];138 mutant.status = MutantStatus.Survived;139 act(report);140 expect(stdoutStub).calledWithExactly(`Tests ran:${os.EOL}`);141 expect(stdoutStub).calledWithExactly(` foo should be bar${os.EOL}`);142 expect(stdoutStub).calledWithExactly(` bar should be baz${os.EOL}`);143 const allCalls = stdoutStub.getCalls().map((call) => call.args.join(''));144 expect(allCalls.filter((call) => call.includes('baz should be qux'))).lengthOf(1, 'Test "baz should be qux" was written more than once');145 expect(stdoutStub).calledWithExactly(` and 1 more test!${os.EOL}`);146 });147 it('should report that all tests have ran for a surviving mutant that is static', async () => {148 testInjector.options.clearTextReporter.maxTestsToLog = 2;149 mutant.static = true;150 mutant.status = MutantStatus.Survived;151 act(report);152 expect(stdoutStub).calledWithExactly(`Ran all tests for this mutant.${os.EOL}`);153 });154 it('should not log individual ran tests when logTests is not true', () => {155 testInjector.options.clearTextReporter.logTests = false;156 mutant.coveredBy = ['1', '2', '3'];157 mutant.status = MutantStatus.Survived;158 act(report);159 const allCalls = stdoutStub.getCalls().map((call) => call.args.join(''));160 expect(process.stdout.write).not.calledWithMatch(sinon.match('Tests ran: '));161 expect(allCalls.filter((call) => call.includes('foo should be bar'))).lengthOf(1, 'Test "foo should be bar" was written more than once');162 expect(process.stdout.write).not.calledWithMatch(sinon.match('Ran all tests for this mutant.'));163 });164 it('should correctly report tests run per mutant on avg', () => {165 mutant.testsCompleted = 4;166 report.files['foo.js'].mutants.push(factory.mutationTestReportSchemaMutantResult({ testsCompleted: 5 }));167 report.files['foo.js'].mutants.push(factory.mutationTestReportSchemaMutantResult({ testsCompleted: 1 }));168 act(report);169 expect(stdoutStub).calledWithExactly(`Ran 3.33 tests per mutant on average.${os.EOL}`);170 });171 it('should log source file location', () => {172 mutant.status = MutantStatus.Survived;173 mutant.location.start = { line: 4, column: 6 };174 act(report);175 expect(stdoutStub).to.have.been.calledWithMatch(sinon.match(`${chalk.cyan('foo.js')}:${chalk.yellow('4')}:${chalk.yellow('6')}`));176 });177 it('should log source file names without colored text when clearTextReporter is not false and allowConsoleColors is false', () => {178 testInjector.options.allowConsoleColors = false;179 mutant.status = MutantStatus.Survived;180 mutant.location.start = { line: 4, column: 6 };181 // Recreate, color setting is set in constructor182 sut = testInjector.injector.injectClass(ClearTextReporter);183 act(report);184 expect(stdoutStub).calledWithMatch(sinon.match('foo.js:4:6'));185 });186 });187 describe('tests', () => {188 it('should report a big list of tests if file names are unknown', () => {189 testInjector.options.clearTextReporter.allowColor = false;190 const report = factory.mutationTestReportSchemaMutationTestResult({191 files: {192 'foo.js': factory.mutationTestReportSchemaFileResult({193 mutants: [194 factory.mutationTestReportSchemaMutantResult({ killedBy: ['0'] }),195 factory.mutationTestReportSchemaMutantResult({ coveredBy: ['1'] }),196 ],197 }),198 },199 testFiles: {200 '': factory.mutationTestReportSchemaTestFile({201 tests: [202 factory.mutationTestReportSchemaTestDefinition({ id: '0', name: 'foo should bar' }),203 factory.mutationTestReportSchemaTestDefinition({ id: '1', name: 'baz should qux' }),204 factory.mutationTestReportSchemaTestDefinition({ id: '2', name: 'quux should corge' }),205 ],206 }),207 },208 });209 act(report);210 expect(stdoutStub).calledWithMatch(sinon.match('All tests'));211 expect(stdoutStub).calledWithMatch(sinon.match(' â foo should bar (killed 1)'));212 expect(stdoutStub).calledWithMatch(sinon.match(' ~ baz should qux (covered 1)'));213 expect(stdoutStub).calledWithMatch(sinon.match(' â quux should corge (covered 0)'));214 });215 it('should report in the correct colors', () => {216 testInjector.options.clearTextReporter.allowColor = true;217 const report = factory.mutationTestReportSchemaMutationTestResult({218 files: {219 'foo.js': factory.mutationTestReportSchemaFileResult({220 mutants: [221 factory.mutationTestReportSchemaMutantResult({ killedBy: ['0'] }),222 factory.mutationTestReportSchemaMutantResult({ coveredBy: ['1'] }),223 ],224 }),225 },226 testFiles: {227 '': factory.mutationTestReportSchemaTestFile({228 tests: [229 factory.mutationTestReportSchemaTestDefinition({ id: '0', name: 'foo should bar' }),230 factory.mutationTestReportSchemaTestDefinition({ id: '1', name: 'baz should qux' }),231 factory.mutationTestReportSchemaTestDefinition({ id: '2', name: 'quux should corge' }),232 ],233 }),234 },235 });236 act(report);237 expect(stdoutStub).calledWithMatch(sinon.match('All tests'));238 expect(stdoutStub).calledWithMatch(sinon.match(`${chalk.greenBright('â')} ${chalk.grey('foo should bar')} (killed 1)`));239 expect(stdoutStub).calledWithMatch(sinon.match(`${chalk.blueBright('~')} ${chalk.grey('baz should qux')} (covered 1)`));240 expect(stdoutStub).calledWithMatch(sinon.match(`${chalk.redBright('â')} ${chalk.grey('quux should corge')} (covered 0)`));241 });242 it('should report tests per file if file names are unknown', () => {243 testInjector.options.clearTextReporter.allowColor = false;244 const report = factory.mutationTestReportSchemaMutationTestResult({245 files: {246 'foo.js': factory.mutationTestReportSchemaFileResult({247 mutants: [248 factory.mutationTestReportSchemaMutantResult({ killedBy: ['0'] }),249 factory.mutationTestReportSchemaMutantResult({ coveredBy: ['1'] }),250 ],251 }),252 },253 testFiles: {254 'foo.spec.js': factory.mutationTestReportSchemaTestFile({255 tests: [256 factory.mutationTestReportSchemaTestDefinition({ id: '0', name: 'foo should bar' }),257 factory.mutationTestReportSchemaTestDefinition({ id: '1', name: 'baz should qux' }),258 ],259 }),260 'foo.test.js': factory.mutationTestReportSchemaTestFile({261 tests: [factory.mutationTestReportSchemaTestDefinition({ id: '2', name: 'quux should corge' })],262 }),263 },264 });265 act(report);266 expect(stdoutStub).calledWithMatch(sinon.match('All tests'));267 expect(stdoutStub).calledWithMatch(sinon.match(' foo.spec.js'));268 expect(stdoutStub).calledWithMatch(sinon.match(' â foo should bar (killed 1)'));269 expect(stdoutStub).calledWithMatch(sinon.match(' ~ baz should qux (covered 1)'));270 expect(stdoutStub).calledWithMatch(sinon.match(' foo.test.js'));271 expect(stdoutStub).calledWithMatch(sinon.match(' â quux should corge (covered 0)'));272 });273 it('should report the line number if they are known', () => {274 testInjector.options.clearTextReporter.allowColor = false;275 const report = factory.mutationTestReportSchemaMutationTestResult({276 testFiles: {277 'foo.spec.js': factory.mutationTestReportSchemaTestFile({278 tests: [279 factory.mutationTestReportSchemaTestDefinition({ id: '0', name: 'foo should bar', location: { start: { line: 7, column: 1 } } }),280 ],281 }),282 },283 });284 act(report);285 expect(stdoutStub).calledWithMatch(sinon.match('â foo should bar [line 7] (covered 0)'));286 });287 it('should merge deep directories with only one entry', () => {288 testInjector.options.clearTextReporter.allowColor = false;289 const report = factory.mutationTestReportSchemaMutationTestResult({290 files: {291 'components/foo.js': factory.mutationTestReportSchemaFileResult({292 mutants: [293 factory.mutationTestReportSchemaMutantResult({ killedBy: ['0'] }),294 factory.mutationTestReportSchemaMutantResult({ coveredBy: ['1'] }),295 ],296 }),297 },298 testFiles: {299 'test/unit/components/foo.spec.js': factory.mutationTestReportSchemaTestFile({300 tests: [factory.mutationTestReportSchemaTestDefinition({ id: '0', name: 'foo should bar' })],301 }),302 'test/unit/components/foo.test.js': factory.mutationTestReportSchemaTestFile({303 tests: [factory.mutationTestReportSchemaTestDefinition({ id: '1', name: 'baz should qux' })],304 }),305 'test/integration/components/foo.it.test.js': factory.mutationTestReportSchemaTestFile({306 tests: [factory.mutationTestReportSchemaTestDefinition({ id: '2', name: 'quux should corge' })],307 }),308 },...
Using AI Code Generation
1const strykerParent = require('stryker-parent');2const mutationTestReportSchemaMutantResult = strykerParent.mutationTestReportSchemaMutantResult;3const strykerParent = require('stryker-parent');4const mutationTestReportSchemaMutantResult = strykerParent.mutationTestReportSchemaMutantResult;5const strykerParent = require('stryker-parent');6const mutationTestReportSchemaMutantResult = strykerParent.mutationTestReportSchemaMutantResult;7const strykerParent = require('stryker-parent');8const mutationTestReportSchemaMutantResult = strykerParent.mutationTestReportSchemaMutantResult;9const strykerParent = require('stryker-parent');10const mutationTestReportSchemaMutantResult = strykerParent.mutationTestReportSchemaMutantResult;11const strykerParent = require('stryker-parent');12const mutationTestReportSchemaMutantResult = strykerParent.mutationTestReportSchemaMutantResult;13const strykerParent = require('stryker-parent');14const mutationTestReportSchemaMutantResult = strykerParent.mutationTestReportSchemaMutantResult;15const strykerParent = require('stryker-parent');16const mutationTestReportSchemaMutantResult = strykerParent.mutationTestReportSchemaMutantResult;17const strykerParent = require('stryker-parent');18const mutationTestReportSchemaMutantResult = strykerParent.mutationTestReportSchemaMutantResult;19const strykerParent = require('stryker-parent');
Using AI Code Generation
1const { mutationTestReportSchemaMutantResult } = require('stryker-parent');2const { mutationTestReportSchemaMutantResult } = require('stryker-parent');3const { mutationTestReportSchemaMutantResult } = require('stryker-parent');4const { mutationTestReportSchemaMutantResult } = require('stryker-parent');5const { mutationTestReportSchemaMutantResult } = require('stryker-parent');6const { mutationTestReportSchemaMutantResult } = require('stryker-parent');7const { mutationTestReportSchemaMutantResult } = require('stryker-parent');8const { mutationTestReportSchemaMutantResult } = require('stryker-parent');9const { mutationTestReportSchemaMutantResult } = require('stryker-parent');10const { mutationTestReportSchemaMutantResult } = require('stryker-parent');11const { mutationTestReportSchemaMutantResult } = require('stryker-parent');12const { mutationTestReportSchemaMutantResult } = require('stryker-parent');13const { mutationTestReportSchemaMutantResult } = require('stryker-parent');
Using AI Code Generation
1var stryker = require('stryker-parent');2var mutationTestReportSchemaMutantResult = stryker.mutationTestReportSchemaMutantResult;3var mutantResult = mutationTestReportSchemaMutantResult({id: 1, location: {start: {line: 1, column: 1}, end: {line: 1, column: 2}}, mutatorName: 'testMutator', replacement: 'testReplacement'});4console.log(mutantResult);5{ id: 1,6 location: { start: { line: 1, column: 1 }, end: { line: 1, column: 2 } },7 replacement: 'testReplacement' }
Using AI Code Generation
1const { mutationTestReportSchemaMutantResult } = require('stryker-parent');2const mutantResult = {3 location: {4 end: {5 },6 start: {7 },8 },9};10const result = mutationTestReportSchemaMutantResult.validate(mutantResult);11console.log(result.error);12const { mutationTestReportSchemaMutantResult } = require('stryker-parent');13const mutantResult = {14 location: {15 end: {16 },17 start: {18 },19 },20};21const result = mutationTestReportSchemaMutantResult.validate(mutantResult);22console.log(result.error);23const { mutationTestReportSchemaMutantResult } = require('stryker-parent');24const mutantResult = {25 location: {26 end: {27 },28 start: {29 },30 },31};32const result = mutationTestReportSchemaMutantResult.validate(mutantResult);33console.log(result.error);34const { mutationTestReportSchemaMutantResult } = require('stryker-parent');35const mutantResult = {36 location: {37 end: {
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!!