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