How to use netTimeMS method in stryker-parent

Best JavaScript code snippet using stryker-parent

3-dry-run-executor.ts

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

copy

Full Screen

1import { EOL } from 'os';2import { Injector } from 'typed-inject';3import { I } from '@stryker-mutator/util';4import { Logger } from '@stryker-mutator/api/logging';5import { commonTokens, tokens } from '@stryker-mutator/api/plugin';6import { StrykerOptions, Mutant } from '@stryker-mutator/api/core';7import {8 DryRunResult,9 TestRunner,10 DryRunStatus,11 CompleteDryRunResult,12 TestStatus,13 TestResult,14 FailedTestResult,15 ErrorDryRunResult,16} from '@stryker-mutator/api/test-runner';17import { lastValueFrom, of } from 'rxjs';18import { Checker } from '@stryker-mutator/api/check';19import { coreTokens } from '../di';20import { Sandbox } from '../sandbox/sandbox';21import { Timer } from '../utils/timer';22import { createTestRunnerFactory } from '../test-runner';23import { MutationTestReportHelper } from '../reporters/mutation-test-report-helper';24import { ConfigError } from '../errors';25import { findMutantTestCoverage } from '../mutants';26import { ConcurrencyTokenProvider, Pool, createTestRunnerPool } from '../concurrent';27import { FileMatcher } from '../config';28import { MutationTestContext } from './4-mutation-test-executor';29import { MutantInstrumenterContext } from './2-mutant-instrumenter-executor';30const INITIAL_TEST_RUN_MARKER = 'Initial test run';31export interface DryRunContext extends MutantInstrumenterContext {32 [coreTokens.sandbox]: I<Sandbox>;33 [coreTokens.mutants]: readonly Mutant[];34 [coreTokens.checkerPool]: I<Pool<Checker>>;35 [coreTokens.concurrencyTokenProvider]: I<ConcurrencyTokenProvider>;36}37/**38 * A small object that keeps the timing variables of a test run.39 */40interface Timing {41 /**42 * The time that the test runner was actually executing tests in milliseconds.43 */44 net: number;45 /**46 * the time that was spend not executing tests in milliseconds.47 * So the time it took to start the test runner and to report the result.48 */49 overhead: number;50 /**51 * The total time spent (net + overhead) in a human readable format52 */53 humanReadableTimeElapsed: string;54}55function isFailedTest(testResult: TestResult): testResult is FailedTestResult {56 return testResult.status === TestStatus.Failed;57}58export class DryRunExecutor {59 public static readonly inject = tokens(60 commonTokens.injector,61 commonTokens.logger,62 commonTokens.options,63 coreTokens.timer,64 coreTokens.concurrencyTokenProvider,65 coreTokens.sandbox66 );67 constructor(68 private readonly injector: Injector<DryRunContext>,69 private readonly log: Logger,70 private readonly options: StrykerOptions,71 private readonly timer: I<Timer>,72 private readonly concurrencyTokenProvider: I<ConcurrencyTokenProvider>,73 public readonly sandbox: I<Sandbox>74 ) {}75 public async execute(): Promise<Injector<MutationTestContext>> {76 const testRunnerInjector = this.injector77 .provideFactory(coreTokens.testRunnerFactory, createTestRunnerFactory)78 .provideValue(coreTokens.testRunnerConcurrencyTokens, this.concurrencyTokenProvider.testRunnerToken$)79 .provideFactory(coreTokens.testRunnerPool, createTestRunnerPool);80 const testRunnerPool = testRunnerInjector.resolve(coreTokens.testRunnerPool);81 const { dryRunResult, timing } = await lastValueFrom(testRunnerPool.schedule(of(0), (testRunner) => this.timeDryRun(testRunner)));82 this.logInitialTestRunSucceeded(dryRunResult.tests, timing);83 if (!dryRunResult.tests.length) {84 throw new ConfigError('No tests were executed. Stryker will exit prematurely. Please check your configuration.');85 }86 return testRunnerInjector87 .provideValue(coreTokens.timeOverheadMS, timing.overhead)88 .provideValue(coreTokens.dryRunResult, dryRunResult)89 .provideClass(coreTokens.mutationTestReportHelper, MutationTestReportHelper)90 .provideFactory(coreTokens.mutantsWithTestCoverage, findMutantTestCoverage);91 }92 private validateResultCompleted(runResult: DryRunResult): asserts runResult is CompleteDryRunResult {93 switch (runResult.status) {94 case DryRunStatus.Complete:95 const failedTests = runResult.tests.filter(isFailedTest);96 if (failedTests.length) {97 this.logFailedTestsInInitialRun(failedTests);98 throw new ConfigError('There were failed tests in the initial test run.');99 }100 return;101 case DryRunStatus.Error:102 this.logErrorsInInitialRun(runResult);103 break;104 case DryRunStatus.Timeout:105 this.logTimeoutInitialRun();106 break;107 }108 throw new Error('Something went wrong in the initial test run');109 }110 private async timeDryRun(testRunner: TestRunner): Promise<{ dryRunResult: CompleteDryRunResult; timing: Timing }> {111 const dryRunTimeout = this.options.dryRunTimeoutMinutes * 1000 * 60;112 this.timer.mark(INITIAL_TEST_RUN_MARKER);113 this.log.info(114 `Starting initial test run (${this.options.testRunner} test runner with "${this.options.coverageAnalysis}" coverage analysis). This may take a while.`115 );116 this.log.debug(`Using timeout of ${dryRunTimeout} ms.`);117 const dryRunResult = await testRunner.dryRun({118 timeout: dryRunTimeout,119 coverageAnalysis: this.options.coverageAnalysis,120 disableBail: this.options.disableBail,121 });122 const grossTimeMS = this.timer.elapsedMs(INITIAL_TEST_RUN_MARKER);123 const humanReadableTimeElapsed = this.timer.humanReadableElapsed(INITIAL_TEST_RUN_MARKER);124 this.validateResultCompleted(dryRunResult);125 this.remapSandboxFilesToOriginalFiles(dryRunResult);126 const timing = this.calculateTiming(grossTimeMS, humanReadableTimeElapsed, dryRunResult.tests);127 return { dryRunResult, timing };128 }129 /**130 * Remaps test files to their respective original names outside the sandbox.131 * @param dryRunResult the completed result132 */133 private remapSandboxFilesToOriginalFiles(dryRunResult: CompleteDryRunResult) {134 const disableTypeCheckingFileMatcher = new FileMatcher(this.options.disableTypeChecks);135 dryRunResult.tests.forEach((test) => {136 if (test.fileName) {137 test.fileName = this.sandbox.originalFileFor(test.fileName);138 // HACK line numbers of the tests can be offset by 1 because the disable type checks preprocessor could have added a `// @ts-nocheck` line.139 // We correct for that here if needed140 // If we do more complex stuff in sandbox preprocessing in the future, we might want to add a robust remapping logic141 if (test.startPosition && disableTypeCheckingFileMatcher.matches(test.fileName)) {142 test.startPosition.line--;143 }144 }145 });146 }147 private logInitialTestRunSucceeded(tests: TestResult[], timing: Timing) {148 this.log.info(149 'Initial test run succeeded. Ran %s tests in %s (net %s ms, overhead %s ms).',150 tests.length,151 timing.humanReadableTimeElapsed,152 timing.net,153 timing.overhead154 );155 }156 /**157 * Calculates the timing variables for the test run.158 * grossTime = NetTime + overheadTime159 *160 * The overhead time is used to calculate exact timeout values during mutation testing.161 * See timeoutMS setting in README for more information on this calculation162 */163 private calculateTiming(grossTimeMS: number, humanReadableTimeElapsed: string, tests: readonly TestResult[]): Timing {164 const netTimeMS = tests.reduce((total, test) => total + test.timeSpentMs, 0);165 const overheadTimeMS = grossTimeMS - netTimeMS;166 return {167 net: netTimeMS,168 overhead: overheadTimeMS < 0 ? 0 : overheadTimeMS,169 humanReadableTimeElapsed,170 };171 }172 private logFailedTestsInInitialRun(failedTests: FailedTestResult[]): void {173 let message = 'One or more tests failed in the initial test run:';174 failedTests.forEach((test) => {175 message += `${EOL}\t${test.name}`;176 message += `${EOL}\t\t${test.failureMessage}`;177 });178 this.log.error(message);179 }180 private logErrorsInInitialRun(runResult: ErrorDryRunResult) {181 const message = `One or more tests resulted in an error:${EOL}\t${runResult.errorMessage}`;182 this.log.error(message);183 }184 private logTimeoutInitialRun() {185 this.log.error('Initial test run timed out!');186 }...

Full Screen

Full Screen

mixin-history.js

Source:mixin-history.js Github

copy

Full Screen

1import dayjs from 'dayjs'2export default {3 computed: {4 historyStorage: {5 get() {6 let value = []7 const stored = localStorage.getItem('_tuble_history')8 if (stored) {9 value = JSON.parse(stored)10 }11 return value12 },13 set(data) {14 const str = JSON.stringify(data)15 localStorage.setItem('_tuble_history', str)16 },17 },18 },19 methods: {20 addResponseToHistory(item) {21 const h = this.historyStorage22 h.push({23 netMoves: item.NetMoves,24 netTime: dayjs(item.NetTimeMs).format('mm:ss'),25 gameDate: this.$store.state.game.gameDate,26 })27 if (h.length > 30) {28 // localStorage size is limited. We will keep only 30 entries.29 h.shift()30 }31 this.historyStorage = h32 },33 },...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const strykerParent = require('stryker-parent');2console.log(strykerParent.netTimeMS());3const strykerParent = require('stryker-parent');4console.log(strykerParent.netTimeMS());5const strykerParent = require('stryker-parent');6console.log(strykerParent.netTimeMS());7const strykerParent = require('stryker-parent');8console.log(strykerParent.netTimeMS());

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