Sketch Test Inspector

Helper utils and plugin for running unit tests on sketch plugins
Alternatives To Sketch Test Inspector
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Plugin Directory3,404
5 days ago1Ruby
Official Sketch Plugin directory
4 years ago19otherJavaScript
A set of plugins for Sketch include drawing links & marks, UI Kit & Color sync, font & text replacing.
4 years agoSeptember 26, 20229mitObjective-C
A Xcode plugin to automatically generate 2x, 1x image from 3x image for you, or upscale to 3x from 2x
Git Sketch Plugin2,454
10 months ago14mitJavaScript
:gem::octocat: A Git client generating pretty diffs built right into Sketch.
Fluid For Sketch2,411
5 years ago35Objective-C
[Sketch Plugin] Sketch-flavored Auto Layout-like Constraints
Sketch Palettes2,216
4 years ago8mitJavaScript
A Sketch plugin for exporting and importing fill presets. It supports colors, gradients, and pattern fills.
Sketch Iconfont1,980
2 years ago25JavaScript
This plugin helps you easily insert and manage icons from icon fonts.
Sketch Style Inventory1,868
4 years ago34mitJavaScript
Review, import & export styles in Sketch.
Sketch Isometric1,656
4 years ago3JavaScript
Generate Isometric and 3D Rotation views from Artboards and Rectangles in Sketch app.
4 years ago25mitJavaScript
Sketch Internationalization Plugin
Alternatives To Sketch Test Inspector
Select To Compare

Alternative Project Comparisons


🕵️‍♀️ Helper utils and plugin for running unit tests on sketch plugins.


The Sketch plugin environment is great, and cocoascript giving you access to (almost) all Objective C classes makes it super powerful as well.

Unfortunately it is not reliable. When using Sketch core classes (because, lets be honest, the JS API is not far enough yet to completely replace those) you always risk running into issues when new versions introduce breaking changes. Also, for macOS and the usage of NS* classes it comes down to pretty much the same issue on every system update. That leads to sweat and long nights of testing and debugging on every new OS or Sketch version.

Sketch plugins are very hard to write unit tests for. This helper library (+ plugin) tries to solve that problem by providing a bunch of helpers that let you write tests for your plugin commands more easily, using your favorite test library as you are used to.

Why can't I just use sketchtool?

Because sketchtool makes it easy to get information about a certain file, or to run a certain plugin command in sketch, but its quite hard to do both. This helper library is build on top of sketchtool (which comes with every Sketch version) to overcome these difficulties.

NOTE: Problems with async

I couldn't find a proper way yet to ensure a plugin command has fished, in order to use it as reference when to save the document and resolve the promise returned by the runPluginCommand and runScript methods. So, for now as a quick fix, I just use timeouts, which will work as long as you don't have any long running processes in your script.

I am currently working on an alternative handling and happy for any ideas 😊

Getting started

yarn add sketch-test-inspector --dev

# or
npm i sketch-test-instepctor --dev

How to use it

To use it, e.g. with jest, simply import the inspector, set your plugin that you want to test, open a file that you want to test on and shoot plugin actions at it ... that's it, simple 😊

const inspector = require('sketch-plugin-inspector');
const path = require('path');

// Set you plugin that you want to test

// Have a test file somewhere, that you want to test your plugin on
const myTestFile = path.resolve(__dirname, 'Test.sketch');

describe('My awesome plugin', () => {
  // Test a specific command of your plugin
  describe('Test action', () => {
    it('Does something', done => {
      // Open the test file in sketch

      // Run a plugin command
        .then(() => {
          // Check if everything is as you'd expect it
          // e.g. if the command was supposed to create 100 pages in the sketch file...



# Clone repo

# Change into repos example dir
cd sketch-test-inspector/example

# Install dependencies and run test
yarn test

This will run the jest tests that use sketch-test-inspector to run plugin commands on a prepared test file.




Sets the plugin for your inspector.


  • name: The file name of your sketch plugin (with or without the .sketchplugin extension)


Opens the specified file in sketch so you can run commands on it.


  • path Absolute sketch file path that you want to open


Changes the selection in the current document to specified layers.


  • layers Array of layers you want to select


Saves the document in its current state. The Inspector will always work with temporary copies of the original file that you specified in openFile, so you never actually overwrite it. You do want to save the temporary file if you made changes (programatically) and want to test the output (sketchtool can only read the file from the disc!). NOTE: runPluginCommand automatically saves the temp. file before resolving the promise!


Closes the current document. Mainly because right now the inspector physically opens Sketch. This function lets you close the opened document window.


Runs specified command identifier on plugin that has been specified before via setPlugin.


  • identifier The plugin command identifier you want to run on the currently opened file.


Runs specified custom script as plugin command. The function will receive the command context and will then be run within Sketch, giving it access the whole cocoascript environent of Sketch plugins.


  • fnc The function you want to run as plugin command


sketchtool dump ${currentFilePath}


sketchtool list ${type} ${currentFilePath}


  • type Sketchtool list type.


sketchtool list pages ${currentFilePath}

Todos / Roadmap

  • [ ] Change to running sketchtool in the background rather than physically having to open the test file(s) in Sketch!
  • [ ] Add more utils, like Sketch action listeners, observer for logs and document messages, etc.
  • [ ] Optimise plugin command handling and promise resolving
  • [ ] Optimise automated resetting and garbage collection of temporary files
  • [ ] Think about test coverage
Popular Plugin Projects
Popular Sketch Projects
Popular Libraries Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Unit Testing
Sketch Plugin