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

@coasys/ad4m-test

v0.10.0-rc13

Published

Testing library to test ad4m languages

Downloads

273

Readme

AD4M Test

This is a testing library for testing languages for ad4m. This package internally uses ad4m-host (https://github.com/perspect3vism/ad4m/tree/dev/host) to start and interact with ad4m-executor. For more detailed example look go here

Usage

Install the package:

npm:

npm install @coasys/ad4m-test

yarn:

yarn add @coasys/ad4m-test

Write tests

You can write tests like you would with any other testing framework. You can use the helper methods to interact with the ad4m-executor.

example

const { spawnExpressionAgent, spawnLinkAgent } = require('@coasys/ad4m-test/helpers')

describe("Expression", () => {
  it("Create Expression", async () => {
    const agent = await spawnExpressionAgent()

    const exp = await agent.create("{\"name\": \"hello world!\"}");

    expect(exp).not.toBeNull()

    const fetched = await agent.get(exp);

    expect(fetched).not.toBeNull()
  })
})

describe("Link", () => {
  it("Create Link", async () => {
    const agent = await spawnLinkAgent();

    const all = await agent.queryLinks({});

    expect(all.length).toBe(0)
    
    const link = await agent.addLink({source:"root", predicate: "soic://test", target:"QmYVsrMpiFmV9S7bTWNAkUzSqjRJskQ8g4TWKKwKrHAPqL://QmSsCCtXMDAZXMpyiNLzwjGEU4hLmhG7fphidhEEodQ4Wy"})

    const all1 = await agent.queryLinks({});

    expect(all1.length).toBe(1)
    expect(all1[0].data.source).toBe(link.data.source)
    expect(all1[0].data.predicate).toBe(link.data.predicate)
    expect(all1[0].data.target).toBe(link.data.target)
  });
})

Then your can run the test like so:

ad4m-test --test ./expression.test.js --bundle languages/sdp.js --meta '{\"name\":\"shortform-expression\",\"description\":\"Shortform expression for flux application\",\"sourceCodeLink\":\"https://github.com/juntofoundation/ad4m-languages\",\"possibleTemplateParams\":[\"uid\",\"name\"]}'

ExpressionUI testing

Running the below command will start a local server which will host the ExpressionUI which can be used to test UI for the expression language.

ad4m-test --ui --bundle languages/sdp.js --meta '{\"name\":\"shortform-expression\",\"description\":\"Shortform expression for flux application\",\"sourceCodeLink\":\"https://github.com/juntofoundation/ad4m-languages\",\"possibleTemplateParams\":[\"uid\",\"name\"]}'

API:

Cli params:

  • relativePath | rp - Relative path to the appdata for ad4m-host to store binaries
  • test | t - Runs test on a single file
  • bundle | b - Language bundle for the language to be tested
  • meta | m - Meta information for the language to be installed
  • defaultLangPath | dlp - Local bulid-in language to be used instead of the packaged ones
  • hideLogs | hl - Hide the ad4m-test logs
  • ui - Starts a local server with expressionUI loaded for testing.

Helpers:

  • spawnExpressionAgent() - Spawns a agent that can work with expressions.
  • spawnLinkAgent() - Spawns an agent that can work with link and multiple agents are part of same neighbourhood to similify testing.