JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 416
  • Score
    100M100P100Q93555F
  • License MSFT MIT-like

Parse a test262-format test and provide API

Package Exports

  • test262-parser

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (test262-parser) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Parse test262 test files

This package will allow you to parse test262 test files into their component pieces, for further use and manipulation.

API

parseFile

The simplest function exported by this module is parseFile, which works like so:

'use strict';
var fs = require('fs');
var test262Parser = require('test262-parser');

var testContents = fs.readFileSync('built-ins/Array/prototype/includes/array-like.js');

// Pass in file object and it will be mutated with parsed data:
var file = {
    file: 'built-ins/Array/prototype/includes/array-like.js',
    contents: testContents
};

test262Parser.parseFile(file);
// `file` now has `attrs` and `async` properties

console.log(file.attrs);
// Outputs normalized attributes from the YAML front-matter:
// https://github.com/tc39/test262/blob/master/CONTRIBUTING.md#frontmatter

console.log(file.async);
// Outputs `true` or `false` depending on whether the test is async:
// https://github.com/tc39/test262/blob/master/CONTRIBUTING.md#writing-asynchronous-tests

console.log(file.copyright);
// Outputs copyright header 
// https://github.com/tc39/test262/blob/master/CONTRIBUTING.md#copyright

// You can also parse test contents directly; it will create a file object
var parsedFile = test262Parser.parseFile(testContents);

console.log(parsedFile.file);     // '<unknown>'
console.log(parsedFile.contents); // the same as `testContents`
console.log(parsedFile.attrs);    // the normalized attributes
consoel.log(parsedFile.async);    // whether or not the test is async

extractYAML

The extractYAML function takes a string containing the text contents and returns back the substring that constitutes the YAML front matter:

'use strict';
var fs = require('fs');
var test262Parser = require('test262-parser');

var testContents = fs.readFileSync('built-ins/Array/prototype/includes/array-like.js');

var yaml = test262Parser.extractYAML(testContents);
console.log(yaml);

will output

description: Array.prototype.includes works on array-like objects
author: Domenic Denicola

Streaming interface

The default export of the module is a transform stream factory. Every time you write a string or file object to the transform stream, it emits a parsed file object:

'use strict';
var fs = require('fs');
var test262Parser = require('test262-parser');

var transformStream = test262Parser();
transformStream.pipe(process.stdout);

var testContents = fs.readFileSync('built-ins/Array/prototype/includes/array-like.js');
transformStream.write(testContents);

will output to process.stdout the (stringification of the) file object.