How to use sourceFile method in storybook-root

Best JavaScript code snippet using storybook-root

textChanges.ts

Source:textChanges.ts Github

copy

Full Screen

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 }); ...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var sourceFile = require('storybook-root').sourceFile;2var source = sourceFile('test.js');3console.log(source);4var sourceFile = require('storybook-root').sourceFile;5var source = sourceFile('test.js');6console.log(source);7var sourceFile = require('storybook-root').sourceFile;8var source = sourceFile('test.js');9console.log(source);10var sourceFile = require('storybook-root').sourceFile;11var source = sourceFile('test.js');12console.log(source);13var sourceFile = require('storybook-root').sourceFile;14var source = sourceFile('test.js');15console.log(source);16var sourceFile = require('storybook-root').sourceFile;17var source = sourceFile('test.js');18console.log(source);19var sourceFile = require('storybook-root').sourceFile;20var source = sourceFile('test.js');21console.log(source);22var sourceFile = require('storybook-root').sourceFile;23var source = sourceFile('test.js');24console.log(source);25var sourceFile = require('storybook-root').sourceFile;26var source = sourceFile('test.js');27console.log(source);28var sourceFile = require('storybook-root').sourceFile;29var source = sourceFile('test.js');30console.log(source);31var sourceFile = require('storybook-root').sourceFile;32var source = sourceFile('test.js');33console.log(source);34var sourceFile = require('storybook-root').sourceFile;35var source = sourceFile('test.js');36console.log(source);

Full Screen

Using AI Code Generation

copy

Full Screen

1var storybook = require('storybook-root');2storybook.sourceFile('test.js');3var storybook = require('storybook-root');4storybook.sourceFile('test.js');5var storybook = require('storybook-root');6storybook.sourceFile('test.js');7var storybook = require('storybook-root');8storybook.sourceFile('test.js');9var storybook = require('storybook-root');10storybook.sourceFile('test.js');11var storybook = require('storybook-root');12storybook.sourceFile('test.js');13var storybook = require('storybook-root');14storybook.sourceFile('test.js');15var storybook = require('storybook-root');16storybook.sourceFile('test.js');17var storybook = require('storybook-root');18storybook.sourceFile('test.js');19var storybook = require('storybook-root');20storybook.sourceFile('test.js');21var storybook = require('storybook-root');22storybook.sourceFile('test.js');

Full Screen

Using AI Code Generation

copy

Full Screen

1import { sourceFile } from 'storybook-root';2const source = sourceFile('./other.js');3console.log(source);4import { sourceFile } from 'storybook-root';5const source = sourceFile('./test.js');6console.log(source);

Full Screen

Using AI Code Generation

copy

Full Screen

1import { sourceFile } from 'storybook-root'2const src = sourceFile('src/components/Button/Button.js')3console.log(src)4import { sourceFile } from 'storybook-root'5const src = sourceFile('src/components/Button/Button.js')6console.log(src)7import { sourceFile } from 'storybook-root'8const src = sourceFile('src/components/Button/Button.js')9console.log(src)10import { sourceFile } from 'storybook-root'11const src = sourceFile('src/components/Button/Button.js')12console.log(src)13import { sourceFile } from 'storybook-root'14const src = sourceFile('src/components/Button/Button.js')15console.log(src)16import { sourceFile } from 'storybook-root'17const src = sourceFile('src/components/Button/Button.js')18console.log(src)19import { sourceFile } from 'storybook-root'20const src = sourceFile('src/components/Button/Button.js')21console.log(src)22import { sourceFile } from 'storybook-root'23const src = sourceFile('src/components/Button/Button.js')24console.log(src)25import { sourceFile } from 'storybook-root'26const src = sourceFile('src/components/Button/Button.js')27console.log(src)28import { sourceFile } from 'storybook-root'29const src = sourceFile('src/components/Button/Button.js')30impsole.log(src)31imporr {t { soeFilu } from 'storybook-root'32const srcrcesourceFile('sFc/components/Button/Button.js')33consoli.log(src)

Full Screen

Using AI Code Generation

copy

Full Screen

1const source = rele } from 'storybook-root'2const src = sourceFile('src/components/Button/Button.js')3console.log(src)4import { sourceFile } from 'storybook-root'5const src = sourceFile('src/components/Button/Button.js')6console.log(src)7import { sourceFile } from 'storybook-root'8const src = sourceFile('src/components/Button/Button.js')9console.log(src)10import { sourceFile } from 'storybook-root'11const src = sourceFile('src/components/Button/Button.js')12console.log(src)13import { sourceFile } from 'storybook-root'14const src = sourceFile('src/components/Button/Button.js')15console.log(src)16import { sourceFile } from 'storybook-root'17const src = sourceFile('src/components/Button/Button.js')18console.log(src)19import { sourceFile } from 'storybook-root'20const src = sourceFile('src/components/Button/Button.js')21console.log(src)22import { sourceFile } from 'storybook-root'23const src = sourceFile('src/components/Button/Button.js')24console.log(src)25import { sourceFile } from 'storybook-root'26const src = sourceFile('src/components/Button/Button.js')27console.log(src)28import { sourceFile } from 'storybook-root'29const src = sourceFile('src/components/Button/Button.js')30console.log(src)31import { sourceFile } from 'storybook-root'32const src = sourceFile('src/components/Button/Button.js')33console.log(src)

Full Screen

Using AI Code Generation

copy

Full Screen

1import { sourceFile } from './test.js'2i;port { sourceFil } from './test.js'3import { sourceFile } from './test.js'4import { sourceFile } from './test.js'5import { sourceFile } from './test.js'6import { sourceFile } from './test.js'7import { sourceFile } from './test.js'8import { sourceFile } from './test.js'9import { sourceFile } from './test.js'10import { sourceFile } from './test.js'11import12const sourcePath = path.join(__dirname, 'test.js');13const sourceCode = sourceFile(sourcePath);14console.log(sourceCode);15const source = require('./storybook-root');16const path = require('path');17const sourceFile = source.sourceFile;18const sourcePath = path.join(__dirname, 'test.js');19const sourceCode = sourceFile(sourcePath);20console.log(sourceCode);21const source = require('./storybook-root');22const path = require('path');23const sourceFile = source.sourceFile;24const sourcePath = path.join(__dirname, 'test.js');25const sourceCode = sourceFile(sourcePath);26console.log(sourceCode);27const source = require('./storybook-root');28const path = require('path');29const sourceFile = source.sourceFile;30const sourcePath = path.join(__dirname, 'test.js');31const sourceCode = sourceFile(sourcePath);32console.log(sourceCode);33const source = require('./storybook-root');34const path = require('path');35const sourceFile = source.sourceFile;36const sourcePath = path.join(__dirname, 'test.js');37const sourceCode = sourceFile(sourcePath);38console.log(sourceCode);39const source = require('./storybook-root');40const path = require('path');41const sourceFile = source.sourceFile;42const sourcePath = path.join(__dirname, 'test.js');43const sourceCode = sourceFile(sourcePath);44console.log(sourceCode);45const source = require('./storybook-root');46const path = require('path');47const sourceFile = source.sourceFile;48const sourcePath = path.join(__dirname

Full Screen

Using AI Code Generation

copy

Full Screen

1import { sourceFile } from 'storybook-root';2const source = sourceFile('./other.js');3console.log(source);4import { sourceFile } from 'storybook-root';5const source = sourceFile('./test.js');6console.log(source);

Full Screen

Using AI Code Generation

copy

Full Screen

1const source = require('./storybook-root');2const path = require('path');3const sourceFile = source.sourceFile;4const sourcePath = path.join(__dirname, 'test.js');5const sourceCode = sourceFile(sourcePath);6console.log(sourceCode);7const source = require('./storybook-root');8const path = require('path');9const sourceFile = source.sourceFile;10const sourcePath = path.join(__dirname, 'test.js');11const sourceCode = sourceFile(sourcePath);12console.log(sourceCode);13const source = require('./storybook-root');14const path = require('path');15const sourceFile = source.sourceFile;16const sourcePath = path.join(__dirname, 'test.js');17const sourceCode = sourceFile(sourcePath);18console.log(sourceCode);19const source = require('./storybook-root');20const path = require('path');21const sourceFile = source.sourceFile;22const sourcePath = path.join(__dirname, 'test.js');23const sourceCode = sourceFile(sourcePath);24console.log(sourceCode);25const source = require('./storybook-root');26const path = require('path');27const sourceFile = source.sourceFile;28const sourcePath = path.join(__dirname, 'test.js');29const sourceCode = sourceFile(sourcePath);30console.log(sourceCode);31const source = require('./storybook-root');32const path = require('path');33const sourceFile = source.sourceFile;34const sourcePath = path.join(__dirname, 'test.js');35const sourceCode = sourceFile(sourcePath);36console.log(sourceCode);37const source = require('./storybook-root');38const path = require('path');39const sourceFile = source.sourceFile;40const sourcePath = path.join(__dirname

Full Screen

Using AI Code Generation

copy

Full Screen

1const storybookRoot = require('storybook-root');2const path = require('path');3const storybookDir = path.join(__dirname, '../storybook');4const storybook = storybookRoot(storybookDir);5module.exports = storybook.sourceFile('test.js');6const data = require('./test');7console.log(data);

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 storybook-root 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