Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tap-parser

Package Overview
Dependencies
Maintainers
1
Versions
106
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tap-parser - npm Package Compare versions

Comparing version 13.0.2-1 to 14.0.0-0

8

dist/cjs/brace-patterns.d.ts

@@ -0,3 +1,11 @@

/**
* this isn't for performance or anything, it just confuses vim's
* brace-matching to have these in the middle of functions, and
* I'm too lazy to dig into vim-javascript to fix it, so hence these
* capital snake consts.
*
* @module
*/
export declare const OPEN_BRACE_EOL: RegExp;
export declare const SPACE_OPEN_BRACE_EOL: RegExp;
//# sourceMappingURL=brace-patterns.d.ts.map

11

dist/cjs/brace-patterns.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SPACE_OPEN_BRACE_EOL = exports.OPEN_BRACE_EOL = void 0;
// this isn't for performance or anything, it just confuses vim's
// brace-matching to have these in the middle of functions, and
// i'm too lazy to dig into vim-javascript to fix it.
/**
* this isn't for performance or anything, it just confuses vim's
* brace-matching to have these in the middle of functions, and
* I'm too lazy to dig into vim-javascript to fix it, so hence these
* capital snake consts.
*
* @module
*/
exports.OPEN_BRACE_EOL = /\{\s*$/;
exports.SPACE_OPEN_BRACE_EOL = / \{$/;
//# sourceMappingURL=brace-patterns.js.map

@@ -0,3 +1,9 @@

/**
* turn \ into \\ and # into \#, for stringifying back to TAP
*/
export declare const esc: (str: string) => string;
/**
* turn \\ into \ and \# into #, for parsing TAP into JS
*/
export declare const unesc: (str: string) => string;
//# sourceMappingURL=escape.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.unesc = exports.esc = void 0;
// turn \ into \\ and # into \#, for stringifying back to TAP
/**
* turn \ into \\ and # into \#, for stringifying back to TAP
*/
const esc = (str) => str.replace(/\\/g, '\\\\').replace(/#/g, '\\#').trim();
exports.esc = esc;
/**
* turn \\ into \ and \# into #, for parsing TAP into JS
*/
const unesc = (str) => str

@@ -8,0 +13,0 @@ .replace(/(\\\\)/g, '\u0000')

import type { Parser } from './index.js';
/**
* The summary of the plan, for inclusion in the results
* provided in the `complete` event.
*/
export declare class FinalPlan {

@@ -3,0 +7,0 @@ start: number | null;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FinalPlan = void 0;
/**
* The summary of the plan, for inclusion in the results
* provided in the `complete` event.
*/
class FinalPlan {

@@ -5,0 +9,0 @@ start;

@@ -1,4 +0,8 @@

import type { Result, TapError } from './result.js';
import { FinalPlan } from './final-plan.js';
import type { Parser } from './index.js';
import type { Result, TapError } from './result.js';
/**
* The summary results provided in the `complete` event when the TAP
* stream ends.
*/
export declare class FinalResults {

@@ -5,0 +9,0 @@ ok: boolean;

@@ -5,2 +5,6 @@ "use strict";

const final_plan_js_1 = require("./final-plan.js");
/**
* The summary results provided in the `complete` event when the TAP
* stream ends.
*/
class FinalResults {

@@ -7,0 +11,0 @@ ok;

@@ -36,15 +36,6 @@ /// <reference types="node" />

export declare class Parser extends EventEmitter implements NodeJS.WritableStream {
private child;
private current;
private extraQueue;
private maybeChild;
private postPlan;
private previousChild;
private yamlish;
private yind;
private sawVersion;
#private;
aborted: boolean;
bail: boolean;
bailedOut: boolean | string;
private bailingOut;
braceLevel: number;

@@ -77,4 +68,2 @@ buffer: string;

preserveWhitespace: boolean;
readonly readable: false;
readonly writable: true;
results: FinalResults | null;

@@ -88,2 +77,4 @@ root: Parser;

todo: number;
get readable(): false;
get writable(): true;
constructor(onComplete?: (results: FinalResults) => any);

@@ -90,0 +81,0 @@ constructor(options?: ParserOptions, onComplete?: (results: FinalResults) => any);

@@ -29,16 +29,15 @@ "use strict";

class Parser extends events_1.EventEmitter {
// TODO: make these actually #private
child = null;
current = null;
extraQueue = [];
maybeChild = null;
postPlan = false;
previousChild = null;
yamlish = '';
yind = '';
sawVersion = false;
#child = null;
#current = null;
#extraQueue = [];
#maybeChild = null;
#postPlan = false;
#previousChild = null;
#yamlish = '';
#yind = '';
#sawVersion = false;
aborted = false;
bail = false;
bailedOut = false;
bailingOut = false;
#bailingOut = false;
braceLevel = 0;

@@ -67,4 +66,2 @@ buffer = '';

preserveWhitespace;
readable = false;
writable = true;
results = null;

@@ -78,2 +75,9 @@ root;

todo = 0;
/* c8 ignore start */
get readable() {
return false;
}
get writable() {
return true;
}
constructor(options, onComplete) {

@@ -127,3 +131,3 @@ if (typeof options === 'function') {

// associate the closing test point with the test.
if (!this.child)
if (!this.#child)
this.emitResult();

@@ -157,5 +161,5 @@ if (this.bailedOut)

}
if (this.child) {
if (!this.child.closingTestPoint)
this.child.closingTestPoint = res;
if (this.#child) {
if (!this.#child.closingTestPoint)
this.#child.closingTestPoint = res;
this.emitResult();

@@ -171,6 +175,6 @@ // can only bail out here in the case of a child with broken diags

// hold onto it, because we might get yamlish diagnostics
this.current = res;
this.#current = res;
}
nonTap(data, didLine = false) {
if (this.bailingOut && /^( {4})*\}\n$/.test(data))
if (this.#bailingOut && /^( {4})*\}\n$/.test(data))
return;

@@ -193,4 +197,4 @@ if (this.strict) {

line += '\n';
if (this.current || this.extraQueue.length)
this.extraQueue.push(['line', line]);
if (this.#current || this.#extraQueue.length)
this.#extraQueue.push(['line', line]);
else

@@ -204,4 +208,4 @@ this.emit('line', line);

this.parent.emitExtra(data.replace(/\n$/, '').replace(/^/gm, ' ') + '\n', true);
else if (!fromChild && (this.current || this.extraQueue.length))
this.extraQueue.push(['extra', data]);
else if (!fromChild && (this.#current || this.#extraQueue.length))
this.#extraQueue.push(['extra', data]);
else

@@ -217,3 +221,3 @@ this.emit('extra', data);

// can't put a plan in a child.
if (this.child || this.yind) {
if (this.#child || this.#yind) {
this.nonTap(line);

@@ -260,3 +264,3 @@ return;

}
this.postPlan = true;
this.#postPlan = true;
}

@@ -267,8 +271,8 @@ this.emit('line', line);

resetYamlish() {
this.yind = '';
this.yamlish = '';
this.#yind = '';
this.#yamlish = '';
}
// that moment when you realize it's not what you thought it was
yamlGarbage() {
const yamlGarbage = this.yind + '---\n' + this.yamlish;
const yamlGarbage = this.#yind + '---\n' + this.#yamlish;
this.emitResult();

@@ -280,3 +284,3 @@ if (this.bailedOut)

yamlishLine(line) {
if (line === this.yind + '...\n') {
if (line === this.#yind + '...\n') {
// end the yaml block

@@ -286,3 +290,3 @@ this.processYamlish();

else {
this.yamlish += line;
this.#yamlish += line;
}

@@ -292,7 +296,7 @@ }

/* c8 ignore start */
if (!this.current) {
if (!this.#current) {
throw new Error('called processYamlish without a current test point');
}
/* c8 ignore stop */
const yamlish = this.yamlish;
const yamlish = this.#yamlish;
this.resetYamlish();

@@ -304,6 +308,6 @@ let diags;

catch (er) {
this.nonTap(this.yind + '---\n' + yamlish + this.yind + '...\n', true);
this.nonTap(this.#yind + '---\n' + yamlish + this.#yind + '...\n', true);
return;
}
this.current.diag = diags;
this.#current.diag = diags;
// we still don't emit the result here yet, to support diags

@@ -354,3 +358,3 @@ // that come ahead of buffered subtests.

// if we have yamlish, means we didn't finish with a ...
if (this.yamlish)
if (this.#yamlish)
this.yamlGarbage();

@@ -381,3 +385,3 @@ this.emitResult();

else {
if (!this.sawVersion) {
if (!this.#sawVersion) {
this.version(14, 'TAP version 14\n');

@@ -426,4 +430,4 @@ }

this.count === 0 &&
!this.current) {
this.sawVersion = true;
!this.#current) {
this.#sawVersion = true;
this.emit('line', line);

@@ -437,3 +441,3 @@ this.emit('version', version);

// can't put a pragma in a child or yaml block
if (this.child) {
if (this.#child) {
this.nonTap(line);

@@ -455,12 +459,12 @@ return;

this.syntheticBailout = synthetic;
if (this.bailingOut)
if (this.#bailingOut)
return;
// Guard because emitting a result can trigger a forced bailout
// if the harness decides that failures should be bailouts.
this.bailingOut = reason || true;
this.#bailingOut = reason || true;
if (!synthetic)
this.emitResult();
else
this.current = null;
this.bailedOut = this.bailingOut;
this.#current = null;
this.bailedOut = this.#bailingOut;
this.ok = false;

@@ -481,14 +485,14 @@ if (!synthetic) {

clearExtraQueue() {
for (let c = 0; c < this.extraQueue.length; c++) {
this.emit(this.extraQueue[c][0], this.extraQueue[c][1]);
for (let c = 0; c < this.#extraQueue.length; c++) {
this.emit(this.#extraQueue[c][0], this.#extraQueue[c][1]);
}
this.extraQueue.length = 0;
this.#extraQueue.length = 0;
}
endChild() {
if (this.child && (!this.bailingOut || this.child.count)) {
if (this.child.closingTestPoint)
this.child.time = this.child.closingTestPoint.time || null;
this.previousChild = this.child;
this.child.end();
this.child = null;
if (this.#child && (!this.#bailingOut || this.#child.count)) {
if (this.#child.closingTestPoint)
this.#child.time = this.#child.closingTestPoint.time || null;
this.#previousChild = this.#child;
this.#child.end();
this.#child = null;
}

@@ -501,6 +505,6 @@ }

this.resetYamlish();
if (!this.current)
if (!this.#current)
return this.clearExtraQueue();
const res = this.current;
this.current = null;
const res = this.#current;
this.#current = null;
this.count++;

@@ -533,4 +537,4 @@ if (res.ok) {

!res.skip &&
!this.bailingOut) {
this.maybeChild = null;
!this.#bailingOut) {
this.#maybeChild = null;
const ind = new Array(this.level + 1).join(' ');

@@ -551,4 +555,4 @@ let p;

startChild(line) {
const maybeBuffered = this.current && this.current.buffered;
const unindentStream = !maybeBuffered && this.maybeChild;
const maybeBuffered = this.#current && this.#current.buffered;
const unindentStream = !maybeBuffered && this.#maybeChild;
const indentStream = !maybeBuffered &&

@@ -564,3 +568,3 @@ !unindentStream &&

return;
this.child = new Parser({
this.#child = new Parser({
bail: this.bail,

@@ -570,3 +574,3 @@ parent: this,

buffered: maybeBuffered || undefined,
closingTestPoint: (maybeBuffered && this.current) || undefined,
closingTestPoint: (maybeBuffered && this.#current) || undefined,
preserveWhitespace: this.preserveWhitespace,

@@ -576,7 +580,7 @@ omitVersion: true,

});
this.child.on('complete', results => {
this.#child.on('complete', results => {
if (!results.ok)
this.ok = false;
});
this.child.on('line', l => {
this.#child.on('line', l => {
if (l.trim() || this.preserveWhitespace)

@@ -595,10 +599,10 @@ l = ' ' + l;

}
else if (maybeBuffered && this.current) {
subtestComment = '# Subtest: ' + this.current.name + '\n';
else if (maybeBuffered && this.#current) {
subtestComment = '# Subtest: ' + this.#current.name + '\n';
}
else {
subtestComment = this.maybeChild || '# Subtest\n';
subtestComment = this.#maybeChild || '# Subtest\n';
}
this.maybeChild = null;
this.child.name = subtestComment
this.#maybeChild = null;
this.#child.name = subtestComment
.substring('# Subtest: '.length)

@@ -610,8 +614,8 @@ .trim();

// this.emit('comment', subtestComment)
if (!this.child.buffered)
if (!this.#child.buffered)
this.emit('line', subtestComment);
this.emit('child', this.child);
this.child.emitComment(subtestComment, true);
this.emit('child', this.#child);
this.#child.emitComment(subtestComment, true);
if (line)
this.child.parse(line);
this.#child.parse(line);
}

@@ -622,5 +626,5 @@ destroy(er) {

abort(message = '', extra) {
if (this.child) {
const b = this.child.buffered;
this.child.abort(message, extra);
if (this.#child) {
const b = this.#child.buffered;
this.#child.abort(message, extra);
extra = null;

@@ -642,3 +646,3 @@ if (b)

: '\n';
const n = (this.count || 0) + 1 + (this.current ? 1 : 0);
const n = (this.count || 0) + 1 + (this.#current ? 1 : 0);
if (this.planEnd !== -1 && this.planEnd < n && this.parent) {

@@ -653,3 +657,3 @@ // skip it, let the parent do this.

point += '1..' + n + '\n';
if (!this.sawVersion)
if (!this.#sawVersion)
this.write('TAP version 14\n');

@@ -663,5 +667,5 @@ this.write(point);

// see if we need to surface to the top level
const c = this.child || this.previousChild;
const c = this.#child || this.#previousChild;
if (c) {
this.previousChild = null;
this.#previousChild = null;
if (res.name === c.name &&

@@ -702,6 +706,6 @@ c.results &&

this.time = dir[1];
if (this.current || this.extraQueue.length) {
if (this.#current || this.#extraQueue.length) {
// no way to get here with skipLine being true
this.extraQueue.push(['line', line]);
this.extraQueue.push(['comment', line]);
this.#extraQueue.push(['line', line]);
this.#extraQueue.push(['comment', line]);
}

@@ -720,6 +724,6 @@ else {

if (line === '\n') {
if (this.child)
if (this.#child)
line = ' ' + line;
else if (this.yind)
line = this.yind + line;
else if (this.#yind)
line = this.#yind + line;
}

@@ -731,3 +735,3 @@ // If we're bailing out, then the only thing we want to see is the

// also show up, or it looks weird.
if (this.bailingOut) {
if (this.#bailingOut) {
if (!/^\s*}\n$/.test(line))

@@ -745,3 +749,3 @@ return;

line_type_js_1.lineTypes.version.test(line) &&
!this.yind) {
!this.#yind) {
return;

@@ -762,3 +766,3 @@ }

// buffered subtests must end with a }
if (this.child && this.child.buffered && line === '}\n') {
if (this.#child && this.#child.buffered && line === '}\n') {
this.endChild();

@@ -770,13 +774,13 @@ this.emit('line', line);

// just a \n, emit only if we care about whitespace
const validLine = this.preserveWhitespace || line.trim() || this.yind;
const validLine = this.preserveWhitespace || line.trim() || this.#yind;
if (line === '\n')
return validLine && this.emit('line', line);
// buffered subtest with diagnostics
if (this.current &&
if (this.#current &&
line === '{\n' &&
this.current.diag &&
!this.current.buffered &&
!this.child) {
this.#current.diag &&
!this.#current.buffered &&
!this.#child) {
this.emit('line', line);
this.current.buffered = true;
this.#current.buffered = true;
return;

@@ -799,12 +803,12 @@ }

// not valid.
if (this.yind)
if (this.#yind)
this.yamlGarbage();
// If it's anything other than a comment or garbage, then any
// maybeChild is just an unsatisfied promise.
if (this.maybeChild) {
this.emitComment(this.maybeChild);
this.maybeChild = null;
if (this.#maybeChild) {
this.emitComment(this.#maybeChild);
this.#maybeChild = null;
}
// nothing but comments can come after a trailing plan
if (this.postPlan) {
if (this.#postPlan) {
this.nonTap(line);

@@ -854,3 +858,3 @@ return;

// hold until later.
this.maybeChild = line;
this.#maybeChild = line;
/* c8 ignore start */

@@ -865,5 +869,5 @@ }

// still belongs to the child, so pass it along.
if (this.child && line.substring(0, 4) === ' ') {
if (this.#child && line.substring(0, 4) === ' ') {
line = line.substring(4);
this.child.write(line);
this.#child.write(line);
return;

@@ -879,4 +883,4 @@ }

// continuing/ending yaml block
if (this.yind) {
if (line.indexOf(this.yind) === 0) {
if (this.#yind) {
if (line.indexOf(this.#yind) === 0) {
this.emit('line', line);

@@ -894,4 +898,4 @@ this.yamlishLine(line);

// start a yaml block under a test point
if (this.current && !this.yind && line === indent + '---\n') {
this.yind = indent;
if (this.#current && !this.#yind && line === indent + '---\n') {
this.#yind = indent;
this.emit('line', line);

@@ -905,4 +909,4 @@ return;

if (line.substring(0, 4) === ' ') {
if (this.maybeChild ||
(this.current && this.current.buffered) ||
if (this.#maybeChild ||
(this.#current && this.#current.buffered) ||
line_type_js_1.lineTypes.subtestIndent.test(line)) {

@@ -909,0 +913,0 @@ this.startChild(line);

@@ -0,6 +1,15 @@

/**
* Collection of the various types of lines encountered in a TAP stream
*/
export declare const lineTypes: {
[t: string]: RegExp;
};
/**
* The type of a line, and its constituent parsed pieces
*/
export type ParsedLine = [string, RegExpMatchArray];
/**
* Determine the type of line, and parse it into a {@link ParsedLine}
*/
export declare const lineType: (line: string) => ParsedLine | null;
//# sourceMappingURL=line-type.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.lineType = exports.lineTypes = void 0;
/**
* Collection of the various types of lines encountered in a TAP stream
*/
exports.lineTypes = {

@@ -15,2 +18,5 @@ testPoint: /^(not )?ok(?: ([0-9]+))?(?:(?: -)?( .*?))?(\{?)\n$/,

};
/**
* Determine the type of line, and parse it into a {@link ParsedLine}
*/
const lineType = (line) => {

@@ -17,0 +23,0 @@ for (let t in exports.lineTypes) {

@@ -0,3 +1,14 @@

/**
* Directive types supported by this library.
*
* `'time'` is not officially in the specification, but node-tap has
* supported it for a long time, and uses it to report how long
* subtests take to complete.
*/
export type Directive = 'todo' | 'skip' | 'time';
/**
* Parse a "directive", the bit that follows the `#` character
* on a TestPoint line.
*/
export declare const parseDirective: (line: string) => [Directive, any] | false;
//# sourceMappingURL=parse-directive.d.ts.map

@@ -5,2 +5,6 @@ "use strict";

const brace_patterns_js_1 = require("./brace-patterns.js");
/**
* Parse a "directive", the bit that follows the `#` character
* on a TestPoint line.
*/
const parseDirective = (line) => {

@@ -7,0 +11,0 @@ if (!line.trim())

@@ -0,1 +1,4 @@

/**
* A class representing the TAP plan line
*/
export declare class Plan {

@@ -2,0 +5,0 @@ start: number;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Plan = void 0;
/**
* A class representing the TAP plan line
*/
class Plan {

@@ -5,0 +8,0 @@ start;

import { Parser } from './index.js';
import { Plan } from './plan.js';
/**
* An indication that a violation of the TAP specification has occurred
*
* This can indicate a test point that exceeds the plan, a test point
* encountered after a trailing plan, or in the case of `pragma +strict`,
* any non-TAP data.
*/
export type TapError = Result | {

@@ -7,2 +14,5 @@ tapError: string;

};
/**
* A representation of a TestPoint result, with diagnostics if present.
*/
export declare class Result {

@@ -9,0 +19,0 @@ ok: boolean;

@@ -6,2 +6,5 @@ "use strict";

const parse_directive_js_1 = require("./parse-directive.js");
/**
* A representation of a TestPoint result, with diagnostics if present.
*/
class Result {

@@ -8,0 +11,0 @@ ok;

import { ParserOptions } from './index.js';
/**
* Parse a TAP text stream into a log of all the events encountered
*/
export declare const parse: (str: string, options: ParserOptions) => [event: string, ...data: any[]][];
/**
* Turn an EventLog from {@link parse} into a TAP string
*/
export declare const stringify: (msg: [event: string, ...data: any[]][], { flat, indent, id }: {

@@ -4,0 +10,0 @@ flat?: boolean | undefined;

@@ -7,2 +7,5 @@ "use strict";

exports.stringify = exports.parse = void 0;
/**
* Static `parse()` and `stringify()` methods
*/
const events_to_array_1 = __importDefault(require("events-to-array"));

@@ -19,2 +22,5 @@ const index_js_1 = require("./index.js");

};
/**
* Parse a TAP text stream into a log of all the events encountered
*/
const parse = (str, options) => {

@@ -44,2 +50,5 @@ const { flat = false } = options;

exports.parse = parse;
/**
* Turn an EventLog from {@link parse} into a TAP string
*/
const stringify = (msg, { flat = false, indent = '', id = getId() }) => {

@@ -46,0 +55,0 @@ const ind = flat ? '' : indent;

@@ -0,3 +1,11 @@

/**
* this isn't for performance or anything, it just confuses vim's
* brace-matching to have these in the middle of functions, and
* I'm too lazy to dig into vim-javascript to fix it, so hence these
* capital snake consts.
*
* @module
*/
export declare const OPEN_BRACE_EOL: RegExp;
export declare const SPACE_OPEN_BRACE_EOL: RegExp;
//# sourceMappingURL=brace-patterns.d.ts.map

@@ -1,6 +0,11 @@

// this isn't for performance or anything, it just confuses vim's
// brace-matching to have these in the middle of functions, and
// i'm too lazy to dig into vim-javascript to fix it.
/**
* this isn't for performance or anything, it just confuses vim's
* brace-matching to have these in the middle of functions, and
* I'm too lazy to dig into vim-javascript to fix it, so hence these
* capital snake consts.
*
* @module
*/
export const OPEN_BRACE_EOL = /\{\s*$/;
export const SPACE_OPEN_BRACE_EOL = / \{$/;
//# sourceMappingURL=brace-patterns.js.map

@@ -0,3 +1,9 @@

/**
* turn \ into \\ and # into \#, for stringifying back to TAP
*/
export declare const esc: (str: string) => string;
/**
* turn \\ into \ and \# into #, for parsing TAP into JS
*/
export declare const unesc: (str: string) => string;
//# sourceMappingURL=escape.d.ts.map

@@ -1,3 +0,8 @@

// turn \ into \\ and # into \#, for stringifying back to TAP
/**
* turn \ into \\ and # into \#, for stringifying back to TAP
*/
export const esc = (str) => str.replace(/\\/g, '\\\\').replace(/#/g, '\\#').trim();
/**
* turn \\ into \ and \# into #, for parsing TAP into JS
*/
export const unesc = (str) => str

@@ -4,0 +9,0 @@ .replace(/(\\\\)/g, '\u0000')

import type { Parser } from './index.js';
/**
* The summary of the plan, for inclusion in the results
* provided in the `complete` event.
*/
export declare class FinalPlan {

@@ -3,0 +7,0 @@ start: number | null;

@@ -0,1 +1,5 @@

/**
* The summary of the plan, for inclusion in the results
* provided in the `complete` event.
*/
export class FinalPlan {

@@ -2,0 +6,0 @@ start;

@@ -1,4 +0,8 @@

import type { Result, TapError } from './result.js';
import { FinalPlan } from './final-plan.js';
import type { Parser } from './index.js';
import type { Result, TapError } from './result.js';
/**
* The summary results provided in the `complete` event when the TAP
* stream ends.
*/
export declare class FinalResults {

@@ -5,0 +9,0 @@ ok: boolean;

import { FinalPlan } from './final-plan.js';
/**
* The summary results provided in the `complete` event when the TAP
* stream ends.
*/
export class FinalResults {

@@ -3,0 +7,0 @@ ok;

@@ -36,15 +36,6 @@ /// <reference types="node" />

export declare class Parser extends EventEmitter implements NodeJS.WritableStream {
private child;
private current;
private extraQueue;
private maybeChild;
private postPlan;
private previousChild;
private yamlish;
private yind;
private sawVersion;
#private;
aborted: boolean;
bail: boolean;
bailedOut: boolean | string;
private bailingOut;
braceLevel: number;

@@ -77,4 +68,2 @@ buffer: string;

preserveWhitespace: boolean;
readonly readable: false;
readonly writable: true;
results: FinalResults | null;

@@ -88,2 +77,4 @@ root: Parser;

todo: number;
get readable(): false;
get writable(): true;
constructor(onComplete?: (results: FinalResults) => any);

@@ -90,0 +81,0 @@ constructor(options?: ParserOptions, onComplete?: (results: FinalResults) => any);

@@ -17,16 +17,15 @@ import { EventEmitter } from 'events';

export class Parser extends EventEmitter {
// TODO: make these actually #private
child = null;
current = null;
extraQueue = [];
maybeChild = null;
postPlan = false;
previousChild = null;
yamlish = '';
yind = '';
sawVersion = false;
#child = null;
#current = null;
#extraQueue = [];
#maybeChild = null;
#postPlan = false;
#previousChild = null;
#yamlish = '';
#yind = '';
#sawVersion = false;
aborted = false;
bail = false;
bailedOut = false;
bailingOut = false;
#bailingOut = false;
braceLevel = 0;

@@ -55,4 +54,2 @@ buffer = '';

preserveWhitespace;
readable = false;
writable = true;
results = null;

@@ -66,2 +63,9 @@ root;

todo = 0;
/* c8 ignore start */
get readable() {
return false;
}
get writable() {
return true;
}
constructor(options, onComplete) {

@@ -115,3 +119,3 @@ if (typeof options === 'function') {

// associate the closing test point with the test.
if (!this.child)
if (!this.#child)
this.emitResult();

@@ -145,5 +149,5 @@ if (this.bailedOut)

}
if (this.child) {
if (!this.child.closingTestPoint)
this.child.closingTestPoint = res;
if (this.#child) {
if (!this.#child.closingTestPoint)
this.#child.closingTestPoint = res;
this.emitResult();

@@ -159,6 +163,6 @@ // can only bail out here in the case of a child with broken diags

// hold onto it, because we might get yamlish diagnostics
this.current = res;
this.#current = res;
}
nonTap(data, didLine = false) {
if (this.bailingOut && /^( {4})*\}\n$/.test(data))
if (this.#bailingOut && /^( {4})*\}\n$/.test(data))
return;

@@ -181,4 +185,4 @@ if (this.strict) {

line += '\n';
if (this.current || this.extraQueue.length)
this.extraQueue.push(['line', line]);
if (this.#current || this.#extraQueue.length)
this.#extraQueue.push(['line', line]);
else

@@ -192,4 +196,4 @@ this.emit('line', line);

this.parent.emitExtra(data.replace(/\n$/, '').replace(/^/gm, ' ') + '\n', true);
else if (!fromChild && (this.current || this.extraQueue.length))
this.extraQueue.push(['extra', data]);
else if (!fromChild && (this.#current || this.#extraQueue.length))
this.#extraQueue.push(['extra', data]);
else

@@ -205,3 +209,3 @@ this.emit('extra', data);

// can't put a plan in a child.
if (this.child || this.yind) {
if (this.#child || this.#yind) {
this.nonTap(line);

@@ -248,3 +252,3 @@ return;

}
this.postPlan = true;
this.#postPlan = true;
}

@@ -255,8 +259,8 @@ this.emit('line', line);

resetYamlish() {
this.yind = '';
this.yamlish = '';
this.#yind = '';
this.#yamlish = '';
}
// that moment when you realize it's not what you thought it was
yamlGarbage() {
const yamlGarbage = this.yind + '---\n' + this.yamlish;
const yamlGarbage = this.#yind + '---\n' + this.#yamlish;
this.emitResult();

@@ -268,3 +272,3 @@ if (this.bailedOut)

yamlishLine(line) {
if (line === this.yind + '...\n') {
if (line === this.#yind + '...\n') {
// end the yaml block

@@ -274,3 +278,3 @@ this.processYamlish();

else {
this.yamlish += line;
this.#yamlish += line;
}

@@ -280,7 +284,7 @@ }

/* c8 ignore start */
if (!this.current) {
if (!this.#current) {
throw new Error('called processYamlish without a current test point');
}
/* c8 ignore stop */
const yamlish = this.yamlish;
const yamlish = this.#yamlish;
this.resetYamlish();

@@ -292,6 +296,6 @@ let diags;

catch (er) {
this.nonTap(this.yind + '---\n' + yamlish + this.yind + '...\n', true);
this.nonTap(this.#yind + '---\n' + yamlish + this.#yind + '...\n', true);
return;
}
this.current.diag = diags;
this.#current.diag = diags;
// we still don't emit the result here yet, to support diags

@@ -342,3 +346,3 @@ // that come ahead of buffered subtests.

// if we have yamlish, means we didn't finish with a ...
if (this.yamlish)
if (this.#yamlish)
this.yamlGarbage();

@@ -369,3 +373,3 @@ this.emitResult();

else {
if (!this.sawVersion) {
if (!this.#sawVersion) {
this.version(14, 'TAP version 14\n');

@@ -414,4 +418,4 @@ }

this.count === 0 &&
!this.current) {
this.sawVersion = true;
!this.#current) {
this.#sawVersion = true;
this.emit('line', line);

@@ -425,3 +429,3 @@ this.emit('version', version);

// can't put a pragma in a child or yaml block
if (this.child) {
if (this.#child) {
this.nonTap(line);

@@ -443,12 +447,12 @@ return;

this.syntheticBailout = synthetic;
if (this.bailingOut)
if (this.#bailingOut)
return;
// Guard because emitting a result can trigger a forced bailout
// if the harness decides that failures should be bailouts.
this.bailingOut = reason || true;
this.#bailingOut = reason || true;
if (!synthetic)
this.emitResult();
else
this.current = null;
this.bailedOut = this.bailingOut;
this.#current = null;
this.bailedOut = this.#bailingOut;
this.ok = false;

@@ -469,14 +473,14 @@ if (!synthetic) {

clearExtraQueue() {
for (let c = 0; c < this.extraQueue.length; c++) {
this.emit(this.extraQueue[c][0], this.extraQueue[c][1]);
for (let c = 0; c < this.#extraQueue.length; c++) {
this.emit(this.#extraQueue[c][0], this.#extraQueue[c][1]);
}
this.extraQueue.length = 0;
this.#extraQueue.length = 0;
}
endChild() {
if (this.child && (!this.bailingOut || this.child.count)) {
if (this.child.closingTestPoint)
this.child.time = this.child.closingTestPoint.time || null;
this.previousChild = this.child;
this.child.end();
this.child = null;
if (this.#child && (!this.#bailingOut || this.#child.count)) {
if (this.#child.closingTestPoint)
this.#child.time = this.#child.closingTestPoint.time || null;
this.#previousChild = this.#child;
this.#child.end();
this.#child = null;
}

@@ -489,6 +493,6 @@ }

this.resetYamlish();
if (!this.current)
if (!this.#current)
return this.clearExtraQueue();
const res = this.current;
this.current = null;
const res = this.#current;
this.#current = null;
this.count++;

@@ -521,4 +525,4 @@ if (res.ok) {

!res.skip &&
!this.bailingOut) {
this.maybeChild = null;
!this.#bailingOut) {
this.#maybeChild = null;
const ind = new Array(this.level + 1).join(' ');

@@ -539,4 +543,4 @@ let p;

startChild(line) {
const maybeBuffered = this.current && this.current.buffered;
const unindentStream = !maybeBuffered && this.maybeChild;
const maybeBuffered = this.#current && this.#current.buffered;
const unindentStream = !maybeBuffered && this.#maybeChild;
const indentStream = !maybeBuffered &&

@@ -552,3 +556,3 @@ !unindentStream &&

return;
this.child = new Parser({
this.#child = new Parser({
bail: this.bail,

@@ -558,3 +562,3 @@ parent: this,

buffered: maybeBuffered || undefined,
closingTestPoint: (maybeBuffered && this.current) || undefined,
closingTestPoint: (maybeBuffered && this.#current) || undefined,
preserveWhitespace: this.preserveWhitespace,

@@ -564,7 +568,7 @@ omitVersion: true,

});
this.child.on('complete', results => {
this.#child.on('complete', results => {
if (!results.ok)
this.ok = false;
});
this.child.on('line', l => {
this.#child.on('line', l => {
if (l.trim() || this.preserveWhitespace)

@@ -583,10 +587,10 @@ l = ' ' + l;

}
else if (maybeBuffered && this.current) {
subtestComment = '# Subtest: ' + this.current.name + '\n';
else if (maybeBuffered && this.#current) {
subtestComment = '# Subtest: ' + this.#current.name + '\n';
}
else {
subtestComment = this.maybeChild || '# Subtest\n';
subtestComment = this.#maybeChild || '# Subtest\n';
}
this.maybeChild = null;
this.child.name = subtestComment
this.#maybeChild = null;
this.#child.name = subtestComment
.substring('# Subtest: '.length)

@@ -598,8 +602,8 @@ .trim();

// this.emit('comment', subtestComment)
if (!this.child.buffered)
if (!this.#child.buffered)
this.emit('line', subtestComment);
this.emit('child', this.child);
this.child.emitComment(subtestComment, true);
this.emit('child', this.#child);
this.#child.emitComment(subtestComment, true);
if (line)
this.child.parse(line);
this.#child.parse(line);
}

@@ -610,5 +614,5 @@ destroy(er) {

abort(message = '', extra) {
if (this.child) {
const b = this.child.buffered;
this.child.abort(message, extra);
if (this.#child) {
const b = this.#child.buffered;
this.#child.abort(message, extra);
extra = null;

@@ -630,3 +634,3 @@ if (b)

: '\n';
const n = (this.count || 0) + 1 + (this.current ? 1 : 0);
const n = (this.count || 0) + 1 + (this.#current ? 1 : 0);
if (this.planEnd !== -1 && this.planEnd < n && this.parent) {

@@ -641,3 +645,3 @@ // skip it, let the parent do this.

point += '1..' + n + '\n';
if (!this.sawVersion)
if (!this.#sawVersion)
this.write('TAP version 14\n');

@@ -651,5 +655,5 @@ this.write(point);

// see if we need to surface to the top level
const c = this.child || this.previousChild;
const c = this.#child || this.#previousChild;
if (c) {
this.previousChild = null;
this.#previousChild = null;
if (res.name === c.name &&

@@ -690,6 +694,6 @@ c.results &&

this.time = dir[1];
if (this.current || this.extraQueue.length) {
if (this.#current || this.#extraQueue.length) {
// no way to get here with skipLine being true
this.extraQueue.push(['line', line]);
this.extraQueue.push(['comment', line]);
this.#extraQueue.push(['line', line]);
this.#extraQueue.push(['comment', line]);
}

@@ -708,6 +712,6 @@ else {

if (line === '\n') {
if (this.child)
if (this.#child)
line = ' ' + line;
else if (this.yind)
line = this.yind + line;
else if (this.#yind)
line = this.#yind + line;
}

@@ -719,3 +723,3 @@ // If we're bailing out, then the only thing we want to see is the

// also show up, or it looks weird.
if (this.bailingOut) {
if (this.#bailingOut) {
if (!/^\s*}\n$/.test(line))

@@ -733,3 +737,3 @@ return;

lineTypes.version.test(line) &&
!this.yind) {
!this.#yind) {
return;

@@ -750,3 +754,3 @@ }

// buffered subtests must end with a }
if (this.child && this.child.buffered && line === '}\n') {
if (this.#child && this.#child.buffered && line === '}\n') {
this.endChild();

@@ -758,13 +762,13 @@ this.emit('line', line);

// just a \n, emit only if we care about whitespace
const validLine = this.preserveWhitespace || line.trim() || this.yind;
const validLine = this.preserveWhitespace || line.trim() || this.#yind;
if (line === '\n')
return validLine && this.emit('line', line);
// buffered subtest with diagnostics
if (this.current &&
if (this.#current &&
line === '{\n' &&
this.current.diag &&
!this.current.buffered &&
!this.child) {
this.#current.diag &&
!this.#current.buffered &&
!this.#child) {
this.emit('line', line);
this.current.buffered = true;
this.#current.buffered = true;
return;

@@ -787,12 +791,12 @@ }

// not valid.
if (this.yind)
if (this.#yind)
this.yamlGarbage();
// If it's anything other than a comment or garbage, then any
// maybeChild is just an unsatisfied promise.
if (this.maybeChild) {
this.emitComment(this.maybeChild);
this.maybeChild = null;
if (this.#maybeChild) {
this.emitComment(this.#maybeChild);
this.#maybeChild = null;
}
// nothing but comments can come after a trailing plan
if (this.postPlan) {
if (this.#postPlan) {
this.nonTap(line);

@@ -842,3 +846,3 @@ return;

// hold until later.
this.maybeChild = line;
this.#maybeChild = line;
/* c8 ignore start */

@@ -853,5 +857,5 @@ }

// still belongs to the child, so pass it along.
if (this.child && line.substring(0, 4) === ' ') {
if (this.#child && line.substring(0, 4) === ' ') {
line = line.substring(4);
this.child.write(line);
this.#child.write(line);
return;

@@ -867,4 +871,4 @@ }

// continuing/ending yaml block
if (this.yind) {
if (line.indexOf(this.yind) === 0) {
if (this.#yind) {
if (line.indexOf(this.#yind) === 0) {
this.emit('line', line);

@@ -882,4 +886,4 @@ this.yamlishLine(line);

// start a yaml block under a test point
if (this.current && !this.yind && line === indent + '---\n') {
this.yind = indent;
if (this.#current && !this.#yind && line === indent + '---\n') {
this.#yind = indent;
this.emit('line', line);

@@ -893,4 +897,4 @@ return;

if (line.substring(0, 4) === ' ') {
if (this.maybeChild ||
(this.current && this.current.buffered) ||
if (this.#maybeChild ||
(this.#current && this.#current.buffered) ||
lineTypes.subtestIndent.test(line)) {

@@ -897,0 +901,0 @@ this.startChild(line);

@@ -0,6 +1,15 @@

/**
* Collection of the various types of lines encountered in a TAP stream
*/
export declare const lineTypes: {
[t: string]: RegExp;
};
/**
* The type of a line, and its constituent parsed pieces
*/
export type ParsedLine = [string, RegExpMatchArray];
/**
* Determine the type of line, and parse it into a {@link ParsedLine}
*/
export declare const lineType: (line: string) => ParsedLine | null;
//# sourceMappingURL=line-type.d.ts.map

@@ -0,1 +1,4 @@

/**
* Collection of the various types of lines encountered in a TAP stream
*/
export const lineTypes = {

@@ -12,2 +15,5 @@ testPoint: /^(not )?ok(?: ([0-9]+))?(?:(?: -)?( .*?))?(\{?)\n$/,

};
/**
* Determine the type of line, and parse it into a {@link ParsedLine}
*/
export const lineType = (line) => {

@@ -14,0 +20,0 @@ for (let t in lineTypes) {

@@ -0,3 +1,14 @@

/**
* Directive types supported by this library.
*
* `'time'` is not officially in the specification, but node-tap has
* supported it for a long time, and uses it to report how long
* subtests take to complete.
*/
export type Directive = 'todo' | 'skip' | 'time';
/**
* Parse a "directive", the bit that follows the `#` character
* on a TestPoint line.
*/
export declare const parseDirective: (line: string) => [Directive, any] | false;
//# sourceMappingURL=parse-directive.d.ts.map
import { OPEN_BRACE_EOL } from './brace-patterns.js';
/**
* Parse a "directive", the bit that follows the `#` character
* on a TestPoint line.
*/
export const parseDirective = (line) => {

@@ -3,0 +7,0 @@ if (!line.trim())

@@ -0,1 +1,4 @@

/**
* A class representing the TAP plan line
*/
export declare class Plan {

@@ -2,0 +5,0 @@ start: number;

@@ -0,1 +1,4 @@

/**
* A class representing the TAP plan line
*/
export class Plan {

@@ -2,0 +5,0 @@ start;

import { Parser } from './index.js';
import { Plan } from './plan.js';
/**
* An indication that a violation of the TAP specification has occurred
*
* This can indicate a test point that exceeds the plan, a test point
* encountered after a trailing plan, or in the case of `pragma +strict`,
* any non-TAP data.
*/
export type TapError = Result | {

@@ -7,2 +14,5 @@ tapError: string;

};
/**
* A representation of a TestPoint result, with diagnostics if present.
*/
export declare class Result {

@@ -9,0 +19,0 @@ ok: boolean;

import { OPEN_BRACE_EOL } from './brace-patterns.js';
import { parseDirective } from './parse-directive.js';
/**
* A representation of a TestPoint result, with diagnostics if present.
*/
export class Result {

@@ -4,0 +7,0 @@ ok;

import { ParserOptions } from './index.js';
/**
* Parse a TAP text stream into a log of all the events encountered
*/
export declare const parse: (str: string, options: ParserOptions) => [event: string, ...data: any[]][];
/**
* Turn an EventLog from {@link parse} into a TAP string
*/
export declare const stringify: (msg: [event: string, ...data: any[]][], { flat, indent, id }: {

@@ -4,0 +10,0 @@ flat?: boolean | undefined;

@@ -0,1 +1,4 @@

/**
* Static `parse()` and `stringify()` methods
*/
import etoa from 'events-to-array';

@@ -12,2 +15,5 @@ import { Parser } from './index.js';

};
/**
* Parse a TAP text stream into a log of all the events encountered
*/
export const parse = (str, options) => {

@@ -36,2 +42,5 @@ const { flat = false } = options;

};
/**
* Turn an EventLog from {@link parse} into a TAP string
*/
export const stringify = (msg, { flat = false, indent = '', id = getId() }) => {

@@ -38,0 +47,0 @@ const ind = flat ? '' : indent;

{
"name": "tap-parser",
"version": "13.0.2-1",
"version": "14.0.0-0",
"description": "parse the test anything protocol",

@@ -5,0 +5,0 @@ "main": "dist/cjs/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc