Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

debug.test.ts

80 lines1.8 KB

1import { describe, expect, test, vi } from 'vitest'
2import { D2 } from '../../src/d2.js'
3import { MultiSet } from '../../src/multiset.js'
4import { debug } from '../../src/operators/index.js'
5​
6describe(`Operators`, () => {
7 describe(`Debug operation`, () => {
8 test(`basic debug operation`, () => {
9 const graph = new D2()
10 const input = graph.newInput<number>()
11 const consoleSpy = vi.spyOn(console, `log`)
12​
13 input.pipe(debug(`test`))
14​
15 graph.finalize()
16​
17 input.sendData(
18 new MultiSet([
19 [1, 1],
20 [2, 1],
21 [3, 1],
22 ]),
23 )
24​
25 graph.run()
26​
27 expect(consoleSpy).toHaveBeenCalledWith(
28 `debug test data: MultiSet([[1,1],[2,1],[3,1]])`,
29 )
30 })
31​
32 test(`debug with indentation`, () => {
33 const graph = new D2()
34 const input = graph.newInput<number>()
35 const consoleSpy = vi.spyOn(console, `log`)
36​
37 input.pipe(debug(`test`, true))
38​
39 graph.finalize()
40​
41 input.sendData(
42 new MultiSet([
43 [1, 1],
44 [2, 1],
45 [3, 1],
46 ]),
47 )
48​
49 graph.run()
50​
51 expect(consoleSpy).toHaveBeenCalledWith(
52 `debug test data: MultiSet([\n [\n 1,\n 1\n ],\n [\n 2,\n 1\n ],\n [\n 3,\n 1\n ]\n])`,
53 )
54 })
55​
56 test(`debug with negative multiplicities`, () => {
57 const graph = new D2()
58 const input = graph.newInput<number>()
59 const consoleSpy = vi.spyOn(console, `log`)
60​
61 input.pipe(debug(`test`))
62​
63 graph.finalize()
64​
65 input.sendData(
66 new MultiSet([
67 [1, -1],
68 [2, -2],
69 [3, 1],
70 ]),
71 )
72​
73 graph.run()
74​
75 expect(consoleSpy).toHaveBeenCalledWith(
76 `debug test data: MultiSet([[1,-1],[2,-2],[3,1]])`,
77 )
78 })
79 })
80})