Code Monkey home page Code Monkey logo

karma-ui5's Introduction

UI5 icon

REUSE status NPM Version

Table of Contents

About

This Karma plugin helps testing your UI5 projects.

Please refer to the Testing section in the UI5 Developer Guide for information about writing tests for your project.

Note: This project has been renamed from karma-openui5 to karma-ui5 with the v1.0.0 release.
For upgrade information, see the Migration Guide.
For the karma-openui5 documentation, see 0.x branch.

Quickstart

Installation

First you need to install the Karma CLI globally:

npm install -g karma-cli

You can find more information on installing Karma here.

Next, you need to add karma and karma-ui5 as devDependencies:

npm install --save-dev karma karma-ui5

To start a browser, you also need to install a launcher, e.g. for Chrome:

npm install --save-dev karma-chrome-launcher

Configuration

To configure the plugin, you need to add two things to your karma.conf.js:

  1. Specify "ui5" in the list of frameworks.
  2. Set a URL for serving the UI5 resources.

This is an example karma.conf.js file that is sufficient for most projects:

module.exports = function(config) {
  config.set({

    frameworks: ["ui5"],

    ui5: {
      url: "https://openui5.hana.ondemand.com"
    },

    browsers: ["Chrome"]

  });
};

Execution

With the above configuration, karma will by default run all tests in Chrome and listen for changed files to execute them again (watch mode).

karma start

For CI testing, you can run Chrome in headless mode and execute the tests only once using the singleRun option:

module.exports = function(config) {
  config.set({

    // ...

    browsers: ["ChromeHeadless"],
    singleRun: true

  });
};

The options can also be set via CLI arguments:

karma start --browsers=ChromeHeadless --singleRun=true

For more information, see the "Configuration File" documentation from Karma.

Karma Configuration Requirements

There is an important requirement for using this plugin:

  • The karma basePath option must point to your project root, not to a subfolder like "webapp". This is the default when your karma.conf.js is in the project root.
    It is required for the type detection and automatic inclusion of your project files.

Options

All configuration options need to be defined in an ui5 object in your Karma configuration:

module.exports = function(config) {
  config.set({

    ui5: {

    }

  });
};

url

Type: string
CLI: --ui5.url

The URL where UI5 should be loaded from.

When omitted and the project contains a ui5.yaml file, UI5 Tooling will be used as server middleware.

Example:

ui5: {
  url: "https://openui5.hana.ondemand.com"
}

type

Type: enum ("application" / "library")

Defines the project type.
If not set, it is automatically detected based on

  • the type defined in ui5.yaml, or
  • existing folders
    • "webapp" => application
    • "src" / "test" => library

Example:

ui5: {
  type: "application"
}

paths

Type: object

Custom path mappings for project folders based on the type.
Use this option only when the automatic type detection does not work because the project uses a different folder structure.

Example application:

ui5: {
  type: "application",
  paths: {
    webapp: "src/main/webapp"
  }
}

Example library:

ui5: {
  type: "library",
  paths: {
    src: "src/main/js",
    test: "src/test/js"
  }
}

configPath

Type: string
Default: "ui5.yaml"
CLI: --ui5.configPath

Path to the UI5 configuration file. It is resolved relative to the project root.

Example:

ui5: {
  configPath: "ui5-test.yaml"
}

mode

Type: enum ("html" / "script")
Default: "html"

Configures the mode how tests should be executed.

html

The HTML mode runs QUnit test suites and test pages in a separate context.
It has built-in support for QUnit. The QUnit adapter must not be used in combination with this mode. Other framework plugins must also not be used. Instead, the required libraries such as sinon should be loaded within the test.

ui5: {
  mode: "html"
}

Specific config options:

script

The script mode includes the UI5 bootstrap script. It allows to pass UI5 config and loads your test modules.
You need to also install and configure an adapter for your test framework such as QUnit, to enable test execution and reporting.

ui5: {
  mode: "script"
}

Specific config options:

testpage

Type: string
CLI: --ui5.testpage
Specific to "html" mode

A file path pointing to a test page or test suite that should be executed.
The path needs to be relative to the project root.

If not set, the project is scanned for available test suites (testsuite.qunit.html).
When exactly one test suite is found, it will be used as testpage. Otherwise, all found pages are printed out and one of them needs to be configured manually.

Example:

ui5: {
  mode: "html",
  testpage: "webapp/test/myTestPage.qunit.html"
}

urlParameters

Type: Array
Specific to "html" mode

URL parameters to append to every testpage.

Example:

ui5: {
    mode: "html",
    urlParameters: [{
        key: "hidepassed",
        value: true
    }]
}

config

Type: object
Specific to "script" mode

Configuration of the UI5 bootstrap.

Example:

ui5: {
  mode: "script",
  config: {
    bindingSyntax: "complex",
    compatVersion: "edge",
    async: true,
    resourceRoots: {
      "sap.ui.demo.todo": "./base/webapp"
    }
  }
}

tests

Type: Array
Specific to "script" mode

List of test modules that should be loaded (via sap.ui.require).
If not provided, the test files must be included in the karma files config to load them with <script> tags.

Example:

ui5: {
  mode: "script",
  tests: [
    "sap/ui/demo/todo/test/unit/AllTests",
    "sap/ui/demo/todo/test/integration/AllJourneys"
  ]
}

API

helper

This plugin also comes with a helper module to be used in your Karma configuration file.

configureIframeCoverage

Enables code coverage for iframes. Can only be used in combination with the karma-coverage plugin (v2.0.0+).

Must be called from the karma configuration function after the coverage plugin has been configured. The config object must be passed as a parameter.

module.exports = function(config) {
	config.set({

		// ...

	});
	require("karma-ui5/helper").configureIframeCoverage(config);
};

Big Thanks

Cross-browser Testing Platform and Open Source <3 Provided by Sauce Labs.

Testing Provided by Sauce Labs

karma-ui5's People

Contributors

matz3 avatar randombyte avatar dependabot-preview[bot] avatar romaniam avatar cevou avatar dependabot-support avatar sabineloss avatar mlenkeit avatar thodd avatar janmattfeld avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.