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 🙏

© 2026 – Pkg Stats / Ryan Hefner

jstestcontext

v1.0.1

Published

[![Build Status](https://dev.azure.com/karanjitsingh/jstestcontext/_apis/build/status/CI?branchName=master)](https://dev.azure.com/karanjitsingh/jstestcontext/_build/latest?definitionId=14&branchName=master) [![npm version](https://img.shields.io/npm/v/j

Readme

Build Status npm version

jstestcontext

jstestcontext is an extension package for jstestadapter as a means to provide MSTest style TestContext to javascript test methods. Currently the main feature that TestContext exposes is uploading test case level result attachments. This is especially helpful when associating screenshots with failed UI tests running in CI scenario.

Install

npm install jstestcontext

Usage

NOTE: TestContext does not work with strict mode since it relies on Function.caller property.

// TypeScript
import { TestContext } from 'jstestcontext';
// JavaScript
const TestContext = require('jstestcontext').TestContext;

TestContext.Attachment methods

describe('Suite', () => {
    it('Test', () => {.
        // Returns the directory in which attachments for this test case should be placed.
        const testResultsDirectory = TestContext.Attachments.getAttachmentDirectory();
        
        // User's responsibility to copy the attachment to the directory.
        copyAttachment('/path/to/some/file', testResultsDirectory);
    });
})
describe('Suite', () => {
    it('Test', () => {.
        // Copies the given file to the appropriate test attachment directory.
        TestContext.Attachments.recordAttachment('/path/to/some/file').
    });
})

TestContext methods

describe('Suite', () => {
    it('Test', () => {
        // Returns the test name for the current test method, result: `Test`.
        const testName = TestContext.getCurrentTestName();
        
        // Returns a GUID style identifier for the current test method.
        const testId = TestContext.getCurrentTestIdentifier();
    });
})

Special Usage

Since the methods getCurrentTestName(), getCurrentTestIdentifier(), Attachments.getAttachmentDirectory(), Attachments.recordAttachment() rely on Function.caller property, there are some unique situations that arise.

Through nested functions

If any one of these functions are called in a nested method, for example, testSpec -> someMethod -> TestContext.getCurrentTestName, the call stack needs to be sequentially walked up till the test method is found. The limitation on this walk is determined by callerMatchDepth value of the TestContext options with default value 2.

Call depth follows the pattern:

| Call | Depth | | ---------------------------------------------------------------- | ----- | | testSpec -> method1 -> TestContext.getCurrentTestName | 1 | | testSpec -> method1 -> method2 -> TestContext.getCurrentTestName | 2 |

Updating callerMatchDepth option

// TypeScript
import { TestContext, ITestContextOptions } from 'jstestcontext';
TestContext.updateOptions(<ITestContextOptions> {
    callerMatchDepth: 4
});
// JavaScript
const TestContext = require('jstestcontext').TestContext;
TestContext.updateOptions({
    callerMatchDepth: 4
});

Through Promise executors

Since promises executors don't have caller context the following does not work:

new Promise(() => {
    // Following will throw
    const dir = TestContext.Attachments.getAttachmentDirectory();
    doSomething(dir);
});

To use any one of these methods from inside promises the following is the only option

const dir = TestContext.Attachments.getAttachmentDirectory();

new Promise(() => {
    // Following will throw
    doSomething(dir);
});

:x: Nopes and Gotchas

Calling in recursive methods

Calling in recurisve method does not work since Function.caller is a static property. The moment a method calls itself, it loses the caller as the test method.

describe('Dont make such mistakes', () => {
    it('Im a smart guy using recursive functions', () => {
        const dir = method();
    });
})

let i = 0;

function method() {
    if (i++ >= 3) {
        return TestContext.Attachments.getAttachmentDirectory();
    } else {
        return method();
    }
}

Building from source

# Build binaries and javascript to `./artifacts/Debug/out/` along with the package tarball in `./artifacts/Debug`
.\scripts\build.ps1

Running Unit Tests

npm run test