How to use createKarmaSpec method in stryker-parent

Best JavaScript code snippet using stryker-parent

karma-test-runner.spec.ts

Source:karma-test-runner.spec.ts Github

copy

Full Screen

...150 return dryRunPromise;151 }152 it('should report completed specs as test results', async () => {153 const specResults = [154 createKarmaSpec({ id: 'spec1', suite: ['foo'], description: 'should bar', time: 42, success: true }),155 createKarmaSpec({156 id: 'spec2',157 suite: ['bar', 'when baz'],158 description: 'should qux',159 log: ['expected quux to be qux', 'expected length of 1'],160 time: 44,161 success: false,162 }),163 createKarmaSpec({ id: 'spec3', suite: ['quux'], description: 'should corge', time: 45, skipped: true }),164 ];165 const expectedTests = [166 factory.testResult({ id: 'spec1', status: TestStatus.Success, timeSpentMs: 42, name: 'foo should bar' }),167 factory.testResult({168 id: 'spec2',169 status: TestStatus.Failed,170 timeSpentMs: 44,171 name: 'bar when baz should qux',172 failureMessage: 'expected quux to be qux, expected length of 1',173 }),174 factory.testResult({ id: 'spec3', status: TestStatus.Skipped, timeSpentMs: 45, name: 'quux should corge' }),175 ];176 const actualResult = await actDryRun({ specResults });177 assertions.expectCompleted(actualResult);178 expect(actualResult.tests).deep.eq(expectedTests);179 });180 it('should run karma with custom karma configuration', async () => {181 // Arrange182 projectStarterMock.start.resolves({ exitPromise: new Task<number>().promise });183 StrykerReporter.instance.karmaConfig = await karma.config.parseConfig(null, {}, { promiseConfig: true });184 StrykerReporter.instance.karmaConfig.hostname = 'www.localhost.com';185 StrykerReporter.instance.karmaConfig.port = 1337;186 StrykerReporter.instance.karmaConfig.listenAddress = 'www.localhost.com:1337';187 const parseConfigStub = sinon.stub(karma.config, 'parseConfig');188 const expectedRunConfig = { custom: 'config' };189 parseConfigStub.resolves(expectedRunConfig);190 const initPromise = sut.init();191 StrykerReporter.instance.onBrowsersReady();192 await initPromise;193 // Act194 await actDryRun({});195 // Assert196 expect(karmaRunStub).calledWith(expectedRunConfig, sinon.match.func);197 expect(parseConfigStub).calledWithExactly(null, { hostname: 'www.localhost.com', port: 1337, listenAddress: 'www.localhost.com:1337' });198 });199 it('should log when karma run is done', async () => {200 await actDryRun({});201 expect(testInjector.logger.debug).calledWith('karma run done with ', 0);202 });203 it('should clear run results between runs', async () => {204 const firstTestResult = createKarmaSpec({ id: 'spec1', suite: ['foo'], description: 'should bar', time: 42, success: true });205 const expectedTestResult = factory.testResult({ id: 'spec1', status: TestStatus.Success, timeSpentMs: 42, name: 'foo should bar' });206 const actualFirstResult = await actDryRun({ specResults: [firstTestResult] });207 const actualSecondResult = await actDryRun({});208 assertions.expectCompleted(actualFirstResult);209 assertions.expectCompleted(actualSecondResult);210 expect(actualFirstResult.tests).deep.eq([expectedTestResult]);211 expect(actualSecondResult.tests).lengthOf(0);212 });213 it('should configure the coverage analysis in the test hooks middleware', async () => {214 await actDryRun({ options: factory.dryRunOptions({ coverageAnalysis: 'all' }) });215 expect(testHooksMiddlewareMock.configureCoverageAnalysis).calledWithExactly('all');216 });217 it('should add coverage report when the reporter raises the "coverage_report" event', async () => {218 const expectedCoverageReport = factory.mutantCoverage({ static: { '1': 4 } });219 const actualResult = await actDryRun({ mutantCoverage: expectedCoverageReport });220 assertions.expectCompleted(actualResult);221 expect(actualResult.mutantCoverage).eq(expectedCoverageReport);222 });223 it('should add error when the reporter raises the "browser_error" event', async () => {224 const expectedError = 'Global variable undefined';225 const actualResult = await actDryRun({ runResults: createKarmaTestResults({ error: true }), browserError: [createBrowser(), expectedError] });226 assertions.expectErrored(actualResult);227 expect(actualResult.errorMessage).deep.eq(expectedError);228 });229 it('should report state Error when tests where ran and run completed in an error', async () => {230 const actualResult = await actDryRun({231 runResults: createKarmaTestResults({ error: true }),232 specResults: [createKarmaSpec()],233 browserError: [createBrowser(), 'some error'],234 });235 assertions.expectErrored(actualResult);236 });237 });238 describe('mutantRun', () => {239 let sut: KarmaTestRunner;240 function actMutantRun({241 specResults = [],242 runResults = createKarmaTestResults(),243 options = factory.mutantRunOptions(),244 mutantCoverage = factory.mutantCoverage(),245 hitCount = undefined,246 browserError = undefined,247 }: {248 specResults?: KarmaSpec[];249 runResults?: TestResults;250 options?: MutantRunOptions;251 hitCount?: number;252 mutantCoverage?: MutantCoverage;253 browserError?: [browser: Browser, error: any] | undefined;254 }) {255 const promise = sut.mutantRun(options);256 actRun({ specResults, runResults, mutantCoverage, hitCount, browserError });257 return promise;258 }259 beforeEach(() => {260 sut = createSut();261 karmaRunStub.callsArgOn(1, 0);262 });263 it('should configure the mutant run on the middleware', async () => {264 const options = factory.mutantRunOptions({ testFilter: ['foobar'] });265 await actMutantRun({ options });266 expect(testHooksMiddlewareMock.configureMutantRun).calledOnceWithExactly(options);267 });268 it('should correctly report a survived mutant', async () => {269 const result = await actMutantRun({ specResults: [createKarmaSpec({ success: true })] });270 assertions.expectSurvived(result);271 expect(result.nrOfTests).eq(1);272 });273 it('should correctly report a killed mutant', async () => {274 const result = await actMutantRun({ specResults: [createKarmaSpec({ success: true }), createKarmaSpec({ success: false })] });275 assertions.expectKilled(result);276 expect(result.nrOfTests).eq(2);277 });278 it('should report a timeout when the browser disconnects', async () => {279 arrangeLauncherMock();280 const onGoingRun = sut.mutantRun(factory.mutantRunOptions());281 StrykerReporter.instance.onRunStart();282 StrykerReporter.instance.onBrowserError(createBrowser({ id: '42', state: 'DISCONNECTED' }), 'disconnected');283 StrykerReporter.instance.onRunComplete(null, createKarmaTestResults({ disconnected: true }));284 StrykerReporter.instance.onBrowsersReady();285 const result = await onGoingRun;286 assertions.expectTimeout(result);287 expect(result.reason).eq('Browser disconnected during test execution. Karma error: disconnected');288 });289 it('should restart the browser and wait until it is restarted when it gets disconnected (issue #2989)', async () => {290 // Arrange291 const { launcher, karmaServer } = arrangeLauncherMock();292 // Act293 let runCompleted = false;294 const onGoingRun = sut.mutantRun(factory.mutantRunOptions()).then(() => (runCompleted = true));295 StrykerReporter.instance.onRunStart();296 StrykerReporter.instance.onBrowserError(createBrowser({ id: '42', state: 'DISCONNECTED' }), 'disconnected');297 // Assert298 expect(launcher.restart).calledWith('42');299 expect(karmaServer.get).calledWith('launcher');300 StrykerReporter.instance.onRunComplete(null, createKarmaTestResults({ disconnected: true }));301 await tick();302 expect(runCompleted).false;303 StrykerReporter.instance.onBrowsersReady();304 await onGoingRun;305 });306 it('should report a timeout when the hitLimit was reached', async () => {307 const result = await actMutantRun({308 options: factory.mutantRunOptions({ hitLimit: 9 }),309 specResults: [createKarmaSpec({ success: false })],310 hitCount: 10,311 });312 assertions.expectTimeout(result);313 expect(result.reason).contains('Hit limit reached (10/9)');314 });315 it('should reset the hitLimit between runs', async () => {316 const firstResult = await actMutantRun({317 options: factory.mutantRunOptions({ hitLimit: 9 }),318 specResults: [createKarmaSpec({ success: false })],319 hitCount: 10,320 });321 const secondResult = await actMutantRun({322 options: factory.mutantRunOptions({ hitLimit: undefined }),323 specResults: [createKarmaSpec({ success: false })],324 hitCount: 10,325 });326 assertions.expectTimeout(firstResult);327 assertions.expectKilled(secondResult);328 });329 });330 describe('dispose', () => {331 beforeEach(async () => {332 StrykerReporter.instance.karmaConfig = await karma.config.parseConfig(null, {}, { promiseConfig: true });333 });334 it('should not do anything if there is no karma server', async () => {335 const sut = createSut();336 await expect(sut.dispose()).not.rejected;337 });338 it('should stop the karma server', async () => {339 const karmaServerMock = sinon.createStubInstance(karma.Server);340 StrykerReporter.instance.karmaServer = karmaServerMock;341 const sut = createSut();342 await sut.dispose();343 expect(karmaServerMock.stop).called;344 });345 it('should await the exit promise provided at startup', async () => {346 // Arrange347 const sut = createSut();348 const karmaServerMock = sinon.createStubInstance(karma.Server);349 StrykerReporter.instance.karmaServer = karmaServerMock;350 const exitTask = new Task<number>();351 let disposeResolved = false;352 projectStarterMock.start.resolves({ exitPromise: exitTask.promise });353 const initPromise = sut.init();354 StrykerReporter.instance.onBrowsersReady();355 await initPromise;356 // Act357 const onGoingDisposal = sut.dispose().then(() => (disposeResolved = true));358 // Assert359 await tick();360 expect(disposeResolved).false;361 exitTask.resolve(1);362 await onGoingDisposal;363 });364 });365 function actRun({366 specResults,367 runResults,368 mutantCoverage,369 hitCount,370 browserError,371 }: {372 specResults: KarmaSpec[];373 runResults: TestResults;374 mutantCoverage: MutantCoverage;375 hitCount: number | undefined;376 browserError: [browser: Browser, error: any] | undefined;377 }) {378 StrykerReporter.instance.onRunStart();379 specResults.forEach((spec) => StrykerReporter.instance.onSpecComplete(null, spec));380 if (browserError) {381 StrykerReporter.instance.onBrowserError(...browserError);382 }383 StrykerReporter.instance.onBrowserComplete(null, { mutantCoverage, hitCount });384 StrykerReporter.instance.onRunComplete(null, runResults);385 }386});387function arrangeLauncherMock() {388 const karmaServerMock = sinon.createStubInstance(karma.Server);389 const launcherMock = sinon.createStubInstance(karma.launcher.Launcher);390 StrykerReporter.instance.karmaServer = karmaServerMock;391 karmaServerMock.get.returns(launcherMock);392 return { launcher: launcherMock, karmaServer: karmaServerMock };393}394function createKarmaSpec(overrides?: Partial<KarmaSpec>): KarmaSpec {395 return {396 description: 'baz',397 id: '1',398 log: [],399 skipped: false,400 success: true,401 suite: ['foo', 'bar'],402 time: 42,403 ...overrides,404 };405}406function createKarmaTestResults(overrides?: Partial<TestResults>): TestResults {407 return {408 disconnected: false,...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var stryker = require('stryker-parent');2var config = stryker.createKarmaSpec({3 { pattern: 'src/**/*.js', mutated: true, included: false },4 { pattern: 'test/**/*.js', mutated: false, included: false }5 karma: {6 }7});8module.exports = function (config) {9 config.set(config);10};11module.exports = function (config) {12 config.set({13 preprocessors: {14 },15 coverageReporter: {16 },17 });18};

Full Screen

Using AI Code Generation

copy

Full Screen

1const { createKarmaSpec } = require('stryker-parent');2module.exports = createKarmaSpec({3});4const { createKarmaConfig } = require('stryker-parent');5module.exports = createKarmaConfig({6});

Full Screen

Using AI Code Generation

copy

Full Screen

1const createKarmaConfig = require('stryker-parent/config/createKarmaConfig');2const config = createKarmaConfig({3});4module.exports = function(config) {5 config.set(config);6}7module.exports = require('./test.js');8module.exports = function(config) {9 config.set({10 karma: {11 config: require('./karma.conf.js')12 }13 });14};

Full Screen

Using AI Code Generation

copy

Full Screen

1var createKarmaSpec = require('stryker-parent').createKarmaSpec;2module.exports = createKarmaSpec({3 karmaConfig: {4 {pattern: 'src/**/*.js', included: false},5 {pattern: 'test/**/*.js', included: false},6 {pattern: 'test/**/*Spec.js', included: false},7 {pattern: 'test/**/*Spec.js', included: true}8 preprocessors: {9 },10 coverageReporter: {11 }12 }13});14preprocessors: { 'src/*.js': ['coverage'] }15coverageReporter: { type: 'in-memory' }16{pattern: 'src/**/*.js', included: false}17{pattern: 'test/**/*.js', included: false}18{pattern: 'test/**/*Spec.js', included: false}19{pattern: 'test/**/*Spec.js', included: true}

Full Screen

Using AI Code Generation

copy

Full Screen

1const { createKarmaSpec } = require('stryker-parent');2createKarmaSpec(__filename, {3});4module.exports = function(config) {5 config.set({6 });7};

Full Screen

Using AI Code Generation

copy

Full Screen

1const stryker = require('stryker-parent');2const path = require('path');3const files = stryker.createKarmaSpec(path.resolve('test.js'), 'test', 'test.js');4console.log(files);5[ { pattern: 'test.js',6 includedInMutantRun: true } ]7const stryker = require('stryker-parent');8const path = require('path');9const files = stryker.createKarmaSpec(path.resolve('test.js'), 'test', 'test.js');10console.log(files);11[ { pattern: 'test.js',12 includedInMutantRun: true } ]13const stryker = require('stryker-parent');14const path = require('path');15const files = stryker.createKarmaSpec(path.resolve('test.js'), 'test', 'test.js');16console.log(files);17[ { pattern: 'test.js',18 includedInMutantRun: true } ]19const stryker = require('stryker-parent');20const path = require('path');21const files = stryker.createKarmaSpec(path.resolve('test.js'), 'test', 'test.js');22console.log(files);23[ { pattern: 'test.js',24 includedInMutantRun: true } ]25const stryker = require('stryker-parent');26const path = require('path');27const files = stryker.createKarmaSpec(path.resolve('test.js'), 'test', 'test.js');28console.log(files);29[ { pattern: 'test.js',

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