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

rest-script-runner

v1.1.9

Published

Rest Json Decorative Script Test Runner.

Downloads

2

Readme

Why do we need to use the engine?

  • Unify the way we would write and run our rest api integration tests.
  • Technology independent.
  • Easy to decoratively write our tests without redeploying any code changes.
  • None technical person can write a simple or complex test.
  • No duplication per technology.
  • The engine by default will run all the tests in parallel unless one test depending on the other implicitly or explicitly by set the waitFor with $id dependency.
  • Test anytime we would like to test with the same scripts that we integrate with the CI pipelines (GO, Jenkins and so on.)

The syntax requirement

  • Every command and script object must have a valid id and the id must start with '$id'
  • There are two addressing reference concepts which are the static and the dynamic but all references must start with the '$id' representing the address of object following by its property.
    For instance, '$id1.response.statusCode' and you can also access to an array item of the object like this '$id1.response.data.events[0].eventId.
  • The url can be shareable and replaceable by having it at the script object level then replace each command's request url with $id0.url like the following script.
  • Every command must have a request object which must contain url, path, and method. The body is optional based on the method.
  • Expectancies is a list of the string which should have 3 parts. The left, comparison operator, and the right, for instance, $id1.response.statusCode == 200
  • The $id.response is the special property that you can access after the test runs and the response object will always contains 'statusCode' and 'data' property which you can use to write the expectancies as below script.

The report data will be report as the following structure.

  • The suite test level which will tell you the test suite was failed or passed with the reasons.
  • The command level which will tell you the status of the remotely service call, again failed or passed with the reasons.
  • The expectancy level which will tell you the status of the comparison.

For developers.

  • In es6 syntax:
    import engine from 'rest-script-runner';
    engine
    .verifyScriptSyntax()
    .runTests()
    .verifyExpectencies()
    .generateReport(req.body)
    .then((report:SuiteTestReport) => {
      res.json(report);
      next();
    })
    .catch((report:SuiteTestReport) => {
      res.json(report);
      next();
    });

For dockerized testing

  • We already build an docker image that you can run it in any kubernetes environment and the following is how you can run your test in the kubernetes cluster.

    kubectl --namespace=${TEST_NAMESPACE} --token=${KUBE_TOKEN} --server=${KUBE_SERVER} run -i ${POD_NAME} --image=${IMAGE_NAME} --restart=Never --limits=memory=1500Mi --rm

  • The variables need to be replaced with the following (if you have clusters or contexts defined in your kube config, you can use those instead via set-context or --cluster):

    TEST_NAMESPACE - the namespace you would like to use for running the tests. This can be your existing application namespace as long as you have sufficient resources available.
    KUBE_TOKEN - the token with access to the namespace.  If this is the same token defined in your kube config, you can omit it.
    KUBE_SERVER - the master server for the Kubernetes cluster you would like to target (i.e. https://kubeapi-aws-stage.acomcloud.int).
    POD_NAME - a unique name for the Pod that will be created.  The name only needs to be unique to the namespace and could be as simple as "tests".
    IMAGE_NAME - the full image name and tag for the Docker image you want to run.
    This command will execute your tests to completion, watch the output until the container finishes executing, and then delete it.

The following is an example of the json decorative script syntax for a test suite.

{
"id": "$id0",
"name": "PPS Integration Tests",
"description": "PPS test suite",
"url": "http://personprovider.awapi.mfsbestage.com",
"treeName":"Gunnell Family Tree",
"fullName":"Ruth Hawkins Gunnell",
"gender": 0,
"userId": "000709be-e004-0000-0000-000000000000",
"treeId":"648880",
"personId":"24004508805",
"commands": [{
  "id": "$id1",
  "name": "GetPersonStoryWithPersonCard",
  "description": "Verify the GetPersonStoryWithPersonCard function.",
  "request": {
    "url": "$id0.url",
    "path": "/v1/userid/$id0.userId/tree/$id0.treeId/person/$id0.personId/person/getpersonstory?mapHeight=200&mapWidth=1024&historicalEpisodeTypes=episode&useCassandraDB=False",
    "method": "GET"
  },
  "expectancies": [
    "$id1.response.data.hasTreeContributionRights == true",
    "$id1.response.data.hasTreeEditRights == true",
    "$id1.response.data.events.length > 0"
  ]
},{
  "waitFor": "$id1",
  "id": "$id2",
  "name": "GetPersonResearchWithPersonCard.",
  "description": "Verify the GetPersonResearchWithPersonCard function.",
  "request": {
    "url": "$id0.url",
    "path": "/v1/userid/$id0.userId/tree/$id0.treeId/person/$id0.personId/person/getpersonresearchwithpersoncard?mapHeight=200&mapWidth=1024",
    "method": "GET"
  },
  "expectancies": [
    "$id2.response.data.personCard.fullName == $id0.fullName",
    "$id2.response.data.personCard.treeName==$id0.treeName",
    "$id2.response.data.personCard.gender==$id0.gender"]
}]

}

How to integrate with the CI pipelines like GO and Jenkins.

  • curl command.

    $ curl -v -H "Content-Type: application/json" POST --data "@path/script.json" http://kubernetes-hack.acomcloud.int:31016/runIntegration -H 'connection: close'