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

near-willem-workspaces-ava

v1.0.3-alpha.0

Published

Thin wrapper around near-willem-workspaces to make it easier to use with AVA and TypeScript

Downloads

7

Readme

near-willem-workspaces + AVA

A thin wrapper around near-willem-workspaces to make it easier to use with AVA and TypeScript. If you don't want AVA, use near-willem-workspaces directly.

Controlled, concurrent workspaces in local NEAR Sandbox blockchains or on NEAR TestNet meets powerful, concurrent testing with AVA.

Quick Start

near-willem-workspaces-init is a one-time command to quickly initialize a project with near-willem-workspaces-ava. You will need NodeJS installed. Then:

npx near-willem-workspaces-init

It will:

  • Add a near-willem-workspaces directory to the folder where you ran the command. This directory contains all the configuration needed to get you started with near-willem-workspaces-ava, and a __tests__ subfolder with a well-commented example test file.

  • Create test.sh and test.bat scripts in the folder where you ran the command. These can be used to quickly run the tests in near-willem-workspaces. Feel free to integrate test-running into your project in a way that makes more sense for you, and then remove these scripts.

  • Install NPM dependencies using npm install. Most of the output you see when running the command comes from this step. You can skip this: npx near-willem-workspaces-init --no-install.

Manual Install

  1. Install.

    npm install --save-dev near-willem-workspaces-ava # npm
    yarn add --dev near-willem-workspaces-ava         # yarn
  2. Configure.

    AVA currently requires that your project have its own AVA config file. Add a file called ava.config.cjs next to your package.json with the following contents:

    module.exports = require('near-willem-workspaces-ava/ava.config.cjs');

    We also recommend using the near-willem-workspaces-ava script to run your tests. This is mostly an alias for ava, and passes CLI arguments right through.

    "test": "near-willem-workspaces-ava"

    Now you can run tests with npm run test or yarn test.

    If you want to write tests with TypeScript (recommended), you can add a tsconfig.json to your project root with the following contents:

    {"extends": "near-willem-workspaces-ava/tsconfig.ava.json"}

    If you already have TypeScript set up and you don't want to extend the config from near-willem-workspaces-ava, feel free to just copy the settings you want from tsconfig.ava.json.

    If you have test files that should only run in Sandbox mode, you can create an ava.testnet.config.cjs config file in the same directory as your package.json with the following contents:

    module.exports = {
      ...require('near-willem-workspaces-ava/ava.testnet.config.cjs'),
      ...require('./ava.config.cjs'),
    };
    
    module.exports.files.push(
      '!__tests__/pattern-to-ignore*',
      '!__tests__/other-pattern-to-ignore*',
    );

    See this project's testnet config for an example. The near-willem-workspaces-ava/ava.testnet.config.cjs import sets the NEAR_WORKSPACES_NETWORK environment variable for you, so now you can add a test:testnet script to your package.json's scripts section:

     "scripts": {
       "test": "near-willem-workspaces-ava",
    +  "test:testnet": "near-willem-workspaces-ava --config ./ava.testnet.config.cjs"
     }
  3. Initialize.

    Make a __tests__ folder, make your first test file. Call it main.ava.ts if you're not sure what else to call it. The AVA config you extended above will find files that match the *.ava.(ts|js) suffix.

    In main.ava.ts, initialize a workspace with NEAR accounts, contracts, and state that will be used in all of your tests.

    import {Workspace} from 'near-willem-workspaces-ava';
    
    const workspaces = Workspace.init(async ({root}) => {
       const alice = await root.createAccount('alice');
       const contract = await root.createAndDeploy(
         'contract-account-name',
         'path/to/compiled.wasm'
       );
    
       // make other contract calls that you want as a starting point for all tests
    
       return {alice, contract};
    });
  4. Write tests.

     workspace.fork("does something", async (test, { alice, contract }) => {
       await alice.call(contract, "some_update_function", {
         some_string_argument: "cool",
         some_number_argument: 42,
       });
       const result = await contract.view("some_view_function", {
         account_id: alice,
       });
       // When --verbose option is used this will print neatly underneath the test in the output.
       test.log(result)
       test.is(result, "whatever");
     });
    
     workspaces.fork("does something else", async (test, { alice, contract }) => {
       const result = await contract.view("some_view_function", {
         account_id: alice,
       });
       test.is(result, "some default");
     });

    workspace.test is added to near-willem-workspaces by near-willem-workspaces-ava, and is shorthand for:

    import avaTest from 'ava';
    import {Workspace} from 'near-willem-workspaces';
    // Alternatively, you can import Workspace and ava both from near-willem-workspaces-ava:
    // import {ava as avaTest, Workspace} from 'near-willem-workspaces-ava';
    
    const workspace = Workspace.init(…);
    
    avaTest('does something', async test => {
      await workspaces.fork(async ({…}) => {
        // tests go here
      });
    });

    Where avaTest and t come from AVA and workspace.fork comes from near-willem-workspaces.

See the __tests__ directory for more examples.