How to use originalFileFor method in stryker-parent

Best JavaScript code snippet using stryker-parent

3-dry-run-executor.spec.ts

Source:3-dry-run-executor.spec.ts Github

copy

Full Screen

1import { EOL } from 'os';2import { Injector } from 'typed-inject';3import { assertions, factory, testInjector } from '@stryker-mutator/test-helpers';4import sinon from 'sinon';5import { TestRunner, CompleteDryRunResult, ErrorDryRunResult, TimeoutDryRunResult, DryRunResult } from '@stryker-mutator/api/test-runner';6import { expect } from 'chai';7import { Observable } from 'rxjs';8import { mergeMap } from 'rxjs/operators';9import { I } from '@stryker-mutator/util';10import { Timer } from '../../../src/utils/timer';11import { DryRunContext, DryRunExecutor, MutationTestContext } from '../../../src/process';12import { coreTokens } from '../../../src/di';13import { ConfigError } from '../../../src/errors';14import { ConcurrencyTokenProvider, Pool } from '../../../src/concurrent';15import { createTestRunnerPoolMock } from '../../helpers/producers';16import { Sandbox } from '../../../src/sandbox';17describe(DryRunExecutor.name, () => {18 let injectorMock: sinon.SinonStubbedInstance<Injector<MutationTestContext>>;19 let testRunnerPoolMock: sinon.SinonStubbedInstance<Pool<TestRunner>>;20 let sut: DryRunExecutor;21 let timerMock: sinon.SinonStubbedInstance<Timer>;22 let testRunnerMock: sinon.SinonStubbedInstance<Required<TestRunner>>;23 let concurrencyTokenProviderMock: sinon.SinonStubbedInstance<ConcurrencyTokenProvider>;24 let sandbox: sinon.SinonStubbedInstance<Sandbox>;25 beforeEach(() => {26 timerMock = sinon.createStubInstance(Timer);27 testRunnerMock = factory.testRunner();28 testRunnerPoolMock = createTestRunnerPoolMock();29 (30 testRunnerPoolMock.schedule as sinon.SinonStub<31 [Observable<unknown>, (testRunner: TestRunner, arg: unknown) => Promise<DryRunResult>],32 Observable<DryRunResult>33 >34 ).callsFake((item$, task) => item$.pipe(mergeMap((item) => task(testRunnerMock, item))));35 concurrencyTokenProviderMock = sinon.createStubInstance(ConcurrencyTokenProvider);36 injectorMock = factory.injector();37 injectorMock.resolve.withArgs(coreTokens.testRunnerPool).returns(testRunnerPoolMock as I<Pool<TestRunner>>);38 sandbox = sinon.createStubInstance(Sandbox);39 sut = new DryRunExecutor(40 injectorMock as Injector<DryRunContext>,41 testInjector.logger,42 testInjector.options,43 timerMock,44 concurrencyTokenProviderMock,45 sandbox46 );47 });48 it('should pass through any rejections', async () => {49 const expectedError = new Error('expected error');50 testRunnerMock.dryRun.rejects(expectedError);51 await expect(sut.execute()).rejectedWith(expectedError);52 });53 describe('check timeout', () => {54 let runResult: CompleteDryRunResult;55 beforeEach(() => {56 runResult = factory.completeDryRunResult();57 testRunnerMock.dryRun.resolves(runResult);58 runResult.tests.push(factory.successTestResult());59 });60 it('should use the configured timeout in ms if option provided', async () => {61 testInjector.options.dryRunTimeoutMinutes = 7.5;62 const timeoutMS = testInjector.options.dryRunTimeoutMinutes * 60 * 1000;63 await sut.execute();64 expect(testRunnerMock.dryRun).calledWithMatch({65 timeout: timeoutMS,66 });67 });68 it('should use the default timeout value if option not provided', async () => {69 const defaultTimeoutMS = 5 * 60 * 1000;70 await sut.execute();71 expect(testRunnerMock.dryRun).calledWithMatch({72 timeout: defaultTimeoutMS,73 });74 });75 });76 describe('disable bail', () => {77 let runResult: CompleteDryRunResult;78 beforeEach(() => {79 runResult = factory.completeDryRunResult();80 testRunnerMock.dryRun.resolves(runResult);81 runResult.tests.push(factory.successTestResult());82 });83 it('should bail by default', async () => {84 await sut.execute();85 expect(testRunnerMock.dryRun).calledWithMatch({86 disableBail: false,87 });88 });89 it('should bail when given the option', async () => {90 testInjector.options.disableBail = true;91 await sut.execute();92 expect(testRunnerMock.dryRun).calledWithMatch({93 disableBail: true,94 });95 });96 });97 describe('when the dryRun completes', () => {98 let runResult: CompleteDryRunResult;99 beforeEach(() => {100 runResult = factory.completeDryRunResult();101 testRunnerMock.dryRun.resolves(runResult);102 });103 it('should log about that this might take a while', async () => {104 runResult.tests.push(factory.successTestResult());105 await sut.execute();106 expect(testInjector.logger.info).calledWith(107 'Starting initial test run (command test runner with "perTest" coverage analysis). This may take a while.'108 );109 });110 describe('with successful tests', () => {111 it('should calculate the overhead time milliseconds', async () => {112 // Arrange113 runResult.tests.push(factory.successTestResult({ timeSpentMs: 10 }));114 runResult.tests.push(factory.successTestResult({ timeSpentMs: 2 }));115 runResult.tests.push(factory.successTestResult({ timeSpentMs: 6 }));116 const expectedOverHeadTimeMs = 82;117 timerMock.elapsedMs.returns(100);118 // Act119 const actualResultInjector = await sut.execute();120 // Assert121 expect(timerMock.mark).calledWith('Initial test run');122 expect(timerMock.elapsedMs).calledWith('Initial test run');123 expect(timerMock.mark).calledBefore(timerMock.elapsedMs);124 expect(actualResultInjector.provideValue).calledWithExactly(coreTokens.timeOverheadMS, expectedOverHeadTimeMs);125 });126 it('should never calculate a negative overhead time', async () => {127 runResult.tests.push(factory.successTestResult({ timeSpentMs: 10 }));128 timerMock.elapsedMs.returns(9);129 const injector = await sut.execute();130 expect(injector.provideValue).calledWithExactly(coreTokens.timeOverheadMS, 0);131 });132 it('should provide the dry run result', async () => {133 timerMock.elapsedMs.returns(42);134 runResult.tests.push(factory.successTestResult());135 runResult.mutantCoverage = {136 perTest: {},137 static: {},138 };139 const actualInjector = await sut.execute();140 expect(actualInjector.provideValue).calledWithExactly(coreTokens.dryRunResult, runResult);141 });142 it('should remap test files that are reported', async () => {143 runResult.tests.push(factory.successTestResult({ fileName: '.stryker-tmp/sandbox-123/test/foo.spec.js' }));144 sandbox.originalFileFor.returns('test/foo.spec.js');145 await sut.execute();146 const actualDryRunResult = injectorMock.provideValue.getCalls().find((call) => call.args[0] === coreTokens.dryRunResult)!147 .args[1] as DryRunResult;148 assertions.expectCompleted(actualDryRunResult);149 expect(actualDryRunResult.tests[0].fileName).eq('test/foo.spec.js');150 expect(sandbox.originalFileFor).calledWith('.stryker-tmp/sandbox-123/test/foo.spec.js');151 });152 it('should remap test locations when type checking was disabled for a test file', async () => {153 runResult.tests.push(154 factory.successTestResult({ fileName: '.stryker-tmp/sandbox-123/test/foo.spec.js', startPosition: { line: 3, column: 1 } }),155 factory.successTestResult({ fileName: '.stryker-tmp/sandbox-123/testResources/foo.spec.js', startPosition: { line: 5, column: 1 } })156 );157 sandbox.originalFileFor158 .withArgs('.stryker-tmp/sandbox-123/test/foo.spec.js')159 .returns('test/foo.spec.js')160 .withArgs('.stryker-tmp/sandbox-123/testResources/foo.spec.js')161 .returns('testResources/foo.spec.js');162 await sut.execute();163 const actualDryRunResult = injectorMock.provideValue.getCalls().find((call) => call.args[0] === coreTokens.dryRunResult)!164 .args[1] as DryRunResult;165 assertions.expectCompleted(actualDryRunResult);166 expect(actualDryRunResult.tests[0].startPosition).deep.eq({ line: 2, column: 1 });167 expect(actualDryRunResult.tests[1].startPosition).deep.eq({ line: 5, column: 1 }); // should not have been remapped, since type checking wasn't disabled here168 });169 it('should have logged the amount of tests ran', async () => {170 runResult.tests.push(factory.successTestResult({ timeSpentMs: 10 }));171 runResult.tests.push(factory.successTestResult({ timeSpentMs: 10 }));172 timerMock.humanReadableElapsed.returns('30 seconds');173 timerMock.humanReadableElapsed.withArgs('Initial test run').returns('2 seconds');174 timerMock.elapsedMs.returns(30000);175 timerMock.elapsedMs.withArgs('Initial test run').returns(2000);176 await sut.execute();177 expect(testInjector.logger.info).to.have.been.calledWith(178 'Initial test run succeeded. Ran %s tests in %s (net %s ms, overhead %s ms).',179 2,180 '2 seconds',181 20,182 1980183 );184 });185 it('should log when there were no tests', async () => {186 await expect(sut.execute()).rejectedWith(187 ConfigError,188 'No tests were executed. Stryker will exit prematurely. Please check your configuration.'189 );190 });191 });192 describe('with failed tests', () => {193 beforeEach(() => {194 runResult.tests.push(factory.failedTestResult({ name: 'foo is bar', failureMessage: 'foo was baz' }));195 runResult.tests.push(factory.failedTestResult({ name: 'bar is baz', failureMessage: 'bar was qux' }));196 });197 it('should have logged the errors', async () => {198 await expect(sut.execute()).rejected;199 expect(testInjector.logger.error).calledWith(200 `One or more tests failed in the initial test run:${EOL}\tfoo is bar${EOL}\t\tfoo was baz${EOL}\tbar is baz${EOL}\t\tbar was qux`201 );202 });203 it('should reject with correct message', async () => {204 await expect(sut.execute()).rejectedWith(ConfigError, 'There were failed tests in the initial test run.');205 });206 });207 });208 describe('when dryRun errors', () => {209 let runResult: ErrorDryRunResult;210 beforeEach(() => {211 runResult = factory.errorDryRunResult();212 testRunnerMock.dryRun.resolves(runResult);213 });214 it('should have logged the errors', async () => {215 runResult.errorMessage = 'cannot call foo() on undefined';216 await expect(sut.execute()).rejected;217 expect(testInjector.logger.error).calledWith(`One or more tests resulted in an error:${EOL}\tcannot call foo() on undefined`);218 });219 it('should reject with correct message', async () => {220 await expect(sut.execute()).rejectedWith('Something went wrong in the initial test run');221 });222 });223 describe('when dryRun timedOut', () => {224 let runResult: TimeoutDryRunResult;225 beforeEach(() => {226 runResult = factory.timeoutDryRunResult();227 testRunnerMock.dryRun.resolves(runResult);228 });229 it('should have logged the timeout', async () => {230 await expect(sut.execute()).rejected;231 expect(testInjector.logger.error).calledWith('Initial test run timed out!');232 });233 it('should reject with correct message', async () => {234 await expect(sut.execute()).rejectedWith('Something went wrong in the initial test run');235 });236 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const originalFileFor = require('stryker-parent').originalFileFor;2const originalFile = originalFileFor('test.js');3console.log(originalFile);4const originalFileFor = require('stryker-parent').originalFileFor;5const originalFile = originalFileFor('src/test.js');6console.log(originalFile);7const originalFileFor = require('stryker-parent').originalFileFor;8const originalFile = originalFileFor('test.js');9console.log(originalFile);10const originalFileFor = require('stryker-parent').originalFileFor;11const originalFile = originalFileFor('src/test.js');12console.log(originalFile);13const originalFileFor = require('stryker-parent').originalFileFor;14const originalFile = originalFileFor('test.js');15console.log(originalFile);16const originalFileFor = require('stryker-parent').originalFileFor;17const originalFile = originalFileFor('src/test.js');18console.log(originalFile);19const originalFileFor = require('stryker-parent').originalFileFor;20const originalFile = originalFileFor('test.js');21console.log(originalFile);22const originalFileFor = require('stryker-parent').originalFileFor;23const originalFile = originalFileFor('src/test.js');24console.log(originalFile);25const originalFileFor = require('stryker-parent').originalFileFor;26const originalFile = originalFileFor('test.js');27console.log(originalFile);28const originalFileFor = require('stryker-parent').originalFileFor;29const originalFile = originalFileFor('src/test.js');30console.log(originalFile

Full Screen

Using AI Code Generation

copy

Full Screen

1var fs = require('fs');2var path = require('path');3var originalFileFor = require('stryker-parent').originalFileFor;4var originalFile = originalFileFor('test.js');5console.log(originalFile);6console.log(originalFile === fs.readFileSync(path.resolve(__dirname, 'original.js'), 'utf8'));

Full Screen

Using AI Code Generation

copy

Full Screen

1var file = originalFileFor('test.js');2console.log(file.content);3var file = originalFileFor('test.js');4console.log(file.content);5var file = originalFileFor('test.js');6console.log(file.content);7var file = originalFileFor('test.js');8console.log(file.content);9var file = originalFileFor('test.js');10console.log(file.content);11var file = originalFileFor('test.js');12console.log(file.content);13var file = originalFileFor('test.js');14console.log(file.content);15var file = originalFileFor('test.js');16console.log(file.content);17var file = originalFileFor('test.js');18console.log(file.content);19var file = originalFileFor('test.js');20console.log(file.content);21var file = originalFileFor('test.js');22console.log(file.content);23var file = originalFileFor('test.js');24console.log(file.content);25var file = originalFileFor('test.js');26console.log(file.content);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { originalFileFor } = require('stryker-parent');2const originalFile = originalFileFor('test.js');3const originalFile = originalFileFor('src/test.js');4const { originalFileFor } = require('stryker-parent');5const originalFile = originalFileFor('test.js');6const originalFile = originalFileFor('src/test.js');7const { originalFileFor } = require('stryker-parent');8const originalFile = originalFileFor('test.js');9const originalFile = originalFileFor('src/test.js');10const originalFile = originalFileFor('src/subdir/test.js');11const { originalFileFor } = require('stryker-parent');12const originalFile = originalFileFor('test.js');13const originalFile = originalFileFor('src/test.js');14const originalFile = originalFileFor('src/subdir/test.js');15const originalFile = originalFileFor('src/subdir/subdir2/test.js');16const { originalFileFor } = require('stryker-parent');17const originalFile = originalFileFor('test.js');18const originalFile = originalFileFor('src/test.js');19const originalFile = originalFileFor('src/subdir/test.js');20const originalFile = originalFileFor('src/subdir/subdir2/test.js');21const { originalFileFor } = require('stryker-parent');22const originalFile = originalFileFor('test

Full Screen

Using AI Code Generation

copy

Full Screen

1const originalFileFor = require('stryker-parent').originalFileFor;2console.log(originalFileFor('foo.js'));3module.exports = {4 originalFileFor: function (fileName) {5 return fileName;6 }7};8{9}

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = function (strykerConfig) {2 return function (config) {3 config.set({4 { pattern: 'src/**/*.js', included: false },5 { pattern: 'test/**/*.js', included: false },6 ...config.mutator.mutate.map((mutant) => ({7 pattern: mutant.originalFileFor(config),8 }))9 });10 };11};12module.exports = function (config) {13 config.set({14 parent: {15 },16 });17};

Full Screen

Using AI Code Generation

copy

Full Screen

1const { originalFileFor } = require('stryker-parent');2const path = require('path');3const originalFile = originalFileFor(path.resolve(__dirname, 'src', 'foo.js'));4const { originalFileFor } = require('stryker-parent');5const path = require('path');6const originalFile = originalFileFor(path.resolve(__dirname, 'foo.js'));7const { originalFileFor } = require('stryker-parent');8const path = require('path');9const originalFile = originalFileFor(path.resolve(__dirname, 'bar', 'foo.js'));10const { originalFileFor } = require('stryker-parent');11const path = require('path');12const originalFile = originalFileFor(path.resolve(__dirname, 'bar', 'foo.js'));13const { originalFileFor } = require('stryker-parent');14const path = require('path');15const originalFile = originalFileFor(path.resolve(__dirname, 'bar', 'foo.js'));16const { originalFileFor } = require('stryker-parent');17const path = require('path');18const originalFile = originalFileFor(path.resolve(__dirname, 'bar', 'foo.js'));

Full Screen

Using AI Code Generation

copy

Full Screen

1const originalFileFor = require('stryker-parent').originalFileFor;2const original = originalFileFor('test.js');3const original = originalFileFor('test.js', 'test');4const originalFileFor = require('stryker-parent').originalFileFor;5const original = originalFileFor('test.js');6const original = originalFileFor('test.js', 'test');7const originalFileFor = require('stryker-parent').originalFileFor;8const original = originalFileFor('test.js');9const original = originalFileFor('test.js', 'test');10const originalFileFor = require('stryker-parent').originalFileFor;11const original = originalFileFor('test.js');12const original = originalFileFor('test.js', 'test');13const originalFileFor = require('stryker-parent').originalFileFor;14const original = originalFileFor('test.js');15const original = originalFileFor('test.js', 'test');16const originalFileFor = require('stryker-parent').originalFileFor;17const original = originalFileFor('test.js');18const original = originalFileFor('test.js', 'test');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { originalFileFor } = require('stryker-parent');2console.log(originalFileFor('test.js'));3const { originalFileFor } = require('stryker-parent');4console.log(originalFileFor('../test.js'));5const { originalFileFor } = require('stryker-parent');6console.log(originalFileFor('../../test.js'));7const { originalFileFor } = require('stryker-parent');8console.log(originalFileFor('../../../test.js'));9const { originalFileFor } = require('stryker-parent');10console.log(originalFileFor('../../../../test.js'));11const { originalFileFor } = require('stryker-parent');12console.log(originalFileFor('../../../../../test.js'));13const { originalFileFor } = require('stryker-parent');14console.log(originalFileFor('../../../../../../test.js'));15const { originalFileFor } = require('stryker-parent');16console.log(originalFileFor('../../../../../../../test.js'));17const { originalFileFor } = require('stryker-parent');18console.log(original

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