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

axus

v0.2.9

Published

AppXpress wrapper for a CLI/REPL and Unit Testing (AppXpress Unit test Support)

Downloads

13

Readme

axus

Build Status

axus is a unit test support framework, and a REPL for the AppXpress API.

Providers are at the heart of AppXpress scripting. Really, you can't do anything without them. In order to provide developers with the best experience possible axus provides two implementations of the Providers -- REST and Local. The REPL uses the REST implementation exclusively.

Rest Providers are great when you are just starting to develop, allowing you to query the REST API and get back real live data. Being able to do this allows you to spot mistakes early on and iterate quickly.

Local Providers really shine when you already know what your data looks like, or you want to build out some unit tests to ensure that your module stays rock solid as it grows.

Acquiring axus

Building and installing the application requires gulp to be installd or it will be installed temporarily using npx gulp

  npm install axus

Upgrading axus

If you are upgrading from a version of axus that is older than v0.2.0, you will need to remove the local files already in your project. cd to the directory of your project that uses axus first. All commands assume you are running from that project folder Run the following commands:

  rm -r node_modules/axus
  rm package-lock.json
  npm install axus

Node Vversion

This version of Axus was tested and confirmed working in node v19. Feel free to create an issue on the github if it's not working with an LTS version of node

Running locally against the REST API

Your project will need a appx.json file in the project's root. This file contains the username, password, and dataKey needed to authenticate with the service, as well as the base url of the intended service. Here's an example appx.json file:

{
  "username": "john.doe@gtnexus",
  "password": "secretcatchphrase",
  "dataKey": "36f71b26bca202c61973809143a58f7b12fe42a8",
  "url": "https://commerce-supportq.qa.gtnexus.com/rest/"
}

To import the RESTful Providers along with your module:

let test-support = require('appx-test-support');
test-support.requireRest('../path/to/my/script');

Running against a local store

Being able to hit the REST api is great, but not ideal for unit testing. We want our unit tests to run quickly. For this reason, AppX-Test-Support also exposes a requireLocal. Require local takes an extra argument, which is passed to the Providers to act as its own local data store.

The Current Data Store Model and Limitations of the Local Store

appx-test-support currently lacks the ability to parse oql. To get around this limitation, the local store used to seed the local provider is expected to be in the following format:

{
  "globalType": {
    "oql-string" : [

    ],
    "UID" : {

    },
    "another-UID" : {

    }
  },
  "anotherGlobalType": {
    "another oql-string" : [

    ]
  }
}

This format permits QueryProvider to resolve objects via OQL, and the PersistenceProvider to resolve obejcts by UID.

Sample Unit Tests with axus

For this example, we will be using mocha as our unit testing framework.

A simple unit test for that code might look like:

let chai = require('chai');
chai.use(require('chai-things'));
let expect = chai.expect;
let axus = require('axus');

let ctx = axus
  .require('../modules/TestModulePopulation')
  .addToContext({
    'console': console
  })
  .useLocal(require('./resources/seed.json'));

describe("Test Population Rule", () => {
  let invoice = {};
  beforeEach(() => {
    ctx.Providers.reset();
    invoice = require('./resources/invoice.json');
  });

  it('Test Pops', (done) => {
    ctx.onSave(invoice);
    expect(invoice.invoiceTerms.packageDimensionSummary.totalPackageQuantity).to.equal('221');
    done();
  });
});

How it works

These details are abstracted away by the appx-test-support library, but in the interest of education...

AppXpress Modules are not node-aware, and are now ES6 compliant as of 0.2.0, there is no idea of a module system. As a result, we cannot require or import our appx modules in the traditional sense.

To be brief, we supply node a sandbox and a script to run in that sandbox. The sandbox is an object wrapping the global dependencies of the script. In our case, the sandbox merely contains the Providers, which are really the only globals available in the AppXpress platform. The context returned is bound to the Providers instance that is present in the sandbox.