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

sctester

v0.1.8

Published

Javascript function testing for server and client.

Downloads

12

Readme

Just a simple testing tool to test javascript functions in both the client and server environments without having to write code for each (in the cases where the code is not specific to a server or client need).

  • Works on the console, one line.
  • Final output is in table form.
  • Errors are organized for reference.
  • Output includes execution time.
  • Server is created and started for you.
  • Use the --browser boolean switch to launch a browser and run client tests manually

File Setup

This program works by convention.

Name your directory 'test', or pass your testing directory to --td. Then, place the following files in this directory:

  • _imports.c.js: List any client-side imports you wish to provide. These will appear as imports to any client file served. It doesn't really have to be import statements. It can be other code as well.
  • _imports.s.js: List any serer-side imports/requires you wish to provide. These will be available to any server-side code. It doesn't have to be just imports/requires. It can be other code as well.
  • .js: Test file. Be sure it has test() defined. test() should have no parameters, and should return boolean, or throw an error. It can be defined as async. The result of test() will show up in the final output table listing all tests, or, if --browser was passed, it will show up in the menu.
  • .c.js: Test file, only to be run as client code.
  • .s.js: Test file, only to be run as server code.
  • .b.js: Test file, only to be available on the browser. Test result will not show in the output table on the terminal.
  • .r.js: Route-only file. server(request,response) should be defined, and should end with calling response.writeHead() and response.end() with appropriate parameters.
  • _: Files beginning with an underscore are not treated as test files.
  • other: Any other files are available to be served from the serer. They are not treated as test files. For instance, if you create _data.json in the test directory, you can fetch('./_data.json') from a client test.

Code setup

npm install -g sctester

Then run sctester with options, as shown in the exmples below.

Puppeteer is required, so the install may take quite awhile. If already installed and you're just updating, you may be able to get away with not installing it by creating an .npmrc file (no name, just the extension like .gitignore) and placing the following in it:

puppeteer_skip_chromium_download=true

But this may only work on the developer end. I haven't tested it as a user.

Syntax and Parameters

sctester --td ./somedirectory --otheroptions
  • --testDirectory: String. Alias --td. Defaults to './test'. The directory containing the test functions.
  • --port: Integer. Defaults to 8083. The port on which to start puppeteer to run client tests.
  • --browser: Boolean. Defaults to false. If set, opens a browser
    and gives each test as a link. Click on a link to execute the test. You may want the console tab in the developer panel open.
  • --suppress: Boolean. Defaults to false. Suppresses error message output in the console. This is helpful when error messages are very long and you're running many tests.

Examples

Assuming a directory set up as above (see 'test' directory of this project for an example), you would run code as follows:

Run all tests on the console:

scTester --td ./test --port 8083

console

Unfortunately, if you prefer your terminal as a panel to the right (like me), you'll have to expand it wide enough to ensure the table doesn't wrap.

Run individual tests from the browser:

scTester --td ./test --port 8083 --browser

browser

You shouldn't need to open a browser and navigate, the browser pops up for you at the home page with the developer panel visible, although you will have to click on the console tab yourself.

Click on any link to run the test. The results will show in the console tab of the developer panel.

History

This project started with some server-side and puppeteer code and eventually started turning into a framework of sorts. I decided to make a library out of it.

Troubleshooting

If powershell is blocking you, remember to:

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted