npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sitevision-mock

v0.0.28

Published

Mock For Sitevision Webapps / Restapps

Downloads

67

Readme

sitevision-mock

Jest mock for Sitevision Webapps / Restapps (Server side Javascript). Works with both Webapps 1 and 2.

Build npm

Prerequisites

Only applies if you are building the applications in the old / legacy way

  • Your Module Server Javascript code must be written in ES6-format in order to use this mock, see more here how to get started: https://github.com/OlofFredriksson/babel-plugin-transform-sitevision-apps

More information regarding the "bundled app" concept, please read on the following link: https://developer.sitevision.se/archives/developer-news/developer-news/2021-06-10-bundled-apps

Getting started

npm install --save-dev sitevision-mock

Load all (recommended)

In your jest.config.js, add following:

{
  "moduleNameMapper": {
      ...require("sitevision-mock")
  }
}

Examples

See the tests in integration/ if you need some inspiration how to write test cases with this mock.

Transformers

The Sitevision API sometimes returns Java Objects, List & Calendar for example. This repo also contains transformers which could help you adding mock data.

Helpfull to use if you for example need to mock PropertyUtil values.

// Your Test file
import List from "sitevision-mock/dist/transformers/List";
...
const node = {
  yourProperty: new List([1, 2, 3]),
};

Mock Sitevision Node

There is helper to generate a mocked Sitevision Node, with some of the properties and functions.

import { mockNode } from "sitevision-mock/dist/mockNode";

node = mockNode({
    uuid: "myUUID",
});

node.getIdentifier(); // => myUUID

Typescript

sitevision-mock supports webapps written in Typescript. However, due to limitations with the Sitevision Typings file, you cant setMockData directly on the imported members. See workaround:

Working

import { setMockData } from "sitevision-mock/dist/setMockData";
setMockData("PortletContextUtil", {
    getCurrentPage: { key2: "/URI" },
});

Not Working

import portletContextUtil from "PortletContextUtil";
portletContextUtil.__setMockData({
    getCurrentPage: { key1: "/URI" },
});

If you use Javascript both ways work.

Why using Sitevision mock?

If you write unit tests with Jest, you should be able to focus on writing tests on the functions and logic in your code, not spend time on writing mock functions for the Sitevision API.

Imported classes will get wrapped in a jest object, so you can mock the return value or check if functions have been called.

References Sitevision API

  • https://developer.sitevision.se/webdav/files/apidocs/overview-summary.html
  • https://developer.sitevision.se/docs/webapps

Notice

This project is made during my spare time and since I dont have access to any Sitevision server its quite hard at the moment to show a good template project where this mock, and the babel-transform-plugin is used.

In a perfect world, maybe this mock is something that in the future should be generated by Sitevision themself? Much easier than doing reverse engineering. :-) (But less fun?)