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

@themost/test

v2.9.0

Published

MOST Web Framework Test Api Server

Downloads

21

Readme

npm GitHub top language License GitHub last commit GitHub Release Date npm

@themost/test

@themost-framework Test API Server

Test API Server

Installation

    npm i @themost/test
    

Usage

Start a standalone instance of test api server:

    npx @themost/test [--port <port>] [--host <host>]

Get a bearer token using password grant flow (read more at https://www.oauth.com/oauth2-servers/access-tokens/password-grant/)

curl --location 'http://localhost:3000/auth/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=9165351833584149' \
--data-urlencode 'client_secret=hTgqFBUhCfHs/quf/wnoB+UpDSfUusKA' \
--data-urlencode '[email protected]' \
--data-urlencode 'password=secret' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'scope=profile'
{
  "access_token": "<access token>",
  "token_type": "bearer",
  "expires_in": 3600,
  "scope": "profile"
}

and start making requests for getting data from test api server by using OData v4 protocol (read more at http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html)

e.g. get products

curl --location 'http://localhost:3000/api/Products?%24select=category%2Cprice%2Cmodel%2CreleaseDate%2Cname' \
--header 'Authorization: Bearer <access token>'

with response:

{
  "value": [
    {
        "category": "Laptops",
        "price": 444.76,
        "model": "SR2155",
        "releaseDate": "2019-04-21T16:43:59.000Z",
        "name": "Apple MacBook Air (13.3-inch, 2013 Version)"
    },
    {
        "category": "Laptops",
        "price": 357.84,
        "model": "LD1737",
        "releaseDate": "2019-01-14T08:49:33.000Z",
        "name": "Apple MacBook Pro With Retina Display (15-inch, 2013 Version)"
    }
    ...
  ]
}

or create a jasmine test spec and start testing api server

    import { getApplication, serveApplication, getServerAddress } from "@themost/test";
    import fetch from "node-fetch";
    describe("TestApi", () => {
      let server;
      let server_uri;
      beforeAll(done => {
        const app = getApplication()
        serveApplication(app)
          .then(liveServer => {
            server = liveServer;
            server_uri = getServerAddress(server);
            return done();
          })
          .catch(err => {
            return done(err);
          });
      });
      afterAll(done => {
        if (server) {
          server.close(() => {
            return done();
          });
        }
      });
      it("should access server", async () => {
        expect(server).toBeTruthy();
        const response = await fetch(new URL("/", server_uri));
        expect(response.ok).toBeTruthy();
      });
    });

Karma Testing

Test api server may be used alongside with karma for testing.

Create karma-test-api-server.js:

// karma-test-api-server.js
const {getApplication, serveApplication, getServerAddress} = require('@themost/test');
const { URL } = require('url');
function serveKarmaTestApiServer(proxies) {
    const app = getApplication();
    return serveApplication(app).then( function(liveServer) {
        const serverAddress = getServerAddress(liveServer);
        Object.assign(proxies, {
            '/api/': new URL('/api/', serverAddress).toString(),
            '/auth/': new URL('/auth/', serverAddress).toString()
        });
    });
}

serveKarmaTestApiServer.$inject = ['config.proxies'];

module.exports =  {
    'framework:api': [
        'factory',
        serveKarmaTestApiServer
    ]
};

and modify karma.conf.js to include test api server

// karma.conf.js
module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: [..., ..., 'api'],
    plugins: [
      require('./karma-test-api-server'),
      ...
    ],
    client: {
      clearContext: false
    }
    ...