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

@talentsoft-opensource/widget-display-tool

v5.3.4

Published

Widget Simulator

Downloads

171

Readme

Getting Started:

This tools provides a testing environnement for your widget.

Prerequisites:

  1. You should have the following software installed:

    • git
    • node 8.12
    • yarn 1.10.1
  2. The first time you use this tool, you need to install the libraries by running yarn install in a terminal in the project folder (defined in package.json)

  3. You should already have built your widget on your machine and generated a widget bundle file (for example, main.bundle.js) on your local drive. You also need a mock bundle file. Please check the exemple widget for a template to generate such bundles.

How to launch:

To launch the build and deployment of your widget, run yarn start [path to your widget bundle (widget)] [path to your mock script]

Displaying the widget:

Once it's launched, you can view your widget by opening a browser and navigating to: http://localhost:5555/.

Configuring the port number of local url

If you need to change the port number of the local url, you can change the port variable in the file index.js in the root folder.

Customizing the environment of the widget with the mock file

In the testing environment provided by this tool, all host methods such as requestExternalResource are mocked. You may provide your own implementation to test your widget in different conditions.

In order to do this you need to provide a mock script that exports an object that implements the HostMock interface. Please check the exemple widget for an exemple mock script (in the mock folder).

Example

Suppose that your API returns a list of objects and you want to mock your API by returning :

[
            {
                id: 'ToDo',
                y: 0,
                z: 2458
            },
            ...
]

=> You should implement the method requestExternalResource in a typescript file as:

/**
 * This file contains the callbacks that you can modify to test the display of your widget
 */
import { HostMock } from '@talentsoft-opensource/widget-display-tool/src/mock-definitions'
import { HttpResponse, RequestOptions } from '@talentsoft-opensource/integration-widget-contract'

export const hostmock: HostMock = {
    /**
     * This flag controls the requestExternalResource behavior:
     * - proxyMode: true => makes a real http request
     * - proxyMode: false => calls the mocked version defined in this file
     */
    proxyMode: true,

    /**
     * if proxyMode == true, when a direct connect request is made this secretkey will be used
     */
    secretKey: "mysec",

    /**
     * if proxyMode == true, when a direct connect request is made this login will be used
     */
    login: "mylogin",

    /**
     * if proxyMode == false, this method is called instead of sending a request
     */
    requestExternalResource: (options: RequestOptions) => {
        const data = [
            {
                id: 'ToDo',
                y: 0,
                z: 2458
            },
            {
                id: 'InProgress',
                y: 0,
                z: 3874
            },
            {
                id: 'ToValidate',
                y: 0,
                z: 2375
            },
            {
                id: 'Validated',
                y: 0,
                z: 129
            },
        ];
    
        return new Promise<HttpResponse>((resolve, reject) => {
            const response: HttpResponse = {
                body: JSON.stringify(data),
                status: 200,
                headers: {}
            };
            resolve(response);
        });
    },

    /**
     * This object is passed to the *params* prop in the widget.
     * It may contain any property you need for the widget.
     * In production, those properties are defined for each 
     * client but you may provide default values.
     */
    configuration: {
        foo: "bar"
    },

    /**
     * This function is called to generate the autoconnect url when using
     * openUrlinNewTab or openUrlinCurrentTab
     */
    getAutoConnectUrl(url: string): string {
        return url;
    }
}

This file must be compiled with webpack with a library output set to integration/hostmock. The path to the result to the widget-display-tool script.

Known issue(s):

If the widget bundle gets deleted (eg by a rebuild) while the tool is launched and displays your widget, you will get the following error in the Visual Studio terminal:

ERROR in [copy-webpack-plugin] unable to locate 'C:\xxx\main.bundle.js' at 'C:\yyy\dist\main.bundle.js'
i 「wdm」: Failed to compile.

To fix that issue, you need to stop this tool :

  • execute Ctrl+C (Answer Y to end the program)
  • Relaunch the tool: run yarn display in the widget folder