Skip to content

Instantly share code, notes, and snippets.

View yoav-lavi's full-sized avatar

Yoav Lavi yoav-lavi

View GitHub Profile
@yoav-lavi
yoav-lavi / test.js
Created October 13, 2019 19:52
Scriptable describe + test
exports.describe = async (name, callback) => {
const output = [];
const test = async (name, callback) => {
const testStartTime = Date.now();
const testResult = await callback();
const testTime =
Date.now() - testStartTime;
output.push(
`• ${name} (${testTime}ms): ${
testResult ? '✅' : '❌'
@yoav-lavi
yoav-lavi / store.js
Last active January 31, 2025 18:54
A key value store for Scriptable
module.exports = storeName => {
const files = FileManager.iCloud();
const documents = files.documentsDirectory();
const stores = `${documents}/stores`;
const store = `${stores}/${storeName}`;
if (!files.isDirectory(stores)) {
files.createDirectory(stores);
}
@yoav-lavi
yoav-lavi / store.test.js
Created October 15, 2019 18:06
Tests for store.js
const createStore = importModule('store');
const { describe } = importModule('test');
const store = createStore('store-test');
await describe('Store', async test => {
const key = 'key';
const value = 'value';
await test('Saves and retrieves a value', async () => {
store.set(key, value);