Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dnicolson/jxa-unit-testing
✅ Experiment to unit test AppleScript with JXA and Jest
https://github.com/dnicolson/jxa-unit-testing
Last synced: about 1 month ago
JSON representation
✅ Experiment to unit test AppleScript with JXA and Jest
- Host: GitHub
- URL: https://github.com/dnicolson/jxa-unit-testing
- Owner: dnicolson
- Created: 2019-09-10T21:14:14.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-09-22T14:17:59.000Z (over 5 years ago)
- Last Synced: 2024-10-06T02:21:24.560Z (4 months ago)
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# JXA Unit Testing
This is an experiment in writing a JXA script that can be run unmodified by OSA, Node and Jest. As of ES2019 it appears to [not be possible](https://stackoverflow.com/questions/56592950/mocking-jxa-calls-with-the-proxy-object) to use the Proxy object to mock JXA calls as method calls and properties are indistinguishable. Dependency injection can be used to make method wrappers for the JXA and testing environment.
A very old AppleScript that updates missing track counts in iTunes has been rewritten in JXA and tested with Jest at about 1/3 of the size of the old script.
The code can be run without modification in the following environments:
### OSA
`osascript -l JavaScript set-track-counts.js`
### Node
`node set-track-counts.js`
### Jest
`jest set-track-counts.test.js`
### Script Editor
`cp set-track-counts.js set-track-counts.applescript && open -a "Script Editor" set-track-counts.applescript`
### Music
`cp set-track-counts.js ~/Library/Music/Scripts/set-track-counts.js`
The script menu can be used to invoke the script in Music.