How to use testFileFullName method in stryker-parent

Best JavaScript code snippet using stryker-parent

mutant-test-planner.spec.ts

Source:mutant-test-planner.spec.ts Github

copy

Full Screen

1import path from 'path';2import sinon from 'sinon';3import { expect } from 'chai';4import { factory, testInjector } from '@stryker-mutator/test-helpers';5import { MutantEarlyResultPlan, MutantRunPlan, MutantTestPlan, PlanKind, Mutant, MutantStatus, schema } from '@stryker-mutator/api/core';6import { Reporter } from '@stryker-mutator/api/report';7import { MutantTestPlanner } from '../../../src/mutants/index.js';8import { coreTokens } from '../../../src/di/index.js';9import { Sandbox } from '../../../src/sandbox/index.js';10import { Project } from '../../../src/fs/index.js';11import { FileSystemTestDouble } from '../../helpers/file-system-test-double.js';12import { loc } from '../../helpers/producers.js';13import { TestCoverageTestDouble } from '../../helpers/test-coverage-test-double.js';14import { IncrementalDiffer } from '../../../src/mutants/incremental-differ.js';15const TIME_OVERHEAD_MS = 501;16describe(MutantTestPlanner.name, () => {17 let reporterMock: sinon.SinonStubbedInstance<Required<Reporter>>;18 let sandboxMock: sinon.SinonStubbedInstance<Sandbox>;19 let fileSystemTestDouble: FileSystemTestDouble;20 let testCoverage: TestCoverageTestDouble;21 beforeEach(() => {22 reporterMock = factory.reporter();23 sandboxMock = sinon.createStubInstance(Sandbox);24 sandboxMock.sandboxFileFor.returns('sandbox/foo.js');25 fileSystemTestDouble = new FileSystemTestDouble();26 testCoverage = new TestCoverageTestDouble();27 });28 function act(29 mutants: Mutant[],30 project = new Project(fileSystemTestDouble, fileSystemTestDouble.toFileDescriptions())31 ): Promise<readonly MutantTestPlan[]> {32 return testInjector.injector33 .provideValue(coreTokens.testCoverage, testCoverage)34 .provideValue(coreTokens.reporter, reporterMock)35 .provideValue(coreTokens.mutants, mutants)36 .provideValue(coreTokens.sandbox, sandboxMock)37 .provideValue(coreTokens.project, project)38 .provideValue(coreTokens.timeOverheadMS, TIME_OVERHEAD_MS)39 .provideClass(coreTokens.incrementalDiffer, IncrementalDiffer) // inject the real deal40 .injectClass(MutantTestPlanner)41 .makePlan(mutants);42 }43 it('should make an early result plan for an ignored mutant', async () => {44 const mutant = factory.mutant({ id: '2', status: MutantStatus.Ignored, statusReason: 'foo should ignore' });45 // Act46 const result = await act([mutant]);47 // Assert48 const expected: MutantEarlyResultPlan[] = [49 { plan: PlanKind.EarlyResult, mutant: { ...mutant, static: false, status: MutantStatus.Ignored, coveredBy: undefined, killedBy: undefined } },50 ];51 expect(result).deep.eq(expected);52 });53 it('should make a plan with an empty test filter for a mutant without coverage', async () => {54 // Arrange55 const mutant = factory.mutant({ id: '3' });56 testCoverage.addTest(factory.testResult({ id: 'spec2' }));57 testCoverage.addCoverage(1, ['spec2']);58 // Act59 const [result] = await act([mutant]);60 // Assert61 assertIsRunPlan(result);62 expect(result.mutant.coveredBy).lengthOf(0);63 expect(result.runOptions.testFilter).lengthOf(0);64 expect(result.mutant.static).false;65 });66 it('should provide the sandboxFileName', async () => {67 // Arrange68 const mutant = factory.mutant({ id: '3', fileName: 'file.js' });69 // Act70 const [result] = await act([mutant]);71 // Assert72 assertIsRunPlan(result);73 expect(result.runOptions.sandboxFileName).eq('sandbox/foo.js');74 expect(sandboxMock.sandboxFileFor).calledWith('file.js');75 });76 it('should pass disableBail in the runOptions', async () => {77 const mutant = factory.mutant({ id: '3', fileName: 'file.js' });78 testInjector.options.disableBail = true;79 // Act80 const [result] = await act([mutant]);81 // Assert82 assertIsRunPlan(result);83 expect(result.runOptions.disableBail).true;84 });85 it('should report onMutationTestingPlanReady', async () => {86 // Arrange87 const mutants = [88 factory.mutant({89 id: '1',90 fileName: 'foo.js',91 mutatorName: 'fooMutator',92 replacement: '<=',93 location: { start: { line: 0, column: 0 }, end: { line: 0, column: 1 } },94 }),95 factory.mutant({96 id: '2',97 fileName: 'bar.js',98 mutatorName: 'barMutator',99 replacement: '{}',100 location: { start: { line: 0, column: 2 }, end: { line: 0, column: 3 } },101 }),102 ];103 testCoverage.addTest(factory.successTestResult({ timeSpentMs: 20 }));104 testCoverage.addTest(factory.successTestResult({ timeSpentMs: 22 }));105 // Act106 const mutantPlans = await act(mutants);107 // Assert108 sinon.assert.calledOnceWithExactly(reporterMock.onMutationTestingPlanReady, { mutantPlans });109 });110 describe('coverage', () => {111 describe('without mutant coverage data', () => {112 it('should disable the test filter', async () => {113 // Arrange114 const mutant1 = factory.mutant({ id: '1' });115 const mutant2 = factory.mutant({ id: '2' });116 const mutants = [mutant1, mutant2];117 // Act118 const [plan1, plan2] = await act(mutants);119 // Assert120 assertIsRunPlan(plan1);121 assertIsRunPlan(plan2);122 expect(plan1.runOptions.testFilter).undefined;123 expect(plan1.mutant.coveredBy).undefined;124 expect(plan1.mutant.static).undefined;125 expect(plan2.runOptions.testFilter).undefined;126 expect(plan2.mutant.coveredBy).undefined;127 expect(plan2.mutant.static).undefined;128 });129 it('should disable the hitLimit', async () => {130 // Arrange131 const mutants = [factory.mutant({ id: '1' })];132 // Act133 const [result] = await act(mutants);134 // Assert135 assertIsRunPlan(result);136 expect(result.runOptions.hitLimit).undefined;137 });138 it('should calculate timeout and net time using the sum of all tests', async () => {139 // Arrange140 const mutant1 = factory.mutant({ id: '1' });141 const mutants = [mutant1];142 testCoverage.addTest(factory.successTestResult({ id: 'spec1', timeSpentMs: 20 }));143 testCoverage.addTest(factory.successTestResult({ id: 'spec2', timeSpentMs: 22 }));144 // Act145 const [result] = await act(mutants);146 // Assert147 assertIsRunPlan(result);148 expect(result.runOptions.timeout).eq(calculateTimeout(42));149 expect(result.netTime).eq(42);150 });151 });152 describe('with static coverage', () => {153 it('should ignore when ignoreStatic is enabled', async () => {154 // Arrange155 testInjector.options.ignoreStatic = true;156 const mutant = factory.mutant({ id: '1' });157 const mutants = [mutant];158 testCoverage.staticCoverage['1'] = true;159 testCoverage.addTest(factory.successTestResult({ id: 'spec1', timeSpentMs: 0 }));160 testCoverage.hasCoverage = true;161 // Act162 const result = await act(mutants);163 // Assert164 const expected: MutantTestPlan[] = [165 {166 plan: PlanKind.EarlyResult,167 mutant: {168 ...mutant,169 status: MutantStatus.Ignored,170 statusReason: 'Static mutant (and "ignoreStatic" was enabled)',171 static: true,172 coveredBy: [],173 killedBy: undefined,174 },175 },176 ];177 expect(result).deep.eq(expected);178 });179 it('should disable test filtering, set reload environment and activate mutant statically when ignoreStatic is disabled', async () => {180 // Arrange181 testInjector.options.ignoreStatic = false;182 const mutants = [factory.mutant({ id: '1' })];183 testCoverage.staticCoverage['1'] = true;184 testCoverage.addTest(factory.successTestResult({ id: 'spec1', timeSpentMs: 0 }));185 testCoverage.hasCoverage = true;186 // Act187 const [result] = await act(mutants);188 // Assert189 assertIsRunPlan(result);190 expect(result.mutant.coveredBy).lengthOf(0);191 expect(result.mutant.static).true;192 expect(result.runOptions.reloadEnvironment).true;193 expect(result.runOptions.testFilter).undefined;194 expect(result.runOptions.mutantActivation).eq('static');195 });196 it('should set activeMutant on the runOptions', async () => {197 // Arrange198 const mutants = [Object.freeze(factory.mutant({ id: '1' }))];199 testCoverage.addTest(factory.successTestResult({ id: 'spec1', timeSpentMs: 0 }));200 // Act201 const [result] = await act(mutants);202 // Assert203 assertIsRunPlan(result);204 expect(result.runOptions.activeMutant).deep.eq(mutants[0]);205 });206 it('should calculate the hitLimit based on total hits (perTest and static)', async () => {207 // Arrange208 const mutant = factory.mutant({ id: '1' });209 const mutants = [mutant];210 testCoverage.hitsByMutantId.set('1', 6);211 // Act212 const [result] = await act(mutants);213 // Assert214 assertIsRunPlan(result);215 expect(result.runOptions.hitLimit).deep.eq(600);216 });217 it('should calculate timeout and net time using the sum of all tests', async () => {218 // Arrange219 const mutant = factory.mutant({ id: '1' });220 const mutants = [mutant];221 testCoverage.addTest(factory.successTestResult({ id: 'spec1', timeSpentMs: 20 }));222 testCoverage.addTest(factory.successTestResult({ id: 'spec2', timeSpentMs: 22 }));223 // Act224 const [result] = await act(mutants);225 // Assert226 assertIsRunPlan(result);227 expect(result.runOptions.timeout).eq(calculateTimeout(42));228 expect(result.netTime).eq(42);229 });230 });231 describe('with hybrid coverage', () => {232 it('should set the testFilter, coveredBy, static and runtime mutant activation when ignoreStatic is enabled', async () => {233 // Arrange234 testInjector.options.ignoreStatic = true;235 const mutants = [factory.mutant({ id: '1' })];236 testCoverage.addTest(factory.successTestResult({ id: 'spec1', timeSpentMs: 10 }));237 testCoverage.addCoverage('1', ['spec1']);238 testCoverage.staticCoverage['1'] = true;239 // Act240 const [result] = await act(mutants);241 // Assert242 assertIsRunPlan(result);243 const { mutant, runOptions } = result;244 expect(mutant.coveredBy).deep.eq(['spec1']);245 expect(mutant.static).deep.eq(true);246 expect(runOptions.testFilter).deep.eq(['spec1']);247 expect(result.runOptions.mutantActivation).eq('runtime');248 });249 it('should disable test filtering and statically activate the mutant, yet still set coveredBy and static when ignoreStatic is false', async () => {250 // Arrange251 testInjector.options.ignoreStatic = false;252 const mutants = [factory.mutant({ id: '1' })];253 testCoverage.addTest(factory.successTestResult({ id: 'spec1', timeSpentMs: 10 }));254 testCoverage.addTest(factory.successTestResult({ id: 'spec2', timeSpentMs: 20 }));255 testCoverage.staticCoverage['1'] = true;256 testCoverage.addCoverage('1', ['spec1']);257 // Act258 const [result] = await act(mutants);259 // Assert260 assertIsRunPlan(result);261 const { mutant, runOptions } = result;262 expect(mutant.coveredBy).deep.eq(['spec1']);263 expect(mutant.static).deep.eq(true);264 expect(runOptions.testFilter).deep.eq(undefined);265 expect(result.runOptions.mutantActivation).eq('static');266 });267 });268 describe('with perTest coverage', () => {269 it('should enable test filtering with runtime mutant activation for covered tests', async () => {270 // Arrange271 const mutants = [factory.mutant({ id: '1' }), factory.mutant({ id: '2' })];272 testCoverage.addTest(factory.successTestResult({ id: 'spec1', timeSpentMs: 0 }), factory.successTestResult({ id: 'spec2', timeSpentMs: 0 }));273 testCoverage.addCoverage('1', ['spec1']);274 testCoverage.addCoverage('2', ['spec2']);275 testCoverage.staticCoverage['1'] = false;276 // Act277 const [plan1, plan2] = await act(mutants);278 // Assert279 assertIsRunPlan(plan1);280 assertIsRunPlan(plan2);281 const { runOptions: runOptions1, mutant: mutant1 } = plan1;282 const { runOptions: runOptions2, mutant: mutant2 } = plan2;283 expect(runOptions1.testFilter).deep.eq(['spec1']);284 expect(runOptions1.mutantActivation).eq('runtime');285 expect(mutant1.coveredBy).deep.eq(['spec1']);286 expect(mutant1.static).false;287 expect(runOptions2.testFilter).deep.eq(['spec2']);288 expect(runOptions2.mutantActivation).eq('runtime');289 expect(mutant2.coveredBy).deep.eq(['spec2']);290 expect(mutant2.static).false;291 });292 it('should calculate timeout and net time using the sum of covered tests', async () => {293 // Arrange294 const mutants = [factory.mutant({ id: '1' }), factory.mutant({ id: '2' })];295 testCoverage.addTest(296 factory.successTestResult({ id: 'spec1', timeSpentMs: 20 }),297 factory.successTestResult({ id: 'spec2', timeSpentMs: 10 }),298 factory.successTestResult({ id: 'spec3', timeSpentMs: 22 })299 );300 testCoverage.staticCoverage['1'] = false;301 testCoverage.addCoverage('1', ['spec1', 'spec3']);302 testCoverage.addCoverage('2', ['spec2']);303 // Act304 const [plan1, plan2] = await act(mutants);305 // Assert306 assertIsRunPlan(plan1);307 assertIsRunPlan(plan2);308 expect(plan1.netTime).eq(42); // spec1 + spec3309 expect(plan2.netTime).eq(10); // spec2310 expect(plan1.runOptions.timeout).eq(calculateTimeout(42)); // spec1 + spec3311 expect(plan2.runOptions.timeout).eq(calculateTimeout(10)); // spec2312 });313 });314 });315 describe('static mutants warning', () => {316 function arrangeStaticWarning() {317 const mutants = [318 factory.mutant({ id: '1' }),319 factory.mutant({ id: '2' }),320 factory.mutant({ id: '3' }),321 factory.mutant({ id: '4' }), // static322 factory.mutant({ id: '8' }),323 factory.mutant({ id: '9' }),324 factory.mutant({ id: '10' }),325 ];326 testCoverage.addTest(327 factory.successTestResult({ id: 'spec1', timeSpentMs: 10 }),328 factory.successTestResult({ id: 'spec2', timeSpentMs: 10 }),329 factory.successTestResult({ id: 'spec3', timeSpentMs: 10 }),330 factory.successTestResult({ id: 'spec4', timeSpentMs: 10 })331 );332 arrangeStaticCoverage(4, 5, 6, 7);333 testCoverage.addCoverage(1, ['spec1']);334 testCoverage.addCoverage(2, ['spec2']);335 testCoverage.addCoverage(3, ['spec3']);336 testCoverage.addCoverage(8, ['spec3']);337 testCoverage.addCoverage(9, ['spec3']);338 testCoverage.addCoverage(10, ['spec2']);339 return { mutants };340 }341 it('should warn when the estimated time to run all static mutants exceeds 40% and the performance impact of a static mutant is estimated to be twice that of other mutants', async () => {342 // Arrange343 testInjector.options.ignoreStatic = false;344 const { mutants } = arrangeStaticWarning();345 // Act346 await act(mutants);347 // Assert348 expect(testInjector.logger.warn)349 .calledWithMatch('Detected 1 static mutants (14% of total) that are estimated to take 40% of the time running the tests!')350 .and.calledWithMatch('(disable "warnings.slow" to ignore this warning)');351 });352 it('should warn when 100% of the mutants are static', async () => {353 // Arrange354 testInjector.options.ignoreStatic = false;355 const mutants = [factory.mutant({ id: '1' }), factory.mutant({ id: '2' })];356 testCoverage.addTest(factory.successTestResult({ id: 'spec1', timeSpentMs: 10 }));357 testCoverage.hasCoverage = true;358 arrangeStaticCoverage(1, 2);359 // Act360 await act(mutants);361 // Assert362 expect(testInjector.logger.warn).calledWithMatch(363 'Detected 2 static mutants (100% of total) that are estimated to take 100% of the time running the tests!'364 );365 });366 it('should not warn when ignore static is enabled', async () => {367 // Arrange368 testInjector.options.ignoreStatic = true;369 const { mutants } = arrangeStaticWarning();370 // Act371 await act(mutants);372 // Assert373 expect(testInjector.logger.warn).not.called;374 });375 it('should not warn when "warning.slow" is disabled', async () => {376 // Arrange377 testInjector.options.ignoreStatic = false;378 testInjector.options.warnings = factory.warningOptions({ slow: false });379 const { mutants } = arrangeStaticWarning();380 // Act381 await act(mutants);382 // Assert383 expect(testInjector.logger.warn).not.called;384 });385 it('should not warn when all static mutants is not estimated to exceed 40%', async () => {386 // Arrange387 const mutants = [388 factory.mutant({ id: '1' }),389 factory.mutant({ id: '2' }),390 factory.mutant({ id: '3' }),391 factory.mutant({ id: '4' }), // static392 factory.mutant({ id: '8' }),393 factory.mutant({ id: '9' }),394 factory.mutant({ id: '10' }),395 ];396 testCoverage.addTest(397 factory.successTestResult({ id: 'spec1', timeSpentMs: 10 }),398 factory.successTestResult({ id: 'spec2', timeSpentMs: 10 }),399 factory.successTestResult({ id: 'spec3', timeSpentMs: 10 }),400 factory.successTestResult({ id: 'spec4', timeSpentMs: 9 })401 );402 arrangeStaticCoverage(4, 5, 6, 7);403 testCoverage.addCoverage(1, ['spec1']);404 testCoverage.addCoverage(2, ['spec2']);405 testCoverage.addCoverage(10, ['spec2']);406 testCoverage.addCoverage(3, ['spec3']);407 testCoverage.addCoverage(8, ['spec3']);408 testCoverage.addCoverage(9, ['spec3']);409 // Act410 await act(mutants);411 // Assert412 expect(testInjector.logger.warn).not.called;413 });414 it('should not warn when the performance impact of a static mutant is not estimated to be twice that of other mutants', async () => {415 // Arrange416 const mutants = [417 factory.mutant({ id: '1' }),418 factory.mutant({ id: '2' }),419 factory.mutant({ id: '3' }),420 factory.mutant({ id: '4' }), // static421 factory.mutant({ id: '5' }), // static422 factory.mutant({ id: '6' }), // static423 ];424 testCoverage.addTest(425 factory.successTestResult({ id: 'spec1', timeSpentMs: 1 }),426 factory.successTestResult({ id: 'spec2', timeSpentMs: 3 }),427 factory.successTestResult({ id: 'spec3', timeSpentMs: 0.1 }),428 factory.successTestResult({ id: 'spec4', timeSpentMs: 7 })429 );430 arrangeStaticCoverage(4, 5, 6);431 testCoverage.addCoverage(1, ['spec2', 'spec1']);432 testCoverage.addCoverage(2, ['spec2', 'spec4']);433 testCoverage.addCoverage(3, ['spec2']);434 testCoverage.addCoverage(3, ['spec3']);435 testCoverage.addCoverage(8, ['spec3']);436 testCoverage.addCoverage(9, ['spec3']);437 // static = 11.1438 // runtime = 5.6*2=11.3;439 // Act440 await act(mutants);441 // Assert442 expect(testInjector.logger.warn).not.called;443 });444 });445 describe('incremental', () => {446 class ScenarioBuilder {447 #mutants: Mutant[] = [];448 #srcFileName = 'foo.js';449 #testFileName = 'foo.spec.js';450 #incrementalReport: schema.MutationTestResult | undefined = undefined;451 public withWindowsPathSeparator() {452 // Deliberately not replacing all slashes, otherwise `path.relative` won't work on linux.453 this.#srcFileName = 'src\\foo.js';454 this.#testFileName = 'src\\foo.spec.js';455 return this;456 }457 public withIncrementalKilledMutant() {458 const testFileFullName = path.resolve(this.#testFileName);459 const srcFileFullName = path.resolve(this.#srcFileName);460 this.#mutants.push(461 factory.mutant({ id: '1', fileName: srcFileFullName, mutatorName: 'fooMutator', replacement: '<=', location: loc(0, 0, 0, 1) })462 );463 fileSystemTestDouble.files[srcFileFullName] = 'foo';464 fileSystemTestDouble.files[testFileFullName] = 'describe("foo")';465 this.#incrementalReport = factory.mutationTestReportSchemaMutationTestResult({466 files: {467 [this.#srcFileName.replace(/\\/g, '/')]: factory.mutationTestReportSchemaFileResult({468 source: 'foo',469 mutants: [470 factory.mutantResult({471 status: MutantStatus.Killed,472 replacement: '<=',473 mutatorName: 'fooMutator',474 location: loc(0, 0, 0, 1),475 killedBy: ['1'],476 coveredBy: ['1'],477 }),478 ],479 }),480 },481 testFiles: {482 [this.#testFileName.replace(/\\/g, '/')]: factory.mutationTestReportSchemaTestFile({483 source: 'describe("foo")',484 tests: [factory.mutationTestReportSchemaTestDefinition({ id: '1', name: 'foo should bar' })],485 }),486 },487 });488 testCoverage.addTest(factory.testResult({ fileName: testFileFullName, id: 'spec1', name: 'foo should bar' }));489 testCoverage.addCoverage(1, ['spec1']);490 return this;491 }492 public build() {493 const project = new Project(fileSystemTestDouble, fileSystemTestDouble.toFileDescriptions(), this.#incrementalReport);494 return { mutants: this.#mutants, project };495 }496 }497 // Actual diffing algorithm is tested in the 'incremental-differ' unit tests498 // These are just the unit tests for testing the integration between the planner and the differ499 it("should plan an early result for mutants that didn't change", async () => {500 // Arrange501 const { mutants, project } = new ScenarioBuilder().withIncrementalKilledMutant().build();502 // Act503 const [actualPlan] = await act(mutants, project);504 // Assert505 assertIsEarlyResultPlan(actualPlan);506 expect(actualPlan.mutant.status).eq(MutantStatus.Killed);507 expect(actualPlan.mutant.killedBy).deep.eq(['spec1']);508 });509 it('should normalize file names before passing them to the differ', async () => {510 // Arrange511 const { mutants, project } = new ScenarioBuilder().withWindowsPathSeparator().withIncrementalKilledMutant().build();512 // Act513 const [actualPlan] = await act(mutants, project);514 // Assert515 assertIsEarlyResultPlan(actualPlan);516 expect(actualPlan.mutant.status).eq(MutantStatus.Killed);517 expect(actualPlan.mutant.killedBy).deep.eq(['spec1']);518 });519 });520 function arrangeStaticCoverage(...mutantIds: Array<number | string>) {521 for (const mutantId of mutantIds) {522 testCoverage.staticCoverage[mutantId] = true;523 }524 }525});526function assertIsRunPlan(plan: MutantTestPlan): asserts plan is MutantRunPlan {527 expect(plan.plan).eq(PlanKind.Run);528}529function assertIsEarlyResultPlan(plan: MutantTestPlan): asserts plan is MutantEarlyResultPlan {530 expect(plan.plan).eq(PlanKind.EarlyResult);531}532function calculateTimeout(netTime: number): number {533 return testInjector.options.timeoutMS + testInjector.options.timeoutFactor * netTime + TIME_OVERHEAD_MS;...

Full Screen

Full Screen

crawl.js

Source:crawl.js Github

copy

Full Screen

1import fs from "fs"2import puppeteer from "puppeteer"3import { exec } from "child_process"4if (!fs.existsSync("./screenshots")) {5 fs.mkdirSync("./screenshots")6}7if (!fs.existsSync("./questions")) {8 fs.mkdirSync("./questions")9}10async function sh(cmd) {11 return new Promise(function (resolve, reject) {12 exec(cmd, (err, stdout, stderr) => {13 if (err) {14 reject(err)15 } else {16 resolve({ stdout, stderr })17 }18 })19 })20}21;(async () => {22 var questionNumber = process.argv.slice(2)23 try {24 if (questionNumber.length === 0) {25 throw "Please enter a question number"26 }27 } catch (e) {28 console.log(e)29 return30 }31 const browser = await puppeteer.launch()32 const page = await browser.newPage()33 await page.goto("https://leetcode.com/problemset/all/")34 await page.type("input[placeholder='Search questions']", questionNumber)35 await page.waitForTimeout(2000)36 var questionTitle = await page.evaluate(() => {37 return document.querySelectorAll('a[href^="/problems/"]')[3].innerText38 })39 var questionName = questionTitle.split(questionNumber + ". ")[1]40 var dashQuestionName = questionName41 .split(" ")42 .reduce((name, c) => name.concat("-" + c.toLowerCase()), "")43 .slice(1)44 .replace(/(\(|\)|,)/g, "")45 console.log(`Crawling question: ${questionNumber}. ${questionName}`)46 await page.goto(`https://leetcode.com/problems/${dashQuestionName}`, {47 waitUntil: "domcontentloaded",48 })49 console.log(`Going to: https://leetcode.com/problems/${dashQuestionName}`)50 await page.waitForTimeout(5000)51 var diffculty = await page.evaluate(() => {52 return document.querySelectorAll("div[diff]")[0].innerText53 })54 console.log(`Diffculty: ${diffculty}`)55 var description = await page.evaluate(() => {56 return document.querySelector("div[class*='question-content']").firstChild57 .innerText58 })59 await page.waitForSelector(".ant-select-selection")60 await page.$eval(".ant-select-selection", (langDiv) => langDiv.click())61 await page.waitForSelector("li[data-cy='lang-select-JavaScript']")62 await page.$eval("li[data-cy='lang-select-JavaScript']", (li) => li.click())63 var questionTestCases = await page.evaluate(() => {64 var RE = /(?<=<\/strong>)(.*?)(?=\n)/g65 return [66 [67 document.querySelectorAll("pre")[0].innerHTML.match(RE)[0],68 document69 .querySelectorAll("pre")[0]70 .innerHTML.split("Output:</strong>")[1]71 .split("<strong>")[0],72 ],73 [74 document.querySelectorAll("pre")[1].innerHTML.match(RE)[0],75 document76 .querySelectorAll("pre")[1]77 .innerHTML.split("Output:</strong>")[1]78 .split("<strong>")[0],79 ],80 ]81 })82 // await page.screenshot({ path: `screenshots/test.jpeg` })83 var questionTemplate = await page.evaluate(() => {84 // document.querySelector("li[data-cy='lang-select-JavaScript']").click()85 var RE = /(?!([0-9]\n))(.*)/g86 return document87 .querySelector("div.CodeMirror-code")88 .innerText.match(RE)89 .filter((c) => c.length !== 0)90 .join("\n")91 .replace(/function\(/, "function({")92 .replace(/\) \{/, "}) {")93 })94 var functionName = questionTemplate.match(/(?<=var ).*(?= \=)/g)95 await browser.close()96 console.log("Question Template:")97 console.log("\n")98 console.log(questionTemplate)99 console.log("\n")100 console.log("Test Case:")101 console.table([102 {103 Input: questionTestCases[0][0].trim(),104 Output: questionTestCases[0][1].replace("\n", "").trim(),105 },106 {107 Input: questionTestCases[1][0].trim(),108 Output: questionTestCases[1][1].replace("\n", "").trim(),109 },110 ])111 console.log("\n")112 var testCaseTemplates = []113 for (let i = 0; i < 2; i++) {114 testCaseTemplates.push(115 `test('test case ${i.toString()} ', () => { 116 expect(${functionName}({${questionTestCases[i][0].replace(117 /(=)/g,118 ":"119 )} })).toEqual(${questionTestCases[i][1]} ) 120 })\n`121 )122 }123 var comment = `/*\n\nQuestion: ${questionTitle}\n\nDiffculty: ${diffculty}\n\n${description} \n*/`124 var fileName = `questions/q${questionNumber}`125 var fileFullName = fs.existsSync(fileName + ".js")126 ? fileName + "-temp.js"127 : fileName + ".js"128 var testFileFullName = fileName + ".test.js"129 var fileMainContent = `${comment}\n\n${questionTemplate}\n\nexport {${functionName}}\n\n`130 var fileTestContent = `import {${functionName}} from "./${131 fileFullName.split("/")[1]132 }"\n\n${testCaseTemplates.join("\n")}`133 fs.writeFile(fileFullName, fileMainContent, (err) => {134 if (err) throw err135 })136 fs.writeFile(testFileFullName, fileTestContent, (err) => {137 if (err) throw err138 })139 var createFileMessage = fs.existsSync(fileName + ".js")140 ? `File of question ${questionNumber} existed. Create a temp file instead.`141 : `File of question ${questionNumber} is created successfully.\n`142 console.log(createFileMessage)143 await sh(`npx prettier --write ./${fileFullName}`)144 console.log(`Prettier: ${fileFullName}`)145 await sh(`npx prettier --write ./${testFileFullName}`)146 console.log(`Prettier: ${testFileFullName}`)147 console.log("Done.")148 return...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var strykerParent = require('stryker-parent');2console.log(strykerParent.testFileFullName('test.js'));3var strykerParent = require('stryker-parent');4console.log(strykerParent.testFileFullName('src/stryker-parent.js'));5var strykerParent = require('stryker-parent');6console.log(strykerParent.testFileFullName('index.js'));7var strykerParent = require('stryker-parent');8console.log(strykerParent.testFileFullName('index.js'));9var strykerParent = require('stryker-parent');10console.log(strykerParent.testFileFullName('index.js'));

Full Screen

Using AI Code Generation

copy

Full Screen

1const testFileFullName = require('stryker-parent').testFileFullName;2const testFileFullName = require('stryker-parent').testFileFullName;3const testFileFullName = require('stryker-parent').testFileFullName;4const testFileFullName = require('stryker-parent').testFileFullName;5const testFileFullName = require('stryker-parent').testFileFullName;6const testFileFullName = require('stryker-parent').testFileFullName;7const testFileFullName = require('stryker-parent').testFileFullName;8const testFileFullName = require('stryker-parent').testFileFullName;9const testFileFullName = require('stryker-parent').testFileFullName;10const testFileFullName = require('stryker-parent').testFileFullName;

Full Screen

Using AI Code Generation

copy

Full Screen

1var strykerParent = require('stryker-parent');2var testFileFullName = strykerParent.testFileFullName;3var fullName = testFileFullName('test.js');4console.log(fullName);5var strykerParent = require('stryker-parent');6var testFileFullName = strykerParent.testFileFullName;7var fullName = testFileFullName('test.js');8console.log(fullName);9var strykerParent = require('stryker-parent');10var testFileFullName = strykerParent.testFileFullName;11var fullName = testFileFullName('test.js');12console.log(fullName);13var strykerParent = require('stryker-parent');14var testFileFullName = strykerParent.testFileFullName;15var fullName = testFileFullName('test.js');16console.log(fullName);17var strykerParent = require('stryker-parent');18var testFileFullName = strykerParent.testFileFullName;19var fullName = testFileFullName('test.js');20console.log(fullName);21var strykerParent = require('stryker-parent');

Full Screen

Using AI Code Generation

copy

Full Screen

1var strykerParent = require('stryker-parent');2var testFileFullName = strykerParent.testFileFullName;3var strykerParent = require('stryker-parent');4var testFileFullName = strykerParent.testFileFullName;5var strykerParent = require('stryker-parent');6var testFileFullName = strykerParent.testFileFullName;7var strykerParent = require('stryker-parent');8var testFileFullName = strykerParent.testFileFullName;9var strykerParent = require('stryker-parent');

Full Screen

Using AI Code Generation

copy

Full Screen

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

Full Screen

Using AI Code Generation

copy

Full Screen

1var strykerParent = require('stryker-parent');2var path = require('path');3console.log(strykerParent.testFileFullName(path.join('src', 'foo.js')));4var strykerParent = require('stryker-parent');5var path = require('path');6console.log(strykerParent.testFileFullName(path.join('src', 'foo.js')));

Full Screen

Using AI Code Generation

copy

Full Screen

1testFileFullName = require('stryker-parent').testFileFullName;2console.log('test file full name: ' + testFileFullName('test.js'));3testFileFullName = require('stryker-parent').testFileFullName;4console.log('test file full name: ' + testFileFullName('test.js'));5testFileFullName = require('stryker-parent').testFileFullName;6console.log('test file full name: ' + testFileFullName('test.js'));7testFileFullName = require('stryker-parent').testFileFullName;8console.log('test file full name: ' + testFileFullName('test.js'));9testFileFullName = require('stryker-parent').testFileFullName;10console.log('test file full name: ' + testFileFullName('test.js'));11testFileFullName = require('stryker-parent').testFileFullName;12console.log('test file full name: ' + testFileFullName('test.js'));13testFileFullName = require('stryker-parent').testFileFullName;14console.log('test file full name: ' + testFileFullName('test.js'));

Full Screen

Using AI Code Generation

copy

Full Screen

1const { testFileFullName } = require('stryker-parent');2testFileFullName('test.js');3const { testFileFullName } = require('stryker-parent');4testFileFullName('src/index.js');5const { testFileFullName } = require('stryker-parent');6testFileFullName('src/index.js');7const { testFileFullName } = require('stryker-parent');8testFileFullName('src/index.js');9const { testFileFullName } = require('stryker-parent');10testFileFullName('src/index.js');11const { testFileFullName } = require('stryker-parent');12testFileFullName('src/index.js');13const { testFileFullName } = require('stryker-parent');14testFileFullName('src/index.js');15const { testFileFullName } = require('stryker-parent');16testFileFullName('src/index.js');17const { testFileFullName } = require('stryker-parent');18testFileFullName('src/index.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