import {NodeImplChunk} from "../chunks/types/NodeImplChunk"; import {ChunkType} from "../chunks/types/ChunkType"; import {nodeImplChunkToCodeNodeDef} from "./nodeImplChunkToCodeNodeDef"; describe("nodeImplChunkToCodeNodeDef()", () => { describe("on individual input handlers", () => { it("should populate inputHandlers", () => { const nodeImplChunk: NodeImplChunk = { "offset": { "line": 7, "column": 2 }, "type": ChunkType.NodeImpl, "children": [ { "offset": { "line": 8, "column": 4 }, "type": ChunkType.NodeCode, "children": [], "content": "console.log(value, tag);", "captures": [ "(value)", null, null, { "type": ChunkType.Identifier, "captures": [ "(value)" ], "offset": { "line": 8, "column": 4 } } ] } ], "content": "(value)\n console.log(value, tag);", "captures": [ "in node", null, { "type": ChunkType.Runtime, "captures": [ "node" ], "offset": { "line": 7, "column": 2 } } ] }; const result = nodeImplChunkToCodeNodeDef(nodeImplChunk); expect(result).toMatchSnapshot(); }); }); describe("on input handler generators", () => { it("should populate spreadInputHandlers", () => { const nodeImplChunk: NodeImplChunk = { "offset": { "line": 44, "column": 2 }, "type": ChunkType.NodeImpl, "children": [ { "offset": { "line": 45, "column": 4 }, "type": ChunkType.NodeCode, "children": [], "content": "const i = {};\nreturn i;", "captures": [ "...(fields)", { "type": ChunkType.SpreadOp, "captures": [ "..." ], "offset": { "line": 45, "column": 4 } }, null, { "type": ChunkType.Identifier, "captures": [ "(fields)" ], "offset": { "line": 45, "column": 4 } } ] } ], "content": "...(fields)\n const i = {};\n return i;", "captures": [ "in es6", null, { "type": ChunkType.Runtime, "captures": [ "es6" ], "offset": { "line": 44, "column": 2 } } ] }; const result = nodeImplChunkToCodeNodeDef(nodeImplChunk); expect(result).toMatchSnapshot(); }); }); describe("when init handler is present", () => { it("should populate initHandler", () => { const nodeImplChunk: NodeImplChunk = { "offset": { "line": 7, "column": 2 }, "type": ChunkType.NodeImpl, "children": [ { "offset": { "line": 8, "column": 4 }, "type": ChunkType.NodeCode, "children": [], "content": "setTimeout(() => outputs.start(null, \"start\"), 0);", "captures": [ "init", null, { "type": ChunkType.BuiltinCode, "captures": [ "init" ], "offset": { "line": 8, "column": 4 } }, null ] } ], "content": "init\n setTimeout(() => outputs.start(null, \"start\"), 0);", "captures": [ "in es6", null, { "type": ChunkType.Runtime, "captures": [ "es6" ], "offset": { "line": 7, "column": 2 } } ] }; const result = nodeImplChunkToCodeNodeDef(nodeImplChunk); expect(result).toMatchSnapshot(); }); }); });