All Projects → julianburr → sketch-test-inspector

julianburr / sketch-test-inspector

Licence: MIT license
Helper utils and plugin for running unit tests on sketch plugins

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to sketch-test-inspector

Paddy Sketch Plugin
Automated padding, spacing and alignment for your Sketch layers
Stars: ✭ 2,219 (+12227.78%)
Mutual labels:  sketch, sketch-plugin
Android res export
Export Android resources in Sketch, bitmap assets, nine-patch, vector drawable, app icon, shape XML..
Stars: ✭ 204 (+1033.33%)
Mutual labels:  sketch, sketch-plugin
Picasso
一款sketch生成代码插件,可将sketch设计稿自动解析成前端代码。
Stars: ✭ 191 (+961.11%)
Mutual labels:  sketch, sketch-plugin
Symbol Swapper
Swap the selected symbols and/or symbol instances to a master of the same name in a library.
Stars: ✭ 179 (+894.44%)
Mutual labels:  sketch, sketch-plugin
Git Sketch Plugin
💎 A Git client generating pretty diffs built right into Sketch.
Stars: ✭ 2,459 (+13561.11%)
Mutual labels:  sketch, sketch-plugin
Sketch Style Master
Sketch plugin for renaming shared styles
Stars: ✭ 193 (+972.22%)
Mutual labels:  sketch, sketch-plugin
Copy Framer Code
A Sketch plugin that copies any selected layer to the clipboard as code that can be pasted straight into a Framer prototype.
Stars: ✭ 201 (+1016.67%)
Mutual labels:  sketch, sketch-plugin
Sketch Iconfont
This plugin helps you easily insert and manage icons from icon fonts.
Stars: ✭ 1,980 (+10900%)
Mutual labels:  sketch, sketch-plugin
Sketchcrapp
SketchCrapp - Crack your Sketch.app in seconds :) Supports MacOS Big Sur.
Stars: ✭ 218 (+1111.11%)
Mutual labels:  sketch, sketch-plugin
Fluid For Sketch
[Sketch Plugin] Sketch-flavored Auto Layout-like Constraints
Stars: ✭ 2,408 (+13277.78%)
Mutual labels:  sketch, sketch-plugin
Icondrop
Get access to 2 million+ design resources right inside Adobe Xd, Figma, Sketch, Microsoft Office, G Suite and many more.
Stars: ✭ 174 (+866.67%)
Mutual labels:  sketch, sketch-plugin
React Sketchapp
render React components to Sketch ⚛️💎
Stars: ✭ 14,861 (+82461.11%)
Mutual labels:  sketch, sketch-plugin
Move To Library Sketchplugin
You can now move symbol from your project to any library and re-attach all the symbol instances to this library. also it keep the overrides without any problems and it work with abstract that have libraries not in your local machine
Stars: ✭ 174 (+866.67%)
Mutual labels:  sketch, sketch-plugin
Library Symbol Replacer
Sketch plugin to replace symbols in an existing documents with library symbols 💎 📚
Stars: ✭ 193 (+972.22%)
Mutual labels:  sketch, sketch-plugin
Sketch2ae
A Sketch plugin to export sketch file to Adobe After Effect
Stars: ✭ 170 (+844.44%)
Mutual labels:  sketch, sketch-plugin
Sketch Palettes
A Sketch plugin for exporting and importing fill presets. It supports colors, gradients, and pattern fills.
Stars: ✭ 2,267 (+12494.44%)
Mutual labels:  sketch, sketch-plugin
Symbol Instance Renamer
Rename symbol instances to the name of their master.
Stars: ✭ 164 (+811.11%)
Mutual labels:  sketch, sketch-plugin
Sketch Tailwind
A plugin that tries to bridge the gap between designs and code. Sketch Tailwind lets you export aspects of a design made in Sketch to a javascript theme file that you can import into your TailwindCSS config
Stars: ✭ 166 (+822.22%)
Mutual labels:  sketch, sketch-plugin
Plugin Requests
A collection of plugins requested to our Twitter account
Stars: ✭ 211 (+1072.22%)
Mutual labels:  sketch, sketch-plugin
Pdf Export Sketch Plugin
Sketch plugin for PDF exporting
Stars: ✭ 231 (+1183.33%)
Mutual labels:  sketch, sketch-plugin

sketch-test-inspector

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

Why?

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
inspector.setPlugin('my-awesome-plugin');

// 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
      inspector.openFile(myTestFile);

      // Run a plugin command
      inspector.runPluginCommand('AwesomeCommand')
        .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...
          expect(inspector.pages().length).toBe(100);
          done();
        })
        .catch(done.fail);
    });
  });

});

Example

# Clone repo
gitclone https://github.com/julianburr/sketch-test-inspector.git

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

# Install dependencies and run test
yarn
yarn test

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

sketch-test-inspector

Methods

setPlugin(name)

Sets the plugin for your inspector.

Params:

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

openFile(path)

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

Params:

  • path Absolute sketch file path that you want to open

selectLayers(layers)

Changes the selection in the current document to specified layers.

Params:

  • layers Array of layers you want to select

saveDocument

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!

closeDocument

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

runPluginCommand(identifier)

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

Params:

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

runScript(fnc)

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.

Params:

  • fnc The function you want to run as plugin command

dump

sketchtool dump ${currentFilePath}

list(type)

sketchtool list ${type} ${currentFilePath}

Params:

  • type Sketchtool list type.

pages

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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].