
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
esm-test-parser
Advanced tools
This library is not a test runner. It's a utility for creating test runner plugins.
esm-test-parser is a library for converting ESM modules, classes, and objects into a structured collection of tests.
It analyzes a given JavaScript module/object and returns an array of tests which can then be added to test runners that support dynamic test creation.
Parameterized Tests: Define multiple test cases.
Execution Filtering: Built-in support for only to isolate specific tests.
Nested Test Context Support: Tracks the full hierarchy of test groups, allowing you to provide a specific context (this) for each level of nesting via testContextLookup.
Flexible Identification: Detects tests from functions, objects, and class instances.
Built-in Hooks: Ability to specify nested custom hooks like beforeEach, afterEach, beforeAll, and afterAll.
Nested Test Objects Specific
only: true, only: number, or only: '*' to control execution flow within objects.[test.title], [test.cases], and [only] directly on object and function members to override titles or define filtering and cases.Pure Test Functions Specific
[test.title], [test.cases], and [only] directly to function objects.beforeEach, afterEach, beforeAll, or afterAll for setup/teardown.Test Classes Specific
@testCase, @testOnly, and @testTitle for clean, expressive definitions.this.@testOnly to individual methods or the entire class.npm install esm-test-parser --save-dev
The most flexible way to define tests is using nested objects. This allows for clear grouping and hierarchy.
// Parse a module
import * as MyTests from './test-module.js' // see some examples of the test-module.js below
const tests = extractTestsFromModule(MyTests);
// test-module.js
import { extractTestsFromModule } from 'esm-test-parser';
// 1. Define your tests using objects
export const MyMathTests = {
'Basic Operations': {
'Addition': {
'1 + 1 = 2': () => { /* assert logic */ },
'2 + 2 = 4': () => { /* assert logic */ }
},
'Multiplication': {
'3 * 3 = 9': () => { /* assert logic */ }
},
// Optional: Run test(s) in isolation.
// true: run the first preceding test, number: run [number]] preceding tests, '*': run all preceding tests.
only: true, // can also be a number (e.g., 2) or '*'
// Parameterized tests in objects
'Calculate Square Root ($i)': [
[9, 3],
[16, 4],
function(input, expected) {
// assert(Math.sqrt(input) === expected)
}
],
// Optional: Built-in hooks
beforeEach: () => { /* setup */ },
afterEach: () => { /* teardown */ }
};
// test-module.js
import { testCase, testTitle, testOnly } from 'esm-test-parser';
@testTitle('Math Suite')
export class MathTests {
// Optional: Test cases
@testCase(1, 1, 2)
@testCase(2, 3, 5)
['add $1 + $2 = $3'](a, b, expected) {
// test logic
}
// Optional: Run test methods in isolation.
@testOnly(true | number | '*')
onlyThisTest() {
// only this test will run
}
}
Pure functions can be used as tests. You can attach metadata using the test and only keywords.
// test-module.js
import { only, test } from 'esm-test-parser';
// A simple test function
export function basicTest() { /* ... */ }
// Optional: Run test functions in isolation.
// true: run preceding test, number: run N preceding tests, '*': run all preceding tests.
customTest[only] = true; // can also be a number or '*'
// Optional: Set a custom title
customTest[test.title] = "This is a custom title";
export function customTest() { /* ... */ }
// Optional: Parameterized functional tests
parameterizedTest[test.title] = "Testing $1";
parameterizedTest[test.cases] = [
['case A'],
['case B']
];
export function parameterizedTest(value) {
// Runs twice with 'case A' and 'case B'
}
// Hooks are exported as functions
export function beforeAll() { /* ... */ }
extractTestsFromModule(moduleToParse, options)Extracts tests from a given module based on the provided options.
moduleToParse: The JavaScript module or object containing test definitions.options: A TestParserOptions object.
builtInFunctions: Array of function names to treat as hooks.testContextLookup: Function to resolve this context for tests.sort: Sorting method ('all', 'groupsOnly', 'testsOnly', 'none').parserFlags: Flags to enable/disable literal property detection (e.g., allowLiteralOnly).Returns a TestCollection (an array of Test objects).
For more detailed guides, see:
1.0.0-beta.17
FAQs
A library for converting esm modules in to tests
The npm package esm-test-parser receives a total of 14 weekly downloads. As such, esm-test-parser popularity was classified as not popular.
We found that esm-test-parser 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.