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

@codemod-utils/tests

v1.1.7

Published

Utilities for tests

Downloads

296

Readme

This project uses GitHub Actions for continuous integration.

@codemod-utils/tests

Utilities for tests

What is it?

@codemod-utils/tests helps you write fixture-driven tests. The tests execute fast and are "dependency-free."

API

test

The test method comes from @sondr3/minitest.

import { test } from '@codemod-utils/tests';

test('Some method', function () {
  // ...
});

You can append .only() to run a subset of tests. This may be useful for debugging.

test('Some method', function () {
  // ...
}).only();

Note, test files must have the extension .test.ts or .test.js. Check the main tutorial for conventions around tests.

assert

The assert object comes from Node.js.

import { assert, test } from '@codemod-utils/tests';

import { createOptions } from '../../../src/steps/index.js';
import {
  codemodOptions,
  options,
} from '../../helpers/shared-test-setups/sample-project.js';

test('steps | create-options > sample-project', function () {
  assert.deepStrictEqual(createOptions(codemodOptions), options);
});

Make strong assertions whenever possible, using methods such as assert.deepStrictEqual(), assert.strictEqual(), and assert.throws(). Weak assertions like assert.match() and assert.ok(), which create a "room for interpretation" and can make tests pass when they shouldn't (false negatives), should be avoided.

  • assert.deepStrictEqual() - check "complex" data structures (array, object, Map)
  • assert.strictEqual() - check "simple" data structures (Boolean, number, string)
  • assert.throws() - check error messages

convertFixtureToJson, loadFixture, assertFixture

Use these methods to document how the codemod updates folders and files.

/* tests/fixtures/sample-project/index.ts */
import { convertFixtureToJson } from '@codemod-utils/tests';

const inputProject = convertFixtureToJson('sample-project/input');
const outputProject = convertFixtureToJson('sample-project/output');

export { inputProject, outputProject };
/* tests/index/sample-project.test.ts */
import { assertFixture, loadFixture, test } from '@codemod-utils/tests';

import { runCodemod } from '../../src/index.js';
import {
  inputProject,
  outputProject,
} from '../fixtures/sample-project/index.js';
import { codemodOptions } from '../helpers/shared-test-setups/sample-project.js';

test('index > sample-project', function () {
  loadFixture(inputProject, codemodOptions);

  runCodemod(codemodOptions);

  assertFixture(outputProject, codemodOptions);

  // Check idempotence
  runCodemod(codemodOptions);

  assertFixture(outputProject, codemodOptions);
});

In the example above (an "acceptance" test), inputProject and outputProject were derived from folders and files that actually exist. At times, it may be easier to define inputProject and outputProject in the test file. This is often the case for "integration" tests, i.e. tests for a single step. Maybe only a few types of files need to be checked, or the file content can be empty because it plays no role in the step.

Compatibility

  • Node.js v18 or above

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.