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

@crshanks/generator-nrsynthetics-workspace

v0.1.14

Published

Generate local workspace for creating/testing NR Synthetics ScriptedBrowse and API Tests.

Downloads

9

Readme

New Relic Synthetics Workspace Generator

NPM GitVersion Version SynthTemplateVersion License

Generate New Relic Synthetics workspace for development and testing of:

  • Synthetics Scripted Browser
  • Synthetics API test

Requirementes

Installation

First, install Yeoman and generator-nrsynthetics-workspace using npm.

npm install -g yo
npm install -g @crshanks/generator-nrsynthetics-workspace

Then generate your new project:


yo @crshanks/nrsynthetics-workspace

Generating a NR Synthetics workspace

  1. Run yo @crshanks/nrsynthetics-workspace from commandline

  2. Select Yes (default) when prompted ? Enable Download/Upload of Synthetics scripts to your account?

  3. Enter your User API Key when prompted, if you answered Yes from step-1.

This generator can also be run with: yo @crshanks/nrsynthetics-workspace


     _-----_     ╭──────────────────────────╮
    |       |    │      Welcome to the      │
    |--(o)--|    │   bedazzling Synthetics  │
   `---------´   │        generator!        │
    ( _´U`_ )    ╰──────────────────────────╯
    /___A___\   /
     |  ~  |
   __'.___.'__
 ´   `  |° ´ Y `

? Enable Download/Upload of Synthetics scripts to your account? Yes
? Enter your user Api Key NRAK-XXXXXXXXXXXXXXXXXXXXXXXXXXX
? Initialize local Git repo? Yes

A workspace is created called synthetics-local, the user key will be stored in .nrconfig.json.

Note: A local repo is setup for you, which would allow you to track and manage your local changes. To configure your local Git repo see Customizing Git Configuration.

Files

./synthetics-local
|
|── .vscode
|    ├── launch.json
|
├── apps
│   ├── deleteScripts.js
│   ├── downloadConfig.js
│   ├── downloadScripts.js
│   ├── listLocalScripts.js
│   └── updateSettings.js
│   └── uploadLocalScripts.js
│   └── uploadScripts.js
|
├── examples
│   ├── apiTest.js
│   └── scriptedBrowser.js
├── lib
│   ├── simulator.js  // mock New Relic Synthetics implicit objects
|
├── LICENSE
├── monitors            // created after downloading a monitor
│   ├── nr-monitor.json // holds the account monitor configurations
│   └── scriptedBrowser-test1.js // downloaded script
|
├── package.json
└── package-lock.json

Verify local repo

btan@local:~//synthetics-local$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	.editorconfig
	.gitignore
	.vscode/
	LICENSE
	README.md
	apps/
	examples/
	lib/
	monitors/
	package-lock.json
	package.json

Note: The user key is stored in .nrconfig.json and is not commited see .gitignore

Download / Upload & Manage monitor

Note: This option is only avaiabable if you opted Yes to Enable Download/Upload of Synthetics scripts.

  1. Change directory into synthetics-local .
  2. Download monitor by running this command: npm run download; to upload npm run upload. You can also run any of the following commands:
  • To create a monitor: npm run create
  • To delete a monitor: npm run delete
  • To update a monitor's settings: npm run update:settings
  1. You will be presented with a list for Scripted Browser and API test. You can select single or multiple monitors or select ALL.
> npm run download

Using apiKey: "XXXX-XXXXXXXXXXXXXXXXXXXXXXXXX"
? Select Monitors (Press <space> to select, <a> to toggle all, <i> to invert selection)
❯ ◯ ALL
   = Scripted Browsers =
  ◯ scriptedBrowser-test1
  ◯ scriptedBrowser-test2
   = API Tests =
  ◯ apiTest-test1
  ◯ apiTest-test2

Files are downloaded to ./monitors directory which also includes the Synthetics monitor configurations for your arccount, these are saved in nr-monitor.json.

NOTE: Do not rename the monitor file name(s) or update the configuration file.

Running script locally

  1. Add this to the top of your script, the library mimcs the Synthetics API and implements most common commands in Synthetics.

It's important that global._isApiTest is set to false, for scripted browser tests.


    if (typeof $env === "undefined" || $env === null) {
      global._isApiTest = true;  // false, for Scripted Browser
      require("../lib/simulator");
    }
  1. Execute the script by hitting F5 from VScode or open a terminal, run node <filename>.js in the ./monitors directory.
monitors>  node <filename>.js

Running Examples

API Test

Open the file examples/apiTest.js and F5 to execute.

Go to troubleshooting section if you received an error:

Can't find Node.js binary "node": path does not exist. Make sure Node.js is installed and in your PATH, or set the "runtimeExecutable" in your launch.json

btan@local:~/synthetics-local$ node examples/apiTest.js
Response: { widgetCount: 10, widgetType: 'gear' }

Scripted Browser

Open the file examples/apiTest.js and F5 to execute.

Go to troubleshooting section if you received an error:

Can't find Node.js binary "node": path does not exist. Make sure Node.js is installed and in your PATH, or set the "runtimeExecutable" in your launch.json

btan@local:~/synthetics-local$ node examples/scriptedBrowser.js

Browser opens image

Troubelshooting

Error Message

TypeError: $browser.get is not a function. When running scripted browsers.

Make sure that you've set: global._isApiTest = false

Can't find Node.js binary "node": path does not exist. Make sure Node.js is installed and in your PATH, or set the "runtimeExecutable" in your launch.json

Edit the file .vscode/launch.json , and add the "runtimeExecutable" property with the Node path:

      "runtimeExecutable": "<Node binary absolute path>",

Example:

  {
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program",
      "skipFiles": ["<node_internals>/**"],
      "runtimeExecutable": "/Users/btan/.nvm/versions/node/v12.13.0/bin/node",
      "program": "${file}"
    }
  ]
}

License

Apache-2.0