Best JavaScript code snippet using stryker-parent
textChanges.ts
Source:textChanges.ts
1// Some tests have trailing whitespace2// tslint:disable trim-trailing-whitespace34namespace ts {5 describe("unittests:: services:: textChanges", () => {6 function findChild(name: string, n: Node) {7 return find(n)!;89 function find(node: Node): Node | undefined {10 if (isDeclaration(node) && node.name && isIdentifier(node.name) && node.name.escapedText === name) {11 return node;12 }13 else {14 return forEachChild(node, find);15 }16 }17 }1819 const printerOptions = { newLine: NewLineKind.LineFeed };20 const newLineCharacter = getNewLineCharacter(printerOptions);2122 function getRuleProvider(placeOpenBraceOnNewLineForFunctions: boolean): formatting.FormatContext {23 return formatting.getFormatContext(placeOpenBraceOnNewLineForFunctions ? { ...testFormatSettings, placeOpenBraceOnNewLineForFunctions: true } : testFormatSettings);24 }2526 // validate that positions that were recovered from the printed text actually match positions that will be created if the same text is parsed.27 function verifyPositions(node: Node, text: string): void {28 const nodeList = flattenNodes(node);29 const sourceFile = createSourceFile("f.ts", text, ScriptTarget.ES2015);30 const parsedNodeList = flattenNodes(sourceFile.statements[0]);31 zipWith(nodeList, parsedNodeList, (left, right) => {32 Debug.assert(left.pos === right.pos);33 Debug.assert(left.end === right.end);34 });3536 function flattenNodes(n: Node) {37 const data: (Node | NodeArray<Node>)[] = [];38 walk(n);39 return data;4041 function walk(n: Node | NodeArray<Node>): void {42 data.push(n);43 return isArray(n) ? forEach(n, walk) : forEachChild(n, walk, walk);44 }45 }46 }4748 function runSingleFileTest(caption: string, placeOpenBraceOnNewLineForFunctions: boolean, text: string, validateNodes: boolean, testBlock: (sourceFile: SourceFile, changeTracker: textChanges.ChangeTracker) => void) {49 it(caption, () => {50 const sourceFile = createSourceFile("source.ts", text, ScriptTarget.ES2015, /*setParentNodes*/ true);51 const rulesProvider = getRuleProvider(placeOpenBraceOnNewLineForFunctions);52 const changeTracker = new textChanges.ChangeTracker(newLineCharacter, rulesProvider);53 testBlock(sourceFile, changeTracker);54 const changes = changeTracker.getChanges(validateNodes ? verifyPositions : undefined);55 assert.equal(changes.length, 1);56 assert.equal(changes[0].fileName, sourceFile.fileName);57 const modified = textChanges.applyChanges(sourceFile.text, changes[0].textChanges);58 Harness.Baseline.runBaseline(`textChanges/${caption}.js`, `===ORIGINAL===${newLineCharacter}${text}${newLineCharacter}===MODIFIED===${newLineCharacter}${modified}`);59 });60 }6162 {63 const text = `64namespace M65{66 namespace M267 {68 function foo() {69 // comment 170 const x = 1;7172 /**73 * comment 2 line 174 * comment 2 line 275 */76 function f() {77 return 100;78 }79 const y = 2; // comment 380 return 1;81 }82 }83}`;84 runSingleFileTest("extractMethodLike", /*placeOpenBraceOnNewLineForFunctions*/ true, text, /*validateNodes*/ true, (sourceFile, changeTracker) => {85 const statements = (<FunctionDeclaration>findChild("foo", sourceFile)).body!.statements.slice(1);86 const newFunction = createFunctionDeclaration(87 /*decorators*/ undefined,88 /*modifiers*/ undefined,89 /*asteriskToken*/ undefined,90 /*name*/ "bar",91 /*typeParameters*/ undefined,92 /*parameters*/ emptyArray,93 /*type*/ createKeywordTypeNode(SyntaxKind.AnyKeyword),94 /*body */ createBlock(statements)95 );9697 changeTracker.insertNodeBefore(sourceFile, /*before*/findChild("M2", sourceFile), newFunction);9899 // replace statements with return statement100 const newStatement = createReturn(101 createCall(102 /*expression*/ newFunction.name!,103 /*typeArguments*/ undefined,104 /*argumentsArray*/ emptyArray105 ));106 changeTracker.replaceNodeRange(sourceFile, statements[0], last(statements), newStatement, { suffix: newLineCharacter });107 });108 }109 {110 const text = `111function foo() {112 return 1;113}114115function bar() {116 return 2;117}118`;119 runSingleFileTest("deleteRange1", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {120 changeTracker.deleteRange(sourceFile, { pos: text.indexOf("function foo"), end: text.indexOf("function bar") });121 });122 }123 function findVariableStatementContaining(name: string, sourceFile: SourceFile): VariableStatement {124 return cast(findVariableDeclarationContaining(name, sourceFile).parent.parent, isVariableStatement);125 }126 function findVariableDeclarationContaining(name: string, sourceFile: SourceFile): VariableDeclaration {127 return cast(findChild(name, sourceFile), isVariableDeclaration);128 }129 const { deleteNode } = textChanges;130 {131 const text = `132var x = 1; // some comment - 1133/**134 * comment 2135 */136var y = 2; // comment 3137var z = 3; // comment 4138`;139 runSingleFileTest("deleteNode1", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {140 deleteNode(changeTracker, sourceFile, findVariableStatementContaining("y", sourceFile));141 });142 runSingleFileTest("deleteNode2", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {143 deleteNode(changeTracker, sourceFile, findVariableStatementContaining("y", sourceFile), { useNonAdjustedStartPosition: true });144 });145 runSingleFileTest("deleteNode3", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {146 deleteNode(changeTracker, sourceFile, findVariableStatementContaining("y", sourceFile), { useNonAdjustedEndPosition: true });147 });148 runSingleFileTest("deleteNode4", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {149 deleteNode(changeTracker, sourceFile, findVariableStatementContaining("y", sourceFile), { useNonAdjustedStartPosition: true, useNonAdjustedEndPosition: true });150 });151 runSingleFileTest("deleteNode5", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {152 deleteNode(changeTracker, sourceFile, findVariableStatementContaining("x", sourceFile));153 });154 }155 {156 const text = `157// comment 1158var x = 1; // comment 2159// comment 3160var y = 2; // comment 4161var z = 3; // comment 5162// comment 6163var a = 4; // comment 7164`;165 runSingleFileTest("deleteNodeRange1", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {166 changeTracker.deleteNodeRange(sourceFile, findVariableStatementContaining("y", sourceFile), findVariableStatementContaining("z", sourceFile));167 });168 runSingleFileTest("deleteNodeRange2", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {169 changeTracker.deleteNodeRange(sourceFile, findVariableStatementContaining("y", sourceFile), findVariableStatementContaining("z", sourceFile),170 { useNonAdjustedStartPosition: true });171 });172 runSingleFileTest("deleteNodeRange3", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {173 changeTracker.deleteNodeRange(sourceFile, findVariableStatementContaining("y", sourceFile), findVariableStatementContaining("z", sourceFile),174 { useNonAdjustedEndPosition: true });175 });176 runSingleFileTest("deleteNodeRange4", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {177 changeTracker.deleteNodeRange(sourceFile, findVariableStatementContaining("y", sourceFile), findVariableStatementContaining("z", sourceFile),178 { useNonAdjustedStartPosition: true, useNonAdjustedEndPosition: true });179 });180 }181 function createTestVariableDeclaration(name: string) {182 return createVariableDeclaration(name, /*type*/ undefined, createObjectLiteral([createPropertyAssignment("p1", createLiteral(1))], /*multiline*/ true));183 }184 function createTestClass() {185 return createClassDeclaration(186 /*decorators*/ undefined,187 [188 createToken(SyntaxKind.PublicKeyword)189 ],190 "class1",191 /*typeParameters*/ undefined,192 [193 createHeritageClause(194 SyntaxKind.ImplementsKeyword,195 [196 createExpressionWithTypeArguments(/*typeArguments*/ undefined, createIdentifier("interface1"))197 ]198 )199 ],200 [201 createProperty(202 /*decorators*/ undefined,203 /*modifiers*/ undefined,204 "property1",205 /*questionToken*/ undefined,206 createKeywordTypeNode(SyntaxKind.BooleanKeyword),207 /*initializer*/ undefined208 )209 ]210 );211 }212 {213 const text = `214// comment 1215var x = 1; // comment 2216// comment 3217var y = 2; // comment 4218var z = 3; // comment 5219// comment 6220var a = 4; // comment 7`;221 runSingleFileTest("replaceRange", /*placeOpenBraceOnNewLineForFunctions*/ true, text, /*validateNodes*/ true, (sourceFile, changeTracker) => {222 changeTracker.replaceRange(sourceFile, { pos: text.indexOf("var y"), end: text.indexOf("var a") }, createTestClass(), { suffix: newLineCharacter });223 });224 runSingleFileTest("replaceRangeWithForcedIndentation", /*placeOpenBraceOnNewLineForFunctions*/ true, text, /*validateNodes*/ true, (sourceFile, changeTracker) => {225 changeTracker.replaceRange(sourceFile, { pos: text.indexOf("var y"), end: text.indexOf("var a") }, createTestClass(), { suffix: newLineCharacter, indentation: 8, delta: 0 });226 });227228 runSingleFileTest("replaceRangeNoLineBreakBefore", /*placeOpenBraceOnNewLineForFunctions*/ true, `const x = 1, y = "2";`, /*validateNodes*/ false, (sourceFile, changeTracker) => {229 const newNode = createTestVariableDeclaration("z1");230 changeTracker.replaceRange(sourceFile, { pos: sourceFile.text.indexOf("y"), end: sourceFile.text.indexOf(";") }, newNode);231 });232 }233 {234 const text = `235namespace A {236 const x = 1, y = "2";237}238`;239 runSingleFileTest("replaceNode1NoLineBreakBefore", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {240 const newNode = createTestVariableDeclaration("z1");241 changeTracker.replaceNode(sourceFile, findChild("y", sourceFile), newNode);242 });243 }244 {245 const text = `246// comment 1247var x = 1; // comment 2248// comment 3249var y = 2; // comment 4250var z = 3; // comment 5251// comment 6252var a = 4; // comment 7`;253 runSingleFileTest("replaceNode1", /*placeOpenBraceOnNewLineForFunctions*/ true, text, /*validateNodes*/ true, (sourceFile, changeTracker) => {254 changeTracker.replaceNode(sourceFile, findVariableStatementContaining("y", sourceFile), createTestClass(), { suffix: newLineCharacter });255 });256 runSingleFileTest("replaceNode2", /*placeOpenBraceOnNewLineForFunctions*/ true, text, /*validateNodes*/ true, (sourceFile, changeTracker) => {257 changeTracker.replaceNode(sourceFile, findVariableStatementContaining("y", sourceFile), createTestClass(), { useNonAdjustedStartPosition: true, suffix: newLineCharacter, prefix: newLineCharacter });258 });259 runSingleFileTest("replaceNode3", /*placeOpenBraceOnNewLineForFunctions*/ true, text, /*validateNodes*/ true, (sourceFile, changeTracker) => {260 changeTracker.replaceNode(sourceFile, findVariableStatementContaining("y", sourceFile), createTestClass(), { useNonAdjustedEndPosition: true, suffix: newLineCharacter });261 });262 runSingleFileTest("replaceNode4", /*placeOpenBraceOnNewLineForFunctions*/ true, text, /*validateNodes*/ true, (sourceFile, changeTracker) => {263 changeTracker.replaceNode(sourceFile, findVariableStatementContaining("y", sourceFile), createTestClass(), { useNonAdjustedStartPosition: true, useNonAdjustedEndPosition: true });264 });265 runSingleFileTest("replaceNode5", /*placeOpenBraceOnNewLineForFunctions*/ true, text, /*validateNodes*/ true, (sourceFile, changeTracker) => {266 changeTracker.replaceNode(sourceFile, findVariableStatementContaining("x", sourceFile), createTestClass(), { useNonAdjustedStartPosition: true, useNonAdjustedEndPosition: true });267 });268 }269 {270 const text = `271// comment 1272var x = 1; // comment 2273// comment 3274var y = 2; // comment 4275var z = 3; // comment 5276// comment 6277var a = 4; // comment 7`;278 runSingleFileTest("replaceNodeRange1", /*placeOpenBraceOnNewLineForFunctions*/ true, text, /*validateNodes*/ true, (sourceFile, changeTracker) => {279 changeTracker.replaceNodeRange(sourceFile, findVariableStatementContaining("y", sourceFile), findVariableStatementContaining("z", sourceFile), createTestClass(), { suffix: newLineCharacter });280 });281 runSingleFileTest("replaceNodeRange2", /*placeOpenBraceOnNewLineForFunctions*/ true, text, /*validateNodes*/ true, (sourceFile, changeTracker) => {282 changeTracker.replaceNodeRange(sourceFile, findVariableStatementContaining("y", sourceFile), findVariableStatementContaining("z", sourceFile), createTestClass(), { useNonAdjustedStartPosition: true, suffix: newLineCharacter, prefix: newLineCharacter });283 });284 runSingleFileTest("replaceNodeRange3", /*placeOpenBraceOnNewLineForFunctions*/ true, text, /*validateNodes*/ true, (sourceFile, changeTracker) => {285 changeTracker.replaceNodeRange(sourceFile, findVariableStatementContaining("y", sourceFile), findVariableStatementContaining("z", sourceFile), createTestClass(), { useNonAdjustedEndPosition: true, suffix: newLineCharacter });286 });287 runSingleFileTest("replaceNodeRange4", /*placeOpenBraceOnNewLineForFunctions*/ true, text, /*validateNodes*/ true, (sourceFile, changeTracker) => {288 changeTracker.replaceNodeRange(sourceFile, findVariableStatementContaining("y", sourceFile), findVariableStatementContaining("z", sourceFile), createTestClass(), { useNonAdjustedStartPosition: true, useNonAdjustedEndPosition: true });289 });290 }291 {292 const text = `293// comment 1294var x = 1; // comment 2295// comment 3296var y; // comment 4297var z = 3; // comment 5298// comment 6299var a = 4; // comment 7`;300 runSingleFileTest("insertNodeBefore3", /*placeOpenBraceOnNewLineForFunctions*/ true, text, /*validateNodes*/ true, (sourceFile, changeTracker) => {301 changeTracker.insertNodeBefore(sourceFile, findVariableStatementContaining("y", sourceFile), createTestClass());302 });303 runSingleFileTest("insertNodeAfterVariableDeclaration", /*placeOpenBraceOnNewLineForFunctions*/ true, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {304 changeTracker.insertNodeAfter(sourceFile, findVariableDeclarationContaining("y", sourceFile), createTestVariableDeclaration("z1"));305 });306 }307 {308 const text = `309namespace M {310 // comment 1311 var x = 1; // comment 2312 // comment 3313 var y; // comment 4314 var z = 3; // comment 5315 // comment 6316 var a = 4; // comment 7317}`;318 runSingleFileTest("insertNodeBefore1", /*placeOpenBraceOnNewLineForFunctions*/ true, text, /*validateNodes*/ true, (sourceFile, changeTracker) => {319 changeTracker.insertNodeBefore(sourceFile, findVariableStatementContaining("y", sourceFile), createTestClass());320 });321 runSingleFileTest("insertNodeBefore2", /*placeOpenBraceOnNewLineForFunctions*/ true, text, /*validateNodes*/ true, (sourceFile, changeTracker) => {322 changeTracker.insertNodeBefore(sourceFile, findChild("M", sourceFile), createTestClass());323 });324 runSingleFileTest("insertNodeAfter1", /*placeOpenBraceOnNewLineForFunctions*/ true, text, /*validateNodes*/ true, (sourceFile, changeTracker) => {325 changeTracker.insertNodeAfter(sourceFile, findVariableStatementContaining("y", sourceFile), createTestClass());326 });327 runSingleFileTest("insertNodeAfter2", /*placeOpenBraceOnNewLineForFunctions*/ true, text, /*validateNodes*/ true, (sourceFile, changeTracker) => {328 changeTracker.insertNodeAfter(sourceFile, findChild("M", sourceFile), createTestClass());329 });330 }331332 function findConstructor(sourceFile: SourceFile): ConstructorDeclaration {333 const classDecl = <ClassDeclaration>sourceFile.statements[0];334 return find<ClassElement, ConstructorDeclaration>(classDecl.members, (m): m is ConstructorDeclaration => isConstructorDeclaration(m) && !!m.body)!;335 }336 function createTestSuperCall() {337 const superCall = createCall(338 createSuper(),339 /*typeArguments*/ undefined,340 /*argumentsArray*/ emptyArray341 );342 return createStatement(superCall);343 }344345 {346 const text1 = `347class A {348 constructor() {349 }350}351`;352 runSingleFileTest("insertNodeAtConstructorStart", /*placeOpenBraceOnNewLineForFunctions*/ false, text1, /*validateNodes*/ false, (sourceFile, changeTracker) => {353 changeTracker.insertNodeAtConstructorStart(sourceFile, findConstructor(sourceFile), createTestSuperCall());354 });355 const text2 = `356class A {357 constructor() {358 var x = 1;359 }360}361`;362 runSingleFileTest("insertNodeAfter4", /*placeOpenBraceOnNewLineForFunctions*/ false, text2, /*validateNodes*/ false, (sourceFile, changeTracker) => {363 changeTracker.insertNodeAfter(sourceFile, findVariableStatementContaining("x", sourceFile), createTestSuperCall());364 });365 const text3 = `366class A {367 constructor() {368369 }370}371`;372 runSingleFileTest("insertNodeAtConstructorStart-block with newline", /*placeOpenBraceOnNewLineForFunctions*/ false, text3, /*validateNodes*/ false, (sourceFile, changeTracker) => {373 changeTracker.insertNodeAtConstructorStart(sourceFile, findConstructor(sourceFile), createTestSuperCall());374 });375 }376 {377 const text = `var a = 1, b = 2, c = 3;`;378 runSingleFileTest("deleteNodeInList1", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {379 changeTracker.delete(sourceFile, findChild("a", sourceFile));380 });381 runSingleFileTest("deleteNodeInList2", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {382 changeTracker.delete(sourceFile, findChild("b", sourceFile));383 });384 runSingleFileTest("deleteNodeInList3", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {385 changeTracker.delete(sourceFile, findChild("c", sourceFile));386 });387 }388 {389 const text = `var a = 1,b = 2,c = 3;`;390 runSingleFileTest("deleteNodeInList1_1", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {391 changeTracker.delete(sourceFile, findChild("a", sourceFile));392 });393 runSingleFileTest("deleteNodeInList2_1", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {394 changeTracker.delete(sourceFile, findChild("b", sourceFile));395 });396 runSingleFileTest("deleteNodeInList3_1", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {397 changeTracker.delete(sourceFile, findChild("c", sourceFile));398 });399 }400 {401 const text = `402namespace M {403 var a = 1,404 b = 2,405 c = 3;406}`;407 runSingleFileTest("deleteNodeInList4", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {408 changeTracker.delete(sourceFile, findChild("a", sourceFile));409 });410 runSingleFileTest("deleteNodeInList5", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {411 changeTracker.delete(sourceFile, findChild("b", sourceFile));412 });413 runSingleFileTest("deleteNodeInList6", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {414 changeTracker.delete(sourceFile, findChild("c", sourceFile));415 });416 }417 {418 const text = `419namespace M {420 var a = 1, // comment 1421 // comment 2422 b = 2, // comment 3423 // comment 4424 c = 3; // comment 5425}`;426 runSingleFileTest("deleteNodeInList4_1", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {427 changeTracker.delete(sourceFile, findChild("a", sourceFile));428 });429 runSingleFileTest("deleteNodeInList5_1", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {430 changeTracker.delete(sourceFile, findChild("b", sourceFile));431 });432 runSingleFileTest("deleteNodeInList6_1", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {433 changeTracker.delete(sourceFile, findChild("c", sourceFile));434 });435 }436 {437 const text = `438function foo(a: number, b: string, c = true) {439 return 1;440}`;441 runSingleFileTest("deleteNodeInList7", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {442 changeTracker.delete(sourceFile, findChild("a", sourceFile));443 });444 runSingleFileTest("deleteNodeInList8", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {445 changeTracker.delete(sourceFile, findChild("b", sourceFile));446 });447 runSingleFileTest("deleteNodeInList9", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {448 changeTracker.delete(sourceFile, findChild("c", sourceFile));449 });450 }451 {452 const text = `453function foo(a: number,b: string,c = true) {454 return 1;455}`;456 runSingleFileTest("deleteNodeInList10", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {457 changeTracker.delete(sourceFile, findChild("a", sourceFile));458 });459 runSingleFileTest("deleteNodeInList11", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {460 changeTracker.delete(sourceFile, findChild("b", sourceFile));461 });462 runSingleFileTest("deleteNodeInList12", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {463 changeTracker.delete(sourceFile, findChild("c", sourceFile));464 });465 }466 {467 const text = `468function foo(469 a: number,470 b: string,471 c = true) {472 return 1;473}`;474 runSingleFileTest("deleteNodeInList13", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {475 changeTracker.delete(sourceFile, findChild("a", sourceFile));476 });477 runSingleFileTest("deleteNodeInList14", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {478 changeTracker.delete(sourceFile, findChild("b", sourceFile));479 });480 runSingleFileTest("deleteNodeInList15", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {481 changeTracker.delete(sourceFile, findChild("c", sourceFile));482 });483 }484 {485 const text = `486const x = 1, y = 2;`;487 runSingleFileTest("insertNodeInListAfter1", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {488 changeTracker.insertNodeInListAfter(sourceFile, findChild("x", sourceFile), createVariableDeclaration("z", /*type*/ undefined, createLiteral(1)));489 });490 runSingleFileTest("insertNodeInListAfter2", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {491 changeTracker.insertNodeInListAfter(sourceFile, findChild("y", sourceFile), createVariableDeclaration("z", /*type*/ undefined, createLiteral(1)));492 });493 }494 {495 const text = `496const /*x*/ x = 1, /*y*/ y = 2;`;497 runSingleFileTest("insertNodeInListAfter3", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {498 changeTracker.insertNodeInListAfter(sourceFile, findChild("x", sourceFile), createVariableDeclaration("z", /*type*/ undefined, createLiteral(1)));499 });500 runSingleFileTest("insertNodeInListAfter4", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {501 changeTracker.insertNodeInListAfter(sourceFile, findChild("y", sourceFile), createVariableDeclaration("z", /*type*/ undefined, createLiteral(1)));502 });503 }504 {505 const text = `506const x = 1;`;507 runSingleFileTest("insertNodeInListAfter5", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {508 changeTracker.insertNodeInListAfter(sourceFile, findChild("x", sourceFile), createVariableDeclaration("z", /*type*/ undefined, createLiteral(1)));509 });510 }511 {512 const text = `513const x = 1,514 y = 2;`;515 runSingleFileTest("insertNodeInListAfter6", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {516 changeTracker.insertNodeInListAfter(sourceFile, findChild("x", sourceFile), createVariableDeclaration("z", /*type*/ undefined, createLiteral(1)));517 });518 runSingleFileTest("insertNodeInListAfter7", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {519 changeTracker.insertNodeInListAfter(sourceFile, findChild("y", sourceFile), createVariableDeclaration("z", /*type*/ undefined, createLiteral(1)));520 });521 }522 {523 const text = `524const /*x*/ x = 1,525 /*y*/ y = 2;`;526 runSingleFileTest("insertNodeInListAfter8", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {527 changeTracker.insertNodeInListAfter(sourceFile, findChild("x", sourceFile), createVariableDeclaration("z", /*type*/ undefined, createLiteral(1)));528 });529 runSingleFileTest("insertNodeInListAfter9", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {530 changeTracker.insertNodeInListAfter(sourceFile, findChild("y", sourceFile), createVariableDeclaration("z", /*type*/ undefined, createLiteral(1)));531 });532 }533 {534 const text = `535import {536 x537} from "bar"`;538 runSingleFileTest("insertNodeInListAfter10", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {539 changeTracker.insertNodeInListAfter(sourceFile, findChild("x", sourceFile), createImportSpecifier(createIdentifier("b"), createIdentifier("a")));540 });541 }542 {543 const text = `544import {545 x // this is x546} from "bar"`;547 runSingleFileTest("insertNodeInListAfter11", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {548 changeTracker.insertNodeInListAfter(sourceFile, findChild("x", sourceFile), createImportSpecifier(createIdentifier("b"), createIdentifier("a")));549 });550 }551 {552 const text = `553import {554 x555} from "bar"`;556 runSingleFileTest("insertNodeInListAfter12", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {557 changeTracker.insertNodeInListAfter(sourceFile, findChild("x", sourceFile), createImportSpecifier(undefined, createIdentifier("a")));558 });559 }560 {561 const text = `562import {563 x // this is x564} from "bar"`;565 runSingleFileTest("insertNodeInListAfter13", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {566 changeTracker.insertNodeInListAfter(sourceFile, findChild("x", sourceFile), createImportSpecifier(undefined, createIdentifier("a")));567 });568 }569 {570 const text = `571import {572 x0,573 x574} from "bar"`;575 runSingleFileTest("insertNodeInListAfter14", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {576 changeTracker.insertNodeInListAfter(sourceFile, findChild("x", sourceFile), createImportSpecifier(createIdentifier("b"), createIdentifier("a")));577 });578 }579 {580 const text = `581import {582 x0,583 x // this is x584} from "bar"`;585 runSingleFileTest("insertNodeInListAfter15", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {586 changeTracker.insertNodeInListAfter(sourceFile, findChild("x", sourceFile), createImportSpecifier(createIdentifier("b"), createIdentifier("a")));587 });588 }589 {590 const text = `591import {592 x0,593 x594} from "bar"`;595 runSingleFileTest("insertNodeInListAfter16", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {596 changeTracker.insertNodeInListAfter(sourceFile, findChild("x", sourceFile), createImportSpecifier(undefined, createIdentifier("a")));597 });598 }599 {600 const text = `601import {602 x0,603 x // this is x604} from "bar"`;605 runSingleFileTest("insertNodeInListAfter17", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {606 changeTracker.insertNodeInListAfter(sourceFile, findChild("x", sourceFile), createImportSpecifier(undefined, createIdentifier("a")));607 });608 }609 {610 const text = `611import {612 x0, x613} from "bar"`;614 runSingleFileTest("insertNodeInListAfter18", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {615 changeTracker.insertNodeInListAfter(sourceFile, findChild("x", sourceFile), createImportSpecifier(undefined, createIdentifier("a")));616 });617 }618 {619 const text = `620class A {621 x;622}`;623 runSingleFileTest("insertNodeAfterMultipleNodes", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {624 const newNodes = [];625 for (let i = 0; i < 11 /*error doesn't occur with fewer nodes*/; ++i) {626 newNodes.push(627 createProperty(undefined, undefined, i + "", undefined, undefined, undefined));628 }629 const insertAfter = findChild("x", sourceFile);630 for (const newNode of newNodes) {631 changeTracker.insertNodeAfter(sourceFile, insertAfter, newNode);632 }633 });634 }635 {636 const text = `637class A {638 x639}640`;641 runSingleFileTest("insertNodeAfterInClass1", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {642 changeTracker.insertNodeAfter(sourceFile, findChild("x", sourceFile), createProperty(undefined, undefined, "a", undefined, createKeywordTypeNode(SyntaxKind.BooleanKeyword), undefined));643 });644 }645 {646 const text = `647class A {648 x;649}650`;651 runSingleFileTest("insertNodeAfterInClass2", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {652 changeTracker.insertNodeAfter(sourceFile, findChild("x", sourceFile), createProperty(undefined, undefined, "a", undefined, createKeywordTypeNode(SyntaxKind.BooleanKeyword), undefined));653 });654 }655 {656 const text = `657class A {658 x;659 y = 1;660}661`;662 runSingleFileTest("deleteNodeAfterInClass1", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {663 deleteNode(changeTracker, sourceFile, findChild("x", sourceFile));664 });665 }666 {667 const text = `668class A {669 x670 y = 1;671}672`;673 runSingleFileTest("deleteNodeAfterInClass2", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {674 deleteNode(changeTracker, sourceFile, findChild("x", sourceFile));675 });676 }677 {678 const text = `679class A {680 x = foo681}682`;683 runSingleFileTest("insertNodeInClassAfterNodeWithoutSeparator1", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {684 const newNode = createProperty(685 /*decorators*/ undefined,686 /*modifiers*/ undefined,687 createComputedPropertyName(createLiteral(1)),688 /*questionToken*/ undefined,689 createKeywordTypeNode(SyntaxKind.AnyKeyword),690 /*initializer*/ undefined);691 changeTracker.insertNodeAfter(sourceFile, findChild("x", sourceFile), newNode);692 });693 }694 {695 const text = `696class A {697 x() {698 }699}700`;701 runSingleFileTest("insertNodeInClassAfterNodeWithoutSeparator2", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {702 const newNode = createProperty(703 /*decorators*/ undefined,704 /*modifiers*/ undefined,705 createComputedPropertyName(createLiteral(1)),706 /*questionToken*/ undefined,707 createKeywordTypeNode(SyntaxKind.AnyKeyword),708 /*initializer*/ undefined);709 changeTracker.insertNodeAfter(sourceFile, findChild("x", sourceFile), newNode);710 });711 }712 {713 const text = `714interface A {715 x716}717`;718 runSingleFileTest("insertNodeInInterfaceAfterNodeWithoutSeparator1", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {719 const newNode = createProperty(720 /*decorators*/ undefined,721 /*modifiers*/ undefined,722 createComputedPropertyName(createLiteral(1)),723 /*questionToken*/ undefined,724 createKeywordTypeNode(SyntaxKind.AnyKeyword),725 /*initializer*/ undefined);726 changeTracker.insertNodeAfter(sourceFile, findChild("x", sourceFile), newNode);727 });728 }729 {730 const text = `731interface A {732 x()733}734`;735 runSingleFileTest("insertNodeInInterfaceAfterNodeWithoutSeparator2", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {736 const newNode = createProperty(737 /*decorators*/ undefined,738 /*modifiers*/ undefined,739 createComputedPropertyName(createLiteral(1)),740 /*questionToken*/ undefined,741 createKeywordTypeNode(SyntaxKind.AnyKeyword),742 /*initializer*/ undefined);743 changeTracker.insertNodeAfter(sourceFile, findChild("x", sourceFile), newNode);744 });745 }746 {747 const text = `748let x = foo749`;750 runSingleFileTest("insertNodeInStatementListAfterNodeWithoutSeparator1", /*placeOpenBraceOnNewLineForFunctions*/ false, text, /*validateNodes*/ false, (sourceFile, changeTracker) => {751 const newNode = createStatement(createParen(createLiteral(1)));752 changeTracker.insertNodeAfter(sourceFile, findVariableStatementContaining("x", sourceFile), newNode);753 });754 }755 });
...
Using AI Code Generation
1var strykerParent = require('stryker-parent');2console.log(strykerParent.sourceFile('test.js'));3var strykerParent = require('stryker-parent');4console.log(strykerParent.sourceFile('test.js'));5var strykerParent = require('stryker-parent');6console.log(strykerParent.sourceFile('test.js'));7var strykerParent = require('stryker-parent');8console.log(strykerParent.sourceFile('test.js'));9var strykerParent = require('stryker-parent');10console.log(strykerParent.sourceFile('test.js'));11var strykerParent = require('stryker-parent');12console.log(strykerParent.sourceFile('test.js'));13var strykerParent = require('stryker-parent');14console.log(strykerParent.sourceFile('test.js'));15var strykerParent = require('stryker-parent');16console.log(strykerParent.sourceFile('test.js'));17var strykerParent = require('stryker-parent');18console.log(strykerParent.sourceFile('test.js'));19var strykerParent = require('stryker-parent');20console.log(strykerParent.sourceFile('test.js'));21var strykerParent = require('stryker-parent');22console.log(strykerParent.sourceFile('test.js'));23var strykerParent = require('stryker-parent');24console.log(strykerParent.sourceFile('test.js'));
Using AI Code Generation
1const sourceFile = require('stryker').sourceFile;2const chai = require('chai');3const expect = chai.expect;4describe('test', function () {5 it('should pass', function () {6 });7 it('should fail', function () {8 expect(1).to.equal(2);9 });10});11[2018-01-31 11:28:30.325] [INFO] SandboxPool - Creating 1 test runners (based on CPU count)12[2018-01-31 11:28:30.332] [INFO] ConcurrencyTokenProvider - Creating 1 test run(s) based on concurrency 1
Using AI Code Generation
1var sourceFile = require('stryker-parent').sourceFile;2var test = sourceFile('test.js');3var sourceFile = require('stryker-parent').sourceFile;4var test = sourceFile('test.js');5var sourceFile = require('stryker-parent').sourceFile;6var test = sourceFile('test.js');7var sourceFile = require('stryker-parent').sourceFile;8var test = sourceFile('test.js');9var sourceFile = require('stryker-parent').sourceFile;10var test = sourceFile('test.js');11var sourceFile = require('stryker-parent').sourceFile;12var test = sourceFile('test.js');13var sourceFile = require('stryker-parent').sourceFile;14var test = sourceFile('test.js');15var sourceFile = require('stryker-parent').sourceFile;16var test = sourceFile('test.js');17var sourceFile = require('stryker-parent').sourceFile;18var test = sourceFile('test.js');19var sourceFile = require('stryker-parent').sourceFile;20var test = sourceFile('test.js');21var sourceFile = require('stryker-parent').sourceFile;22var test = sourceFile('test.js');23var sourceFile = require('stryker-parent').sourceFile;24var test = sourceFile('test.js');25var sourceFile = require('stryker-parent').sourceFile;26var test = sourceFile('test.js');27var sourceFile = require('stryker-parent').sourceFile;28var test = sourceFile('test.js');29var sourceFile = require('stryker-parent
Using AI Code Generation
1require('stryker-parent').sourceFile('test.js');2require('stryker-child').sourceFile('test.js');3require('stryker-parent').sourceFile('index.js');4require('stryker-child').sourceFile('index.js');5require('stryker-parent').sourceFile('stryker.conf.js');6require('stryker-child').sourceFile('stryker.conf.js');7require('stryker-parent').sourceFile('stryker.conf.js');8require('stryker-child').sourceFile('stryker.conf.js');9require('stryker-parent').sourceFile('stryker.conf.js');10require('stryker-child').sourceFile('stryker.conf.js');11require('stryker-parent').sourceFile('stryker.conf.js');12require('stryker-child').sourceFile('stryker.conf.js');13require('stryker-parent').sourceFile('stryker.conf.js');14require('stryker-child').sourceFile('stryker.conf.js');15require('stryker-parent').sourceFile('stryker.conf.js');16require('stryker-child').sourceFile('stryker.conf.js');
Using AI Code Generation
1var strykerParent = require('stryker-parent');2var strykerParent = require('stryker-parent');3strykerParent.sourceFile('test.js');4var strykerParent = require('stryker-parent');5var strykerParent = require('stryker-parent');6strykerParent.sourceFile('test.js');7var strykerParent = require('stryker-parent');8var strykerParent = require('stryker-parent');9strykerParent.sourceFile('test.js');10var strykerParent = require('stryker-parent');11var strykerParent = require('stryker-parent');12strykerParent.sourceFile('test.js');13var strykerParent = require('stryker-parent');14var strykerParent = require('stryker-parent');15strykerParent.sourceFile('test.js');16var strykerParent = require('stryker-parent');17var strykerParent = require('stryker-parent');18strykerParent.sourceFile('test.js');19var strykerParent = require('stryker-parent');20var strykerParent = require('stryker-parent');21strykerParent.sourceFile('test.js');22var strykerParent = require('stryker-parent');23var strykerParent = require('stryker-parent');24strykerParent.sourceFile('test.js');25var strykerParent = require('stryker-parent');26var strykerParent = require('stryker-parent');27strykerParent.sourceFile('test.js');28var strykerParent = require('stryker-parent');29var strykerParent = require('stryker-parent');30strykerParent.sourceFile('test
Using AI Code Generation
1var strykerParent = require('stryker-parent');2var sourceFile = strykerParent.sourceFile;3var source = sourceFile('test.js');4console.log(source);5var strykerParent = require('stryker-parent');6var sourceFile = strykerParent.sourceFile;7var source = sourceFile('test2.js');8console.log(source);9var strykerParent = require('stryker-parent');10var sourceFile = strykerParent.sourceFile;11var source = sourceFile('test3.js');12console.log(source);13var strykerParent = require('stryker-parent');14var sourceFile = strykerParent.sourceFile;15var source = sourceFile('test4.js');16console.log(source);17var strykerParent = require('stryker-parent');18var sourceFile = strykerParent.sourceFile;19var source = sourceFile('test5.js');20console.log(source);21var strykerParent = require('stryker-parent');22var sourceFile = strykerParent.sourceFile;23var source = sourceFile('test6.js');24console.log(source);25var strykerParent = require('stryker-parent');26var sourceFile = strykerParent.sourceFile;27var source = sourceFile('test7.js');28console.log(source);29var strykerParent = require('stryker-parent');30var sourceFile = strykerParent.sourceFile;31var source = sourceFile('test8.js');32console.log(source);33var strykerParent = require('stryker-parent');34var sourceFile = strykerParent.sourceFile;35var source = sourceFile('test9.js');36console.log(source);
Using AI Code Generation
1var sourceFile = require('stryker-parent').sourceFile;2var source = sourceFile('test.js');3var result = source.findVariableDeclaration('foo');4var sourceFile = require('stryker-parent').sourceFile;5var source = sourceFile('stryker-parent/index.js');6var result = source.findVariableDeclaration('foo');7var sourceFile = require('stryker-parent').sourceFile;8var source = sourceFile('stryker-parent/stryker-parent.js');9var result = source.findVariableDeclaration('foo');10var sourceFile = require('stryker-parent').sourceFile;11var source = sourceFile('node_modules/stryker-parent/stryker-parent.js');12var result = source.findVariableDeclaration('foo');13var sourceFile = require('stryker-parent').sourceFile;14var source = sourceFile('node_modules/stryker-parent/index.js');15var result = source.findVariableDeclaration('foo');16var sourceFile = require('stryker-parent').sourceFile;17var source = sourceFile('node_modules/stryker-parent/test.js');18var result = source.findVariableDeclaration('foo');19var sourceFile = require('stryker-parent').sourceFile;20var source = sourceFile('node_modules/stryker-parent/node_modules/stryker-parent/index.js');
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!