How to use withTestFile method in stryker-parent

Best JavaScript code snippet using stryker-parent

incremental-differ.spec.ts

Source:incremental-differ.spec.ts Github

copy

Full Screen

...122 this.testCoverage.clear();123 this.testCoverage.hasCoverage = false;124 return this;125 }126 public withTestFile(): this {127 this.currentFiles.set(testAdd, testAddContent);128 this.incrementalTestFiles[testAdd].source = testAddContent;129 return this;130 }131 public withLocatedTest({ includeEnd = false } = {}): this {132 this.incrementalTestFiles[testAdd].tests[0].location = loc(4, 2);133 if (includeEnd) {134 this.incrementalTestFiles[testAdd].tests[0].location.end = pos(6, 5);135 }136 [...this.testCoverage.forMutant(this.mutantId)!][0].startPosition = pos(4, 2);137 return this;138 }139 public withAddedLinesAboveTest(...lines: string[]): this {140 this.currentFiles.set(testAdd, `${lines.join('\n')}\n${testAddContent}`);141 for (const test of this.testCoverage.forMutant(this.mutantId)!) {142 if (test.startPosition) {143 test.startPosition = pos(4 + lines.length, 2);144 }145 }146 return this;147 }148 public withAddedLinesAboveMutant(...lines: string[]): this {149 this.currentFiles.set(srcAdd, `${lines.join('\n')}\n${srcAddContent}`);150 this.mutants[0].location = loc(1 + lines.length, 11, 1 + lines.length, 12);151 return this;152 }153 public withCrlfLineEndingsInIncrementalReport(): this {154 Object.values(this.incrementalFiles).forEach((file) => {155 file.source = file.source.replace(/\n/g, '\r\n');156 });157 Object.values(this.incrementalTestFiles).forEach((file) => {158 file.source = file.source?.replace(/\n/g, '\r\n');159 });160 return this;161 }162 public withRemovedLinesAboveMutant(...lines: string[]): this {163 this.incrementalFiles[srcAdd].source = `${lines.join('\n')}\n${srcAddContent}`;164 this.incrementalFiles[srcAdd].mutants[0].location = loc(1 + lines.length, 11, 1 + lines.length, 12);165 return this;166 }167 public withAddedTextBeforeMutant(text: string): this {168 this.currentFiles.set(169 srcAdd,170 srcAddContent171 .split('\n')172 .map((line, nr) => (nr === 1 ? `${text}${line}` : line))173 .join('\n')174 );175 this.mutants[0].location = loc(1, 11 + text.length, 1, 12 + text.length);176 return this;177 }178 public withAddedTextBeforeTest(text: string): this {179 this.currentFiles.set(180 testAdd,181 testAddContent182 .split('\n')183 .map((line, nr) => (nr === 4 ? `${text}${line}` : line))184 .join('\n')185 );186 for (const test of this.testCoverage.forMutant(this.mutantId)!) {187 if (test.startPosition) {188 test.startPosition = pos(4, 2 + text.length);189 }190 }191 return this;192 }193 public withAddedCodeInsideTheTest(code: string): this {194 this.currentFiles.set(195 testAdd,196 testAddContent197 .split('\n')198 .map((line, nr) => (nr === 5 ? ` ${code}\n${line}` : line))199 .join('\n')200 );201 for (const test of this.testCoverage.forMutant(this.mutantId)!) {202 if (test.startPosition) {203 test.startPosition = pos(4, 2);204 }205 }206 return this;207 }208 public withSecondTest({ located }: { located: boolean }): this {209 this.currentFiles.set(testAdd, testAddContentTwoTests);210 const secondTest = factory.testResult({ id: 'spec2', fileName: testAdd, name: 'add(45, -3) = 42' });211 if (located) {212 secondTest.startPosition = pos(7, 2);213 }214 this.testCoverage.addTest(secondTest);215 this.testCoverage.addCoverage(this.mutantId, [secondTest.id]);216 return this;217 }218 public withSecondTestInIncrementalReport({ isKillingTest = false } = {}): this {219 this.incrementalTestFiles[testAdd].tests.unshift(220 factory.mutationTestReportSchemaTestDefinition({ id: 'spec2', name: 'add(45, -3) = 42', location: loc(7, 0) })221 );222 if (isKillingTest) {223 this.incrementalFiles[srcAdd].mutants[0].killedBy = ['spec2'];224 }225 if (this.incrementalTestFiles[testAdd].source) {226 this.incrementalTestFiles[testAdd].source = testAddContentTwoTests;227 }228 return this;229 }230 public withUpdatedTestGeneration(): this {231 this.currentFiles.set(testAdd, testAddContentWithTestGenerationUpdated);232 const createAddWithTestGenerationTestResult = (a: number, b: number, answer: number) =>233 factory.testResult({ id: `spec${a}`, fileName: testAdd, name: `should result in ${answer} for ${a} and ${b}`, startPosition: pos(5, 4) });234 this.testCoverage.clear();235 this.testCoverage.addTest(factory.testResult({ id: 'new-spec-2', fileName: testAdd, name: 'should have name "add"', startPosition: pos(9, 2) }));236 const gen1 = createAddWithTestGenerationTestResult(40, 2, 42);237 const gen2 = createAddWithTestGenerationTestResult(45, -3, 42);238 this.testCoverage.addTest(gen1, gen2);239 this.testCoverage.addCoverage(this.mutantId, ['new-spec-2', gen1.id, gen2.id]);240 return this;241 }242 public withTestGenerationIncrementalReport(): this {243 this.incrementalTestFiles[testAdd].source = testAddContentWithTestGeneration;244 const createAddWithTestGenerationTestDefinition = (id: string, a: number, b: number, answer: number) =>245 factory.mutationTestReportSchemaTestDefinition({246 id,247 name: `should result in ${answer} for ${a} and ${b}`,248 location: loc(5, 4),249 });250 while (this.incrementalTestFiles[testAdd].tests.shift()) {}251 this.incrementalTestFiles[testAdd].tests.push(252 factory.mutationTestReportSchemaTestDefinition({ id: 'spec3', name: 'should have name "add"', location: loc(9, 2) }),253 createAddWithTestGenerationTestDefinition('spec4', 40, 2, 42),254 createAddWithTestGenerationTestDefinition('spec5', 45, -3, 42)255 );256 this.incrementalFiles[srcAdd].mutants[0].coveredBy = ['spec4', 'spec5'];257 this.incrementalFiles[srcAdd].mutants[0].killedBy = ['spec4'];258 return this;259 }260 public withRemovedTextBeforeMutant(text: string): this {261 this.incrementalFiles[srcAdd].source = srcAddContent262 .split('\n')263 .map((line, nr) => (nr === 1 ? `${text}${line}` : line))264 .join('\n');265 this.incrementalFiles[srcAdd].mutants[0].location = loc(1, 11 + text.length, 1, 12 + text.length);266 return this;267 }268 public withAddedTextAfterTest(text: string): this {269 const cnt = testAddContent270 .split('\n')271 .map((line, nr) => `${line}${nr === 6 ? text : ''}`)272 .join('\n');273 this.currentFiles.set(testAdd, cnt);274 return this;275 }276 public withChangedMutantText(replacement: string): this {277 this.currentFiles.set(srcAdd, srcAddContent.replace('+', replacement));278 return this;279 }280 public withDifferentMutator(mutatorName: string): this {281 this.mutants[0].mutatorName = mutatorName;282 return this;283 }284 public withDifferentReplacement(replacement: string): this {285 this.mutants[0].replacement = replacement;286 return this;287 }288 public withDifferentMutantLocation(): this {289 this.incrementalFiles[srcAdd].mutants[0].location = loc(2, 11, 2, 12);290 return this;291 }292 public withDifferentFileName(fileName: string): this {293 this.incrementalFiles[fileName] = this.incrementalFiles[srcAdd];294 delete this.incrementalFiles[srcAdd];295 return this;296 }297 public withSecondSourceAndTestFileInIncrementalReport(): this {298 this.incrementalTestFiles[testMultiply] = factory.mutationTestReportSchemaTestFile({299 source: testMultiplyContent,300 tests: [301 factory.mutationTestReportSchemaTestDefinition({ id: 'spec-3', location: loc(4, 2), name: 'multiply should result in 42 for 2 and 21' }),302 ],303 });304 this.incrementalFiles[srcMultiply] = factory.mutationTestReportSchemaFileResult({305 mutants: [306 factory.mutationTestReportSchemaMutantResult({307 id: 'mut-3',308 coveredBy: ['spec-3'],309 killedBy: ['spec-3'],310 replacement: '/',311 testsCompleted: 1,312 status: MutantStatus.Killed,313 location: loc(1, 11, 1, 12),314 }),315 ],316 source: srcMultiplyContent,317 });318 return this;319 }320 public withSecondSourceFile(): this {321 this.currentFiles.set(srcMultiply, srcMultiplyContent);322 return this;323 }324 public withSecondTestFile(): this {325 this.currentFiles.set(testMultiply, testMultiplyContent);326 return this;327 }328 public act() {329 this.sut = testInjector.injector.injectClass(IncrementalDiffer);330 deepFreeze(this.mutants); // make sure mutants aren't changed at all331 return this.sut.diff(332 this.mutants,333 this.testCoverage,334 factory.mutationTestReportSchemaMutationTestResult({335 files: this.incrementalFiles,336 testFiles: this.incrementalTestFiles,337 }),338 this.currentFiles339 );340 }341}342describe(IncrementalDiffer.name, () => {343 describe('mutant changes', () => {344 it('should copy status, statusReason, testsCompleted if nothing changed', () => {345 // Arrange346 const actualDiff = new ScenarioBuilder().withMathProjectExample().act();347 // Assert348 const actualMutant = actualDiff[0];349 const expected: Partial<Mutant> = {350 id: '2',351 fileName: srcAdd,352 replacement: '-',353 mutatorName: 'min-replacement',354 location: loc(1, 11, 1, 12),355 status: MutantStatus.Killed,356 statusReason: 'Killed by first test',357 testsCompleted: 1,358 };359 expect(actualMutant).deep.contains(expected);360 });361 it('should not reuse the result when --force is active', () => {362 // Arrange363 testInjector.options.force = true;364 const actualDiff = new ScenarioBuilder().withMathProjectExample().act();365 // Assert366 const actualMutant = actualDiff[0];367 expect(actualMutant.status).undefined;368 });369 it('should not reuse when the mutant was ignored', () => {370 // Arrange371 const actualDiff = new ScenarioBuilder().withMathProjectExample({ mutantState: MutantStatus.Ignored }).act();372 // Assert373 const actualMutant = actualDiff[0];374 expect(actualMutant.status).undefined;375 });376 it('should normalize line endings when comparing diffs', () => {377 const actualDiff = new ScenarioBuilder()378 .withMathProjectExample()379 .withTestFile()380 .withLocatedTest()381 .withCrlfLineEndingsInIncrementalReport()382 .act();383 const actualMutant = actualDiff[0];384 expect(actualMutant.status).eq(MutantStatus.Killed);385 });386 it('should map killedBy and coveredBy to the new test ids if a mutant result is reused', () => {387 const scenario = new ScenarioBuilder().withMathProjectExample();388 const actualDiff = scenario.act();389 const actualMutant = actualDiff[0];390 const expectedTestIds = [scenario.newTestId];391 const expected: Partial<Mutant> = {392 coveredBy: expectedTestIds,393 killedBy: expectedTestIds,394 };395 expect(actualMutant).deep.contains(expected);396 });397 it("should identify that a mutant hasn't changed if lines got added above", () => {398 const actualDiff = new ScenarioBuilder().withMathProjectExample().withAddedLinesAboveMutant("import path from 'path';", '', '').act();399 expect(actualDiff[0].status).eq(MutantStatus.Killed);400 });401 it("should identify that a mutant hasn't changed if characters got added before", () => {402 const actualDiff = new ScenarioBuilder().withMathProjectExample().withAddedTextBeforeMutant("/* text added this shouldn't matter */").act();403 expect(actualDiff[0].status).eq(MutantStatus.Killed);404 });405 it("should identify that a mutant hasn't changed if lines got removed above", () => {406 const actualDiff = new ScenarioBuilder().withMathProjectExample().withRemovedLinesAboveMutant('import path from "path";', '').act();407 expect(actualDiff[0].status).eq(MutantStatus.Killed);408 });409 it("should identify that a mutant hasn't changed if characters got removed before", () => {410 const actualDiff = new ScenarioBuilder().withMathProjectExample().withRemovedTextBeforeMutant("/* text removed, this shouldn't matter*/").act();411 expect(actualDiff[0].status).eq(MutantStatus.Killed);412 });413 it('should not reuse the status of a mutant in changed text', () => {414 const actualDiff = new ScenarioBuilder().withMathProjectExample().withChangedMutantText('*').act();415 expect(actualDiff[0].status).undefined;416 });417 it('should reuse the status when there is no test coverage', () => {418 const actualDiff = new ScenarioBuilder().withMathProjectExample().withoutTestCoverage().act();419 expect(actualDiff[0].status).eq(MutantStatus.Killed);420 });421 it('should not copy the status if the mutant came from a different mutator', () => {422 const scenario = new ScenarioBuilder().withMathProjectExample().withDifferentMutator('max-replacement');423 const actualDiff = scenario.act();424 expect(actualDiff[0]).deep.eq(scenario.mutants[0]);425 });426 it('should not copy the status if the mutant has a different replacement', () => {427 const scenario = new ScenarioBuilder().withMathProjectExample().withDifferentReplacement('other replacement');428 const actualDiff = scenario.act();429 expect(actualDiff[0]).deep.eq(scenario.mutants[0]);430 });431 it('should not copy the status if the mutant has a different location', () => {432 const scenario = new ScenarioBuilder().withMathProjectExample().withDifferentMutantLocation();433 const actualDiff = scenario.act();434 expect(actualDiff[0]).deep.eq(scenario.mutants[0]);435 });436 it('should not copy the status if the mutant has a different file name', () => {437 const scenario = new ScenarioBuilder().withMathProjectExample().withDifferentFileName('src/some-other-file.js');438 const actualDiff = scenario.act();439 expect(actualDiff).deep.eq(scenario.mutants);440 });441 it('should collect 1 added mutant and 1 removed mutant if the mutant changed', () => {442 const scenario = new ScenarioBuilder().withMathProjectExample().withChangedMutantText('*');443 scenario.act();444 expect(scenario.sut!.mutantStatisticsCollector!.changesByFile).lengthOf(1);445 const changes = scenario.sut!.mutantStatisticsCollector!.changesByFile.get(srcAdd)!;446 expect(changes).property('added', 1);447 expect(changes).property('removed', 1);448 });449 it('should collect the removed mutants if the file got removed', () => {450 const scenario = new ScenarioBuilder().withMathProjectExample().withDifferentFileName('src/some-other-file.js');451 scenario.act();452 expect(scenario.sut!.mutantStatisticsCollector!.changesByFile).lengthOf(2);453 const changesOldFile = scenario.sut!.mutantStatisticsCollector!.changesByFile.get('src/some-other-file.js')!;454 const changesNewFile = scenario.sut!.mutantStatisticsCollector!.changesByFile.get(srcAdd)!;455 expect(changesNewFile).property('added', 1);456 expect(changesNewFile).property('removed', 0);457 expect(changesOldFile).property('added', 0);458 expect(changesOldFile).property('removed', 1);459 });460 it('should collect 1 added mutant and 1 removed mutant if a mutant changed', () => {461 const scenario = new ScenarioBuilder().withMathProjectExample().withChangedMutantText('*');462 scenario.act();463 expect(scenario.sut!.mutantStatisticsCollector!.changesByFile).lengthOf(1);464 const changes = scenario.sut!.mutantStatisticsCollector!.changesByFile.get(srcAdd)!;465 expect(changes).property('added', 1);466 expect(changes).property('removed', 1);467 });468 it('should log an incremental report', () => {469 const scenario = new ScenarioBuilder().withMathProjectExample().withChangedMutantText('*');470 testInjector.logger.isInfoEnabled.returns(true);471 scenario.act();472 const { mutantStatisticsCollector, testStatisticsCollector } = scenario.sut!;473 sinon.assert.calledWithExactly(474 testInjector.logger.info,475 `Incremental report:\n\tMutants:\t${mutantStatisticsCollector!.createTotalsReport()}` +476 `\n\tTests:\t\t${testStatisticsCollector!.createTotalsReport()}` +477 `\n\tResult:\t\t${chalk.yellowBright(0)} of 1 mutant result(s) are reused.`478 );479 });480 it('should not log test diff when there is no test coverage', () => {481 const scenario = new ScenarioBuilder().withMathProjectExample().withoutTestCoverage();482 testInjector.logger.isInfoEnabled.returns(true);483 scenario.act();484 const { mutantStatisticsCollector } = scenario.sut!;485 sinon.assert.calledWithExactly(486 testInjector.logger.info,487 `Incremental report:\n\tMutants:\t${mutantStatisticsCollector!.createTotalsReport()}` +488 `\n\tResult:\t\t${chalk.yellowBright(1)} of 1 mutant result(s) are reused.`489 );490 });491 it('should log a detailed incremental report', () => {492 const scenario = new ScenarioBuilder().withMathProjectExample().withChangedMutantText('*');493 testInjector.logger.isDebugEnabled.returns(true);494 scenario.act();495 const { mutantStatisticsCollector } = scenario.sut!;496 const lineSeparator = '\n\t\t';497 const detailedMutantSummary = `${lineSeparator}${mutantStatisticsCollector!.createDetailedReport().join(lineSeparator)}`;498 sinon.assert.calledWithExactly(499 testInjector.logger.debug,500 `Detailed incremental report:\n\tMutants: ${detailedMutantSummary}\n\tTests: ${lineSeparator}No changes`501 );502 });503 it('should not log if logLevel "info" or "debug" aren\'t enabled', () => {504 const scenario = new ScenarioBuilder().withMathProjectExample().withChangedMutantText('*');505 testInjector.logger.isInfoEnabled.returns(false);506 testInjector.logger.isDebugEnabled.returns(false);507 scenario.act();508 sinon.assert.notCalled(testInjector.logger.debug);509 sinon.assert.notCalled(testInjector.logger.info);510 });511 });512 describe('test changes', () => {513 it('should identify that a mutant state can be reused when no tests changed', () => {514 const actualDiff = new ScenarioBuilder().withMathProjectExample().withTestFile().act();515 expect(actualDiff[0].status).eq(MutantStatus.Killed);516 });517 it('should identify that mutant state can be reused with changes above', () => {518 const actualDiff = new ScenarioBuilder()519 .withMathProjectExample()520 .withTestFile()521 .withLocatedTest()522 .withAddedLinesAboveTest("import foo from 'bar'", '')523 .act();524 // Assert525 expect(actualDiff[0].status).eq(MutantStatus.Killed);526 });527 it('should identify that mutant state can be reused with changes before', () => {528 const actualDiff = new ScenarioBuilder()529 .withMathProjectExample()530 .withTestFile()531 .withLocatedTest()532 .withAddedTextBeforeTest('/*text-added*/')533 .act();534 expect(actualDiff[0].status).eq(MutantStatus.Killed);535 });536 it('should identify that mutant state can be reused with changes below', () => {537 const actualDiff = new ScenarioBuilder()538 .withMathProjectExample()539 .withTestFile()540 .withLocatedTest({ includeEnd: true })541 .withSecondTest({ located: true })542 .act();543 expect(actualDiff[0].status).eq(MutantStatus.Killed);544 });545 it('should identify that mutant state can be reused with changes behind', () => {546 const actualDiff = new ScenarioBuilder()547 .withMathProjectExample()548 .withTestFile()549 .withLocatedTest({ includeEnd: true })550 .withAddedTextAfterTest('/*text-added*/')551 .act();552 expect(actualDiff[0].status).eq(MutantStatus.Killed);553 });554 it('should not reuse a mutant state when a covering test gets code added', () => {555 const actualDiff = new ScenarioBuilder()556 .withMathProjectExample()557 .withTestFile()558 .withLocatedTest({ includeEnd: true })559 .withAddedCodeInsideTheTest('addedText();')560 .act();561 expect(actualDiff[0].status).undefined;562 });563 it('should close locations of tests in the incremental report', () => {564 // All test runners currently only report the start positions of tests.565 // Add a workaround for 'inventing' the end position based on the next test's start position.566 const actualDiff = new ScenarioBuilder()567 .withMathProjectExample()568 .withTestFile()569 .withLocatedTest({ includeEnd: true })570 .withSecondTest({ located: true })571 .withSecondTestInIncrementalReport()572 .act();573 expect(actualDiff[0].status).eq(MutantStatus.Killed);574 });575 it('should close locations for tests on the same location in the incremental report', () => {576 // Test cases can generate tests, make sure the correct end position is chosen in those cases577 const actualDiff = new ScenarioBuilder().withMathProjectExample().withUpdatedTestGeneration().withTestGenerationIncrementalReport().act();578 expect(actualDiff[0].status).eq(MutantStatus.Killed);579 });580 it('should identify that a non-"Killed" state can be reused when a test is removed', () => {581 const actualDiff = new ScenarioBuilder()582 .withMathProjectExample({ mutantState: MutantStatus.Survived })583 .withSecondTestInIncrementalReport()584 .act();585 expect(actualDiff[0].status).eq(MutantStatus.Survived);586 });587 it('should identify that a non-"Killed" state cannot be reused when a test is added', () => {588 const actualDiff = new ScenarioBuilder()589 .withMathProjectExample({ mutantState: MutantStatus.Survived })590 .withSecondTest({ located: false })591 .act();592 expect(actualDiff[0].status).undefined;593 });594 it('should identify that a "Killed" state can be reused when the killing test didn\'t change', () => {595 const actualDiff = new ScenarioBuilder()596 .withMathProjectExample({ mutantState: MutantStatus.Killed })597 .withTestFile()598 .withLocatedTest()599 .withSecondTestInIncrementalReport()600 .act();601 expect(actualDiff[0].status).eq(MutantStatus.Killed);602 });603 it('should identify that a "Killed" state cannot be reused when the killing test was removed', () => {604 const actualDiff = new ScenarioBuilder()605 .withMathProjectExample({ mutantState: MutantStatus.Killed })606 .withTestFile()607 .withSecondTestInIncrementalReport({ isKillingTest: true })608 .act();609 expect(actualDiff[0].status).undefined;610 });611 it('should identify that a "Killed" state for a static mutant (no covering tests) can be reused when the killing test didn\'t change', () => {612 const actualDiff = new ScenarioBuilder().withMathProjectExample({ mutantState: MutantStatus.Killed, isStatic: true }).act();613 expect(actualDiff[0].status).eq(MutantStatus.Killed);614 });615 it('should collect an added test', () => {616 const scenario = new ScenarioBuilder()617 .withMathProjectExample()618 .withTestFile()619 .withLocatedTest({ includeEnd: true })620 .withSecondTest({ located: true });621 scenario.act();622 const actualCollector = scenario.sut!.testStatisticsCollector!;623 expect(actualCollector.changesByFile).lengthOf(1);624 const changes = actualCollector.changesByFile.get(testAdd)!;625 expect(changes).property('added', 1);626 expect(changes).property('removed', 0);627 });628 it('should collect an added and removed test when a test changes', () => {629 const scenario = new ScenarioBuilder()630 .withMathProjectExample()631 .withTestFile()632 .withLocatedTest()633 .withAddedCodeInsideTheTest('arrangeSomething()');634 scenario.act();635 const actualCollector = scenario.sut!.testStatisticsCollector!;636 expect(actualCollector.changesByFile).lengthOf(1);637 const changes = actualCollector.changesByFile.get(testAdd)!;638 expect(changes).property('added', 1);639 expect(changes).property('removed', 1);640 });641 });642 describe('with history', () => {643 it('should keep historic mutants in other files', () => {644 const scenario = new ScenarioBuilder().withMathProjectExample().withSecondSourceAndTestFileInIncrementalReport().withSecondSourceFile();645 const mutants = scenario.act();...

Full Screen

Full Screen

async.js

Source:async.js Github

copy

Full Screen

...143 done();144 });145 });146 test('fchmod', (done) => {147 withTestFile((fd, testDone) => {148 fs.fchmod(fd, testFileStats.mode, () => {149 expectCallToMatch({150 fromRoot: true,151 family: 'fs',152 method: 'fchmod',153 firstArg: fd,154 });155 testDone();156 });157 }, done);158 });159 test('fchown', (done) => {160 withTestFile((fd, testDone) => {161 fs.fchown(fd, testFileStats.uid, testFileStats.gid, () => {162 expectCallToMatch({163 fromRoot: true,164 family: 'fs',165 method: 'fchown',166 firstArg: fd,167 });168 testDone();169 });170 }, done);171 });172 test('fdatasync', (done) => {173 withTestFile((fd, testDone) => {174 fs.fdatasync(fd, () => {175 expectCallToMatch({176 fromRoot: true,177 family: 'fs',178 method: 'fdatasync',179 firstArg: fd,180 });181 testDone();182 });183 }, done);184 });185 test('fstat', (done) => {186 withTestFile((fd, testDone) => {187 fs.fstat(fd, (err, stats) => {188 if (err) {189 testDone(err);190 return;191 }192 expect(stats.mode).toEqual(testFileStats.mode);193 expectCallToMatch({194 fromRoot: true,195 family: 'fs',196 method: 'fstat',197 firstArg: fd,198 });199 testDone();200 });201 }, done);202 });203 test('fsync', (done) => {204 withTestFile((fd, testDone) => {205 fs.fsync(fd, () => {206 expectCallToMatch({207 fromRoot: true,208 family: 'fs',209 method: 'fsync',210 firstArg: fd,211 });212 testDone();213 });214 }, done);215 });216 test('ftruncate', (done) => {217 withTestFile((fd, testDone) => {218 fs.ftruncate(fd, 1024, () => {219 expectCallToMatch({220 fromRoot: true,221 family: 'fs',222 method: 'ftruncate',223 firstArg: fd,224 secondArg: 1024,225 });226 testDone();227 });228 }, done);229 });230 test('futimes', (done) => {231 withTestFile((fd, testDone) => {232 fs.futimes(fd, testFileStats.atime, testFileStats.mtime, () => {233 expectCallToMatch({234 fromRoot: true,235 family: 'fs',236 method: 'futimes',237 firstArg: fd,238 secondArg: testFileStats.atime,239 });240 testDone();241 });242 }, done);243 });244 test('link', (done) => {245 fs.link(testFilePath, newTestFilePath, (err) => {246 if (err) {247 done(err);248 return;249 }250 expect(fs.existsSync(newTestFilePath)).toBeTruthy();251 expectCallToMatch({252 family: 'fs',253 method: 'link',254 firstArg: testFilePath,255 secondArg: newTestFilePath,256 });257 fs.unlink(newTestFilePath, done);258 });259 });260 test('mkdir', (done) => {261 fs.mkdir(newTestDirPath, (err) => {262 if (err) {263 done(err);264 return;265 }266 expect(fs.existsSync(newTestDirPath)).toBeTruthy();267 expectCallToMatch({268 family: 'fs',269 method: 'mkdir',270 firstArg: newTestDirPath,271 });272 fs.rmdir(newTestDirPath, done);273 });274 });275 test('mkdtemp', (done) => {276 fs.mkdtemp(__dirname, (err, dirPath) => {277 if (err) {278 done(err);279 return;280 }281 expect(fs.existsSync(dirPath)).toBeTruthy();282 expectCallToMatch({283 family: 'fs',284 method: 'mkdtemp',285 firstArg: __dirname,286 });287 fs.rmdir(dirPath, done);288 });289 });290 test('open', (done) => {291 fs.open(testFilePath, 'r', (err, fd) => {292 if (err) {293 done(err);294 return;295 }296 expectCallToMatch({297 family: 'fs',298 method: 'open',299 firstArg: testFilePath,300 });301 fs.close(fd, done);302 });303 });304 testif(fs.opendir)('opendir', (done) => {305 fs.opendir(testDirPath, (err, dir) => {306 if (err) {307 done(err);308 return;309 }310 expectCallToMatch({311 family: 'fs',312 method: 'opendir',313 firstArg: testDirPath,314 });315 dir.closeSync();316 done();317 });318 });319 test('read', (done) => {320 withTestFile((fd, testDone) => {321 fs.read(fd, Buffer.alloc(16), 0, 16, null, (err, bytes, buffer) => {322 if (err) {323 testDone(err);324 return;325 }326 expect(buffer.toString()).toMatch('just for testing');327 expectCallToMatch({328 fromRoot: true,329 family: 'fs',330 method: 'read',331 firstArg: fd,332 });333 testDone();334 });335 }, done);336 });337 test('readdir', (done) => {338 fs.readdir(testDirPath, (err, files) => {339 if (err) {340 done(err);341 return;342 }343 expect(Array.isArray(files)).toBeTruthy();344 expectCallToMatch({345 family: 'fs',346 method: 'readdir',347 firstArg: testDirPath,348 });349 done(err);350 });351 });352 test('readFile', (done) => {353 fs.readFile(testFilePath, (err, data) => {354 expect(data.toString()).toMatch('just for testing');355 expectCallToMatch({family: 'fs', method: 'readFile', firstArg: testFilePath});356 done(err);357 });358 });359 test('realpath', (done) => {360 fs.realpath(testFilePath, (err, p) => {361 expect(p).toBe(testFilePath);362 expectCallToMatch({363 family: 'fs',364 method: 'realpath',365 firstArg: testFilePath,366 });367 done(err);368 });369 });370 test('rename', (done) => {371 fs.rename(testFilePath, newTestFilePath, (err) => {372 if (err) {373 done(err);374 return;375 }376 expect(fs.existsSync(newTestFilePath)).toBeTruthy();377 expectCallToMatch({378 family: 'fs',379 method: 'rename',380 firstArg: testFilePath,381 secondArg: newTestFilePath,382 });383 fs.rename(newTestFilePath, testFilePath, done);384 });385 });386 testif(fs.rm)('rm', (done) => {387 fs.copyFile(testFilePath, newTestFilePath, (err) => {388 if (err) {389 done(err);390 return;391 }392 fs.rm(newTestFilePath, (rmErr) => {393 expectCallToMatch({394 family: 'fs',395 method: 'rm',396 firstArg: newTestFilePath,397 fromRoot: true,398 });399 done(rmErr);400 });401 });402 });403 test('stat', (done) => {404 fs.stat(testFilePath, (err, stats) => {405 if (err) {406 done(err);407 return;408 }409 expect(stats).toBeInstanceOf(fs.Stats);410 expectCallToMatch({411 family: 'fs',412 method: 'stat',413 firstArg: testFilePath,414 });415 done();416 });417 });418 test('symlink', (done) => {419 fs.symlink(testFilePath, newTestFilePath, (err) => {420 if (err) {421 done(err);422 return;423 }424 expectCallToMatch({425 family: 'fs',426 method: 'symlink',427 firstArg: testFilePath,428 });429 fs.unlink(newTestFilePath, done);430 });431 });432 test('truncate', (done) => {433 fs.truncate(testFilePath, 16, (err) => {434 expectCallToMatch({435 family: 'fs',436 method: 'truncate',437 firstArg: testFilePath,438 });439 done(err);440 });441 });442 test('unlink', (done) => {443 fs.copyFile(testFilePath, newTestFilePath, (err) => {444 if (err) {445 done(err);446 return;447 }448 fs.unlink(newTestFilePath, (rmErr) => {449 expectCallToMatch({450 family: 'fs',451 method: 'unlink',452 firstArg: newTestFilePath,453 fromRoot: true,454 });455 done(rmErr);456 });457 });458 });459 test('unwatchFile', () => {460 fs.unwatchFile(testFilePath);461 expectCallToMatch({462 family: 'fs',463 method: 'unwatchFile',464 firstArg: testFilePath,465 });466 });467 test('utimes', (done) => {468 fs.utimes(testFilePath, testFileStats.atime, testFileStats.mtime, (err) => {469 expectCallToMatch({470 family: 'fs',471 method: 'utimes',472 firstArg: testFilePath,473 });474 done(err);475 });476 });477 test('watch', () => {478 const watcher = fs.watch(testFilePath);479 expectCallToMatch({480 family: 'fs',481 method: 'watch',482 firstArg: testFilePath,483 });484 watcher.close();485 });486 test('watchFile', () => {487 fs.watchFile(testFilePath, () => {});488 expectCallToMatch({489 family: 'fs',490 method: 'watchFile',491 firstArg: testFilePath,492 });493 fs.unwatchFile(testFilePath);494 });495 test('write', (done) => {496 withTestFile((fd, testDone) => {497 fs.write(fd, 'just for testing', (err) => {498 expectCallToMatch({499 family: 'fs',500 method: 'write',501 firstArg: fd,502 fromRoot: true,503 });504 testDone(err);505 });506 }, done);507 });508 test('writeFile', (done) => {509 fs.writeFile(testFilePath, 'just for testing', (err) => {510 expectCallToMatch({...

Full Screen

Full Screen

sync.js

Source:sync.js Github

copy

Full Screen

...75 test('existsSync', () => {76 expect(fs.existsSync(testFilePath)).toBeTruthy();77 });78 test('fchmodSync', () => {79 withTestFile((fd) => {80 fs.fchmodSync(fd, testFileStats.mode);81 expectCallToMatch({82 index: 1,83 family: 'fs',84 method: 'fchmodSync',85 firstArg: fd,86 });87 });88 });89 test('fchownSync', () => {90 withTestFile((fd) => {91 fs.fchownSync(fd, testFileStats.uid, testFileStats.gid);92 expectCallToMatch({93 index: 1,94 family: 'fs',95 method: 'fchownSync',96 firstArg: fd,97 });98 });99 });100 test('fdatasyncSync', () => {101 withTestFile((fd) => {102 fs.fdatasyncSync(fd);103 expectCallToMatch({104 index: 1,105 family: 'fs',106 method: 'fdatasyncSync',107 firstArg: fd,108 });109 });110 });111 test('fstatSync', () => {112 withTestFile((fd) => {113 const stats = fs.fstatSync(fd);114 expect(stats.mode).toEqual(testFileStats.mode);115 expectCallToMatch({116 index: 1,117 family: 'fs',118 method: 'fstatSync',119 firstArg: fd,120 });121 });122 });123 test('fsyncSync', () => {124 withTestFile((fd) => {125 fs.fsyncSync(fd);126 expectCallToMatch({127 index: 1,128 family: 'fs',129 method: 'fsyncSync',130 firstArg: fd,131 });132 });133 });134 test('ftruncateSync', () => {135 withTestFile((fd) => {136 fs.ftruncateSync(fd, 16);137 expectCallToMatch({138 index: 1,139 family: 'fs',140 method: 'ftruncateSync',141 firstArg: fd,142 secondArg: 16,143 });144 });145 });146 test('futimesSync', () => {147 withTestFile((fd) => {148 fs.futimesSync(fd, testFileStats.atime, testFileStats.mtime);149 expectCallToMatch({150 index: 1,151 family: 'fs',152 method: 'futimesSync',153 firstArg: fd,154 secondArg: testFileStats.atime,155 });156 });157 });158 test('linkSync', () => {159 fs.linkSync(testFilePath, newTestFilePath);160 expect(fs.existsSync(newTestFilePath)).toBeTruthy();161 expectCallToMatch({162 family: 'fs',163 method: 'linkSync',164 firstArg: testFilePath,165 secondArg: newTestFilePath,166 });167 fs.unlinkSync(newTestFilePath);168 });169 test('mkdirSync', () => {170 fs.mkdirSync(newTestDirPath);171 expect(fs.existsSync(newTestDirPath)).toBeTruthy();172 expectCallToMatch({173 family: 'fs',174 method: 'mkdirSync',175 firstArg: newTestDirPath,176 });177 fs.rmdirSync(newTestDirPath);178 });179 test('mkdtempSync', () => {180 const dirPath = fs.mkdtempSync(__dirname);181 expect(fs.existsSync(dirPath)).toBeTruthy();182 expectCallToMatch({183 family: 'fs',184 method: 'mkdtempSync',185 firstArg: __dirname,186 });187 fs.rmdirSync(dirPath);188 });189 test('openSync', () => {190 const fd = fs.openSync(testFilePath, 'r');191 expectCallToMatch({192 family: 'fs',193 method: 'openSync',194 firstArg: testFilePath,195 });196 fs.closeSync(fd);197 });198 testif(fs.opendirSync)('opendirSync', () => {199 const dir = fs.opendirSync(testDirPath);200 expectCallToMatch({201 family: 'fs',202 method: 'opendirSync',203 firstArg: testDirPath,204 });205 dir.closeSync();206 });207 test('readSync', () => {208 withTestFile((fd) => {209 const buf = Buffer.alloc(16);210 fs.readSync(fd, buf, 0, 16);211 expect(buf.toString()).toEqual('just for testing');212 expectCallToMatch({213 index: 1,214 family: 'fs',215 method: 'readSync',216 firstArg: fd,217 });218 });219 });220 test('readdirSync', () => {221 const files = fs.readdirSync(testDirPath);222 expect(Array.isArray(files)).toBeTruthy();223 expectCallToMatch({224 family: 'fs',225 method: 'readdirSync',226 firstArg: testDirPath,227 });228 });229 test('readFileSync', () => {230 const data = fs.readFileSync(testFilePath);231 expect(data.toString()).toMatch('just for testing');232 expectCallToMatch({family: 'fs', method: 'readFileSync', firstArg: testFilePath});233 });234 test('realpathSync', () => {235 const p = fs.realpathSync(testFilePath);236 expect(p).toBe(testFilePath);237 expectCallToMatch({238 family: 'fs',239 method: 'realpathSync',240 firstArg: testFilePath,241 });242 });243 test('renameSync', () => {244 fs.renameSync(testFilePath, newTestFilePath);245 expect(fs.existsSync(newTestFilePath)).toBeTruthy();246 expectCallToMatch({247 family: 'fs',248 method: 'renameSync',249 firstArg: testFilePath,250 secondArg: newTestFilePath,251 });252 fs.renameSync(newTestFilePath, testFilePath);253 });254 testif(fs.rmSync)('rmSync', (done) => {255 fs.copyFile(testFilePath, newTestFilePath, (err) => {256 fs.rmSync(newTestFilePath);257 expectCallToMatch({258 fromRoot: true,259 family: 'fs',260 method: 'rmSync',261 firstArg: newTestFilePath,262 });263 done(err);264 });265 });266 test('statSync', () => {267 const stats = fs.statSync(testFilePath);268 expect(stats).toBeInstanceOf(fs.Stats);269 expectCallToMatch({270 family: 'fs',271 method: 'statSync',272 firstArg: testFilePath,273 });274 });275 test('symlinkSync', () => {276 fs.symlinkSync(testFilePath, newTestFilePath);277 expectCallToMatch({278 family: 'fs',279 method: 'symlinkSync',280 firstArg: testFilePath,281 });282 fs.unlinkSync(newTestFilePath);283 });284 test('truncateSync', () => {285 fs.truncateSync(testFilePath, 16);286 expectCallToMatch({287 family: 'fs',288 method: 'truncateSync',289 firstArg: testFilePath,290 });291 });292 test('unlinkSync', (done) => {293 fs.copyFile(testFilePath, newTestFilePath, (err) => {294 fs.unlinkSync(newTestFilePath);295 expectCallToMatch({296 family: 'fs',297 method: 'unlinkSync',298 firstArg: newTestFilePath,299 fromRoot: true,300 });301 done(err);302 });303 });304 test('utimesSync', () => {305 fs.utimesSync(testFilePath, testFileStats.atime, testFileStats.mtime);306 expectCallToMatch({307 family: 'fs',308 method: 'utimesSync',309 firstArg: testFilePath,310 });311 });312 test('writeSync', () => {313 withTestFile((fd) => {314 fs.writeSync(fd, 'just for testing');315 expectCallToMatch({316 index: 1,317 family: 'fs',318 method: 'writeSync',319 firstArg: fd,320 });321 });322 });323 test('writeFileSync', () => {324 fs.writeFileSync(testFilePath, 'just for testing');325 expectCallToMatch({326 family: 'fs',327 method: 'writeFileSync',...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { withTestFile } = require('stryker-parent');2module.exports = function(config) {3 withTestFile(config, 'test.js');4}5const { withTestFile } = require('stryker-parent');6module.exports = function(config) {7 withTestFile(config, 'test2.js');8}9const { withTestFile } = require('stryker-parent');10module.exports = function(config) {11 withTestFile(config, 'test3.js');12}13const { withTestFile } = require('stryker-parent');14module.exports = function(config) {15 withTestFile(config, 'test4.js');16}17const { withTestFile } = require('stryker-parent');18module.exports = function(config) {19 withTestFile(config, 'test5.js');20}21const { withTestFile } = require('stryker-parent');22module.exports = function(config) {23 withTestFile(config, 'test6.js');24}25const { withTestFile } = require('stryker-parent');26module.exports = function(config) {27 withTestFile(config, 'test7.js');28}29const { withTestFile } = require('stryker-parent');30module.exports = function(config) {31 withTestFile(config, 'test8.js');32}33const { withTestFile } = require('stryker-parent');34module.exports = function(config) {35 withTestFile(config, 'test9.js');36}37const { withTestFile } =

Full Screen

Using AI Code Generation

copy

Full Screen

1require('stryker-parent').withTestFile(__filename, function () {2 describe('my first test', function () {3 it('should be green', function () {4 expect(true).toBe(true);5 });6 });7});8require('stryker-parent').withTestFile(__filename, function () {9 describe('my first test', function () {10 it('should be green', function () {11 expect(true).toBe(true);12 });13 });14});15require('stryker-parent').withTestFile(__filename, function () {16 describe('my first test', function () {17 it('should be green', function () {18 expect(true).toBe(true);19 });20 });21});22require('stryker-parent').withTestFile(__filename, function () {23 describe('my first test', function () {24 it('should be green', function () {25 expect(true).toBe(true);26 });27 });28});29require('stryker-parent').withTestFile(__filename, function () {30 describe('my first test', function () {31 it('should be green', function () {32 expect(true).toBe(true);33 });34 });35});36require('stryker-parent').withTestFile(__filename, function () {37 describe('my first test', function () {38 it('should be green', function () {39 expect(true).toBe(true);40 });41 });42});43require('stryker-parent').withTestFile(__filename, function () {44 describe('my first test', function

Full Screen

Using AI Code Generation

copy

Full Screen

1const testFile = require('./testFile');2describe('test', () => {3 it('should pass', () => {4 expect(testFile()).to.equal('test');5 });6});7module.exports = () => 'test';8module.exports = function(config) {9 config.set({10 mochaOptions: {11 }12 });13};

Full Screen

Using AI Code Generation

copy

Full Screen

1require('stryker-parent').withTestFile(__filename, function() {2 var assert = require('assert');3 describe('test', function () {4 it('should pass', function () {5 assert.equal(1, 1);6 });7 });8});

Full Screen

Using AI Code Generation

copy

Full Screen

1const fs = require('fs');2const path = require('path');3const testFile = path.join(__dirname, '../src/MyClass.js');4const testCode = fs.readFileSync(testFile, 'utf8');5module.exports = function (strykerConfig) {6 return function (config) {7 config.set({8 commandRunner: {9 },10 });11 }12}13class MyClass {14 constructor() {15 this._value = 0;16 }17 inc() {18 this._value++;19 }20 get value() {21 return this._value;22 }23}24module.exports = MyClass;

Full Screen

Using AI Code Generation

copy

Full Screen

1const {withTestFile} = require('stryker-parent');2withTestFile('test.js', () => {3});4const {withTestFile} = require('stryker-parent');5withTestFile('test.js', () => {6});7const {withTestFile} = require('stryker-parent');8withTestFile('test.js', () => {9});10const {withTestFile} = require('stryker-parent');11withTestFile('test.js', () => {12});13const {withTestFile} = require('stryker-parent');14withTestFile('test.js', () => {15});16const {withTestFile} = require('stryker-parent');17withTestFile('test.js', () => {18});19const {withTestFile} = require('stryker-parent');20withTestFile('test.js', () => {21});22const {withTestFile} = require('stryker-parent');23withTestFile('test.js', () => {24});25const {withTestFile} = require('stryker-parent');26withTestFile('test.js', () => {27});

Full Screen

Using AI Code Generation

copy

Full Screen

1var test = require('unit.js');2var assert = test.assert;3var stryker = require('stryker-parent');4var fs = require('fs');5var path = require('path');6describe('withTestFile', function () {7 it('should work', function () {8 var testFile = path.resolve(__dirname, 'test.js');9 var strykerOptions = {10 };11 return stryker.runMutationTest(strykerOptions).then(function (result) {12 assert.equal(result.errorMessages.length, 0);13 assert.equal(result.killed, 0);14 assert.equal(result.survived, 0);15 assert.equal(result.timedOut, 0);16 assert.equal(result.noCoverage, 0);17 assert.equal(result.totalDetected, 0);18 assert.equal(result.totalUndetected, 0);19 assert.equal(result.totalMutants, 0);20 assert.equal(result.totalCovered, 0);21 assert.equal(result.totalValid, 0);22 assert.equal(result.totalInvalid, 0);23 assert.equal(result.totalIgnored, 0);24 assert.equal(result.errorMessages.length, 0);25 });26 });27});28module.exports = function (config) {29 config.set({30 });31};32{33}

Full Screen

Using AI Code Generation

copy

Full Screen

1const { withTestFile } = require('stryker-parent');2withTestFile(__filename, () => {3});4const { withTestFile } = require('stryker-parent');5withTestFile(__filename, () => {6 global.strykerTestReporter.onTestStart();7 global.strykerTestReporter.onTestResult({8 });9 global.strykerTestReporter.onTestResult({10 });11});12const { withTestFile } = require('stryker-parent');13withTestFile(__filename, () => {14 global.strykerTestRunner.run();15});16const { withTestFile } = require('stryker-parent');17withTestFile(__filename, () => {

Full Screen

Automation Testing Tutorials

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

LambdaTest Learning Hubs:

YouTube

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

Run stryker-parent automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful