Debian Codegraph @

script/demo

raw
1 #!/usr/bin/env osascript
2
3 -- Dependencies
4 -- python
5 -- pip
6 -- venv
7 -- asciinema
8 -- svg-term-cli
9
10 tell application "Terminal"
11 activate
12 delay 1
13 my clearScreen(1)
14 -- Ensure folder is ready and reset
15 my execInput({"rm ", 27, "r ~/syrupy_example"}, 1)
16 my execInput({"mkdir ", 27, "p ~/syrupy_example"}, 1)
17 my execInput({"cd ~/syrupy_example"}, 1)
18 -- Activate venv
19 my execPythonCmd({"venv venv"}, 4)
20 my execInput({"source venv/bin/activate"}, 1)
21 my clearScreen(1)
22 -- Start recording
23 my execInput({"asciinema rec demo", 47, "cast"}, 3)
24 my clearScreen(1)
25 -- Install pytest and syrupy
26 my execPipInstall("pytest syrupy", 2)
27 -- Write initial snapshot test file
28 my createTestFile()
29 my execPytestVerbose()
30 my execPytestSnapshotUpdate()
31 -- Show generated snapshots
32 my execListFiles(".")
33 my execListFiles("__snapshots__")
34 my readTestFileSnapshot()
35 -- Modify test file
36 my updateTestFile1()
37 my execPytestVerbose()
38 my execPytestSnapshotUpdate()
39 -- Modify test file
40 my updateTestFile2()
41 my execPytestVerbose()
42 my execPytestSnapshotUpdate()
43 -- Show updated snapshots
44 my readTestFileSnapshot()
45 my clearScreen(1)
46 -- Stop recording
47 my execInput({"exit"}, 1)
48 my sendInput({"cat demo", 47, "cast | svg", 27, "term "}, 1)
49 my execInput({27, 27, "window ", 27, 27, "out usage_demo", 47, "svg"}, 0)
50 end tell
51
52 on clearScreen(wait)
53 tell application "System Events"
54 tell application process "Terminal"
55 keystroke "k" using command down
56 end tell
57 end tell
58 delay wait
59 end clearScreen
60
61 on inputDelay(n)
62 delay random number from 0.003 to 0.1
63 end inputDelay
64
65 on sendInput(input, n)
66 set inputs to {}
67 repeat n times
68 set inputs to inputs & input
69 end repeat
70 tell application "System Events"
71 tell application process "Terminal"
72 set frontmost to true
73 repeat with input in inputs
74 if class of input is integer then
75 key code input
76 my inputDelay(n)
77 else
78 repeat with char in input
79 keystroke char
80 my inputDelay(n)
81 end repeat
82 end if
83 end repeat
84 end tell
85 end tell
86 end sendInput
87
88 on execInput(cmds, wait)
89 sendInput(cmds, 1)
90 tell application "System Events"
91 tell application process "Terminal"
92 keystroke return
93 end tell
94 end tell
95 delay wait
96 end execInput
97
98 on execListFiles(folder)
99 my execInput({"ls ", 27, "l ", folder}, 2)
100 end execListFiles
101
102 on execPythonCmd(cmd, wait)
103 execInput({"python ", 27, "m "} & cmd, wait)
104 end execPythonCmd
105
106 on execPipInstall(packages, wait)
107 my execPythonCmd({"pip install ", 27, "U ", packages}, wait)
108 end execPipInstall
109
110 on execPytestVerbose()
111 my execPythonCmd({"pytest ", 27, "vv"}, 2)
112 end execPytestSnapshotUpdate
113
114 on execPytestSnapshotUpdate()
115 my execPythonCmd({"pytest ", 27, 27, "snapshot", 27, "update"}, 2)
116 end execPytestSnapshotUpdate
117
118 on createTestFile()
119 my execInput({"vim test_file", 47, "py"}, 1)
120 my execInput({"i","def test_case(snapshot):"}, 1)
121 my execInput({" assert 'syrupy is amazing!' == snapshot"}, 1)
122 my execInput({""}, 1)
123 my execInput({"def test_other(snapshot):"}, 1)
124 my execInput({" assert 'this is amazing' == snapshot"}, 1)
125 my execInput({" assert dict(key='value', hmm=[1,2]) == snapshot"}, 1)
126 my execInput({53}, 1)
127 my execInput({":wq"}, 1)
128 end createFile
129
130 on readTestFileSnapshot()
131 my execInput({"less __snapshots__/test_file", 47, "ambr"}, 3)
132 my execInput({":q"}, 1)
133 end readTestFileSnapshot
134
135 on updateTestFile1()
136 my execInput({"vim test_file", 47, "py"}, 1)
137 my sendInput({125}, 4)
138 my sendInput({124}, 27)
139 my sendInput({"i", "!", 53}, 1)
140 my execInput({":wq"}, 1)
141 end updateTestFile1
142
143 on updateTestFile2()
144 my execInput({"vim test_file", 47, "py"}, 1)
145 my sendInput({125}, 5)
146 my sendInput({124}, 36)
147 my sendInput({"i", 51, 51, 53}, 1)
148 my execInput({":wq"}, 1)
149 end updateTestFile1