Grafana Sdk Mocks banner
grafana grafana

Grafana Sdk Mocks

Development community

Description

Mocks package for the Grafana SDK to be used when developing TypeScript plugins for Grafana. Includes typings so that the plugin can be built and mocks for the Grafana SDK so that Karma tests will work.

Installation

This entry records only its repository, not the path inside it, so there is no exact command to give. Open the source below and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

README

NOTE, this is no longer the recommended way to develop Grafana Plugins:

We recommend copying one of the following projects and using its config files:


Grafana SDK Mocks for Plugins

This package facilitates writing Grafana plugins in TypeScript.

  • provides Typescript typings for the most common Grafana classes.
  • provides some simple fakes and util files to test plugins with Karma

Setup

With npm, Grunt, karma and mocha.js

This shows how to setup a project with Grunt as the build system, using npm to install the packages (yarn is very similar), karma for unit testing and mocha with expect.js for unit testing.

  1. npm install --save systemjs lodash moment (lodash and moment are optional)
  2. npm install --save-dev grunt grunt-contrib-clean grunt-contrib-copy grunt-contrib-watch grunt-typescript karma karma-expect karma-mocha karma-chrome-launcher karma-sinon karma-systemjs karma-phantomjs-launcher plugin-typescript q sinon
  3. Install this package: npm install --save-dev grafana/grafana-sdk-mocks
  4. Here is an example Gruntfile for building TypeScript. It expects the TypeScript files to be located in a src subdirectory.
module.exports = function(grunt) {
  require('load-grunt-tasks')(grunt);

  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-typescript');
  grunt.loadNpmTasks('grunt-contrib-watch');

  grunt.initConfig({
    clean: ['dist'],

    copy: {
      dist_js: {
        expand: true,
        cwd: 'src',
        src: ['**/*.ts', '**/*.d.ts'],
        dest: 'dist'
      },
      dist_html: {
        expand: true,
        flatten: true,
        cwd: 'src/partials',
        src: ['*.html'],
        dest: 'dist/partials/'
      },
      dist_statics: {
        expand: true,
        flatten: true,