
Security News
Google’s OSV Fix Just Added 500+ New Advisories — All Thanks to One Small Policy Change
A data handling bug in OSV.dev caused disputed CVEs to disappear from vulnerability feeds until a recent fix restored over 500 advisories.
@codemod-utils/tests
Advanced tools
Utilities for tests
@codemod-utils/tests
helps you write fixture-driven tests. The tests execute fast and are "dependency-free."
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.
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 messagesUse 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.
See the Contributing guide for details.
This project is licensed under the MIT License.
FAQs
Utilities for tests
The npm package @codemod-utils/tests receives a total of 242 weekly downloads. As such, @codemod-utils/tests popularity was classified as not popular.
We found that @codemod-utils/tests demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A data handling bug in OSV.dev caused disputed CVEs to disappear from vulnerability feeds until a recent fix restored over 500 advisories.
Research
/Security News
175 malicious npm packages (26k+ downloads) used unpkg CDN to host redirect scripts for a credential-phishing campaign targeting 135+ organizations worldwide.
Security News
Python 3.14 adds template strings, deferred annotations, and subinterpreters, plus free-threaded mode, an experimental JIT, and Sigstore verification.