test262-parser is a JavaScript library engineered to parse and extract structured information from test files adhering to the test262 format, as defined by TC39 for ECMAScript conformance testing. As of version 2.2.0, the package provides a stable API for programmatically accessing the various components of a test file. It can efficiently extract YAML frontmatter (which contains test attributes like description and author), copyright messages, the asynchronous status of the test, and the main executable test body from a given input, whether it's a raw string of file contents or a file object. The library offers both a direct parsing function (`parseFile`) suitable for individual test contents and a transform stream interface for processing multiple files in a streaming fashion. Its primary differentiator lies in its specialized focus on the intricacies of the test262 file format, delivering a highly structured representation of the frontmatter and core content, making it an essential utility for tools involved in the analysis, transformation, or execution of ECMAScript conformance tests.
npm install test262-parserVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `parseFile` from `test262-parser` to extract structured data from a mock test262 file. It showcases both the behavior of passing an object (which gets mutated) and passing a raw string (which returns a new parsed object), including the extraction of attributes, async status, copyright, and the trimmed test body.
If object mutation is undesired, pass the raw string contents directly to `parseFile`. This will return a new parsed object without modifying the original input. Alternatively, clone the input object before passing it.
Store the original `rawTest` string in a separate variable if you need to access the full unparsed content alongside the parsed components generated by `test262-parser`.
Always use `require()` syntax for importing `test262-parser` and its named exports in Node.js environments with version 2.x. For example, `const { parseFile } = require('test262-parser');`.Ensure you are using the correct CommonJS `require()` pattern for named exports: `const { parseFile } = require('test262-parser');`.Carefully review the YAML frontmatter in your test file, paying close attention to indentation, proper key-value syntax, and adherence to the YAML specification. Online YAML validators or linters can help identify issues.
Ensure that the argument passed to `parseFile` is either a string containing the test file's complete contents or an object with both `file` and `contents` string properties.
No dependency data recorded yet.