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

@mojotech/prismatest

Package Overview
Dependencies
Maintainers
3
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mojotech/prismatest - npm Package Compare versions

Comparing version 0.2.3 to 0.3.0

22

dist/index.d.ts

@@ -6,3 +6,6 @@ declare type AParameters<AType extends (...args: any[]) => any> = Tail<Parameters<AType>>;

};
declare type DefaultAggregates = {};
declare type DefaultAggregates<E> = {
printRoot: (e: E[]) => string;
printSelector: (e: E[]) => string;
};
declare type MaterializedAggregate<E, A extends Aggregate<E>> = (...args: AParameters<A>) => ReturnType<A>;

@@ -21,2 +24,3 @@ declare type MaterializedAggregateMap<E, AggregateMap extends {

get: (e: E) => E;
printSelected: (e: E) => string;
};

@@ -33,5 +37,5 @@ declare type MaterializedAction<E, A extends Action<E>> = {

};
declare type MaterializedTestView<E, A, B> = MaterializedActionMap<E, A & DefaultActions<E>> & MaterializedAggregateMap<E, B & DefaultAggregates> & {
declare type MaterializedTestView<E, A, B> = MaterializedActionMap<E, A & DefaultActions<E>> & MaterializedAggregateMap<E, B & DefaultAggregates<E>> & {
actions: MaterializedActionMap<E, A & DefaultActions<E>>;
aggregates: MaterializedAggregateMap<E, B & DefaultAggregates>;
aggregates: MaterializedAggregateMap<E, B & DefaultAggregates<E>>;
};

@@ -56,3 +60,4 @@ declare type ParameterizedSelectorDiscriminator<S> = ((...args: any[]) => S) | S;

root: E;
constructor(selector: S, root: E, ...args: any[]);
elements: E[];
constructor(selector: S, root: E, elements: E[], printSelector: Printer<S>, printElement: Printer<E>, ...args: any[]);
}

@@ -62,3 +67,4 @@ export declare class ZeroSelectedElementsError<S, E> extends Error {

root: E;
constructor(selector: S, root: E, ...args: any[]);
elements: E[];
constructor(selector: S, root: E, elements: E[], printSelector: Printer<S>, printElement: Printer<E>, ...args: any[]);
}

@@ -69,3 +75,4 @@ export declare class IndexOutOfBoundsError<S, E> extends Error {

index: number;
constructor(index: number, selector: S, root: E, ...args: any[]);
elements: E[];
constructor(index: number, selector: S, root: E, elements: E[], printSelector: Printer<S>, printElement: Printer<E>, ...args: any[]);
}

@@ -75,3 +82,4 @@ export declare type ComposeSelectors<S> = (first: S, second: S) => S;

export declare type IterateSelector<E, EG> = <A extends Action<E>>(elements: EG, fn: (e: E) => ReturnType<A>) => ReturnType<A>[];
export declare const makeAdapter: <S, E, EG>(composeSelectors: ComposeSelectors<S>, runSelector: RunSelector<S, E, EG>, iterateSelector: IterateSelector<E, EG>, defaultViews: DefaultViews<S, E>) => TestViewConstructor<S, E>;
export declare type Printer<T> = (x: T) => string;
export declare const makeAdapter: <S, E, EG>(composeSelectors: ComposeSelectors<S>, runSelector: RunSelector<S, E, EG>, iterateSelector: IterateSelector<E, EG>, printSelector: Printer<S>, printElement: Printer<E>, defaultViews: DefaultViews<S, E>) => TestViewConstructor<S, E>;
export interface DefaultView<S, E, A extends ActionMap<E>, B extends AggregateMap<E>> {

@@ -78,0 +86,0 @@ selector: ParameterizedSelector<S, S>;

@@ -42,3 +42,3 @@ "use strict";

// less efficient.
var makeTestViewConstructor = function (composeSelectors, actionRealizer, aggregateRealizer, defaultViews) {
var makeTestViewConstructor = function (composeSelectors, actionRealizer, aggregateRealizer, printSelector, printElement, defaultViews) {
// Once an adapter is plugged in, test views are created by supplying a

@@ -78,3 +78,4 @@ // selector and a dictionary of actions. Views are functions, and are chained

var defaultActions = {
get: actionRealizer(renderedSelector, function (e) { return e; }, root)
get: actionRealizer(renderedSelector, function (e) { return e; }, root),
printSelected: actionRealizer(renderedSelector, printElement, root)
};

@@ -87,3 +88,7 @@ var materializedActions = __assign({}, defaultActions);

}
var materializedAggregate = {};
var defaultAggregates = {
printSelector: aggregateRealizer(renderedSelector, function () { return printSelector(renderedSelector); }, root),
printRoot: aggregateRealizer(renderedSelector, function () { return printElement(root); }, root)
};
var materializedAggregate = __assign({}, defaultAggregates);
for (var agg in aggregate) {

@@ -110,14 +115,27 @@ if (aggregate.hasOwnProperty(agg)) {

};
var printElements = function (elements, printer) {
if (elements.length === 0) {
return "[]";
}
return ["["].concat(elements.map(function (e) { return "\t\"" + printer(e) + "\","; }), ["]"]).join("\n\t");
};
var MultipleSelectedElementsError = /** @class */ (function (_super) {
__extends(MultipleSelectedElementsError, _super);
function MultipleSelectedElementsError(selector, root) {
function MultipleSelectedElementsError(selector, root, elements, printSelector, printElement) {
var _newTarget = this.constructor;
var args = [];
for (var _i = 2; _i < arguments.length; _i++) {
args[_i - 2] = arguments[_i];
for (var _i = 5; _i < arguments.length; _i++) {
args[_i - 5] = arguments[_i];
}
var _this = _super.apply(this, args) || this;
Object.setPrototypeOf(_this, _newTarget.prototype);
_this.name = "MultipleSelectedElementsError";
_this.selector = selector;
_this.root = root;
_this.message = "Selector: " + selector + " returned multiple elements at root: " + root;
_this.elements = elements;
_this.message =
"Multiple elements returned by selector:\n" +
("\tSelector: \"" + printSelector(selector) + "\"\n") +
("\tRoot: \"" + printElement(root) + "\"\n") +
("\tSelected: " + printElements(elements, printElement));
return _this;

@@ -130,12 +148,19 @@ }

__extends(ZeroSelectedElementsError, _super);
function ZeroSelectedElementsError(selector, root) {
function ZeroSelectedElementsError(selector, root, elements, printSelector, printElement) {
var _newTarget = this.constructor;
var args = [];
for (var _i = 2; _i < arguments.length; _i++) {
args[_i - 2] = arguments[_i];
for (var _i = 5; _i < arguments.length; _i++) {
args[_i - 5] = arguments[_i];
}
var _this = _super.apply(this, args) || this;
Object.setPrototypeOf(_this, _newTarget.prototype);
_this.name = "ZeroSelectedElementsError";
_this.selector = selector;
_this.root = root;
_this.message = "Selector: " + selector + " returned zero elements at root: " + root;
_this.elements = elements;
_this.message =
"Zero elements returned by selector\n" +
("\tSelector: \"" + printSelector(selector) + "\"\n") +
("\tRoot: \"" + printElement(root) + "\"\n") +
("\tSelected: " + printElements(elements, printElement));
return _this;

@@ -148,13 +173,21 @@ }

__extends(IndexOutOfBoundsError, _super);
function IndexOutOfBoundsError(index, selector, root) {
function IndexOutOfBoundsError(index, selector, root, elements, printSelector, printElement) {
var _newTarget = this.constructor;
var args = [];
for (var _i = 3; _i < arguments.length; _i++) {
args[_i - 3] = arguments[_i];
for (var _i = 6; _i < arguments.length; _i++) {
args[_i - 6] = arguments[_i];
}
var _this = _super.apply(this, args) || this;
Object.setPrototypeOf(_this, _newTarget.prototype);
_this.name = "IndexOutOfBoundsError";
_this.selector = selector;
_this.root = root;
_this.elements = elements;
_this.index = index;
_this.message = "Index: " + index + " of Selector: " + selector + " returned no element at root: " + root;
_this.message =
"Index out of bounds\n" +
("\tIndex: " + index + "\n") +
("\tSelector: \"" + printSelector(selector) + "\"\n") +
("\tRoot: \"" + printElement(root) + "\"\n") +
("\tSelected: " + printElements(elements, printElement));
return _this;

@@ -167,3 +200,3 @@ }

// over selector results.
var makeActionMaterializer = function (runSelector, forEachElement) { return function (selector, action, root) {
var makeActionMaterializer = function (runSelector, forEachElement, printSelector, printElement) { return function (selector, action, root) {
var base = function () {

@@ -185,6 +218,6 @@ var args = [];

if (elements.length === 0) {
throw new ZeroSelectedElementsError(selector, root);
throw new ZeroSelectedElementsError(selector, root, elements, printSelector, printElement);
}
if (elements.length > 1) {
throw new MultipleSelectedElementsError(selector, root);
throw new MultipleSelectedElementsError(selector, root, elements, printSelector, printElement);
}

@@ -201,6 +234,6 @@ return elements.map(function (e) { return action.apply(void 0, [e].concat(args)); })[0];

if (elements.length === 0) {
throw new ZeroSelectedElementsError(selector, root);
throw new ZeroSelectedElementsError(selector, root, elements, printSelector, printElement);
}
if (elements[offset] === null || elements[offset] === undefined) {
throw new IndexOutOfBoundsError(n, selector, root);
throw new IndexOutOfBoundsError(n, selector, root, elements, printSelector, printElement);
}

@@ -218,4 +251,4 @@ return action.apply(void 0, [elements[offset]].concat(args));

}; }; };
exports.makeAdapter = function (composeSelectors, runSelector, iterateSelector, defaultViews) {
return makeTestViewConstructor(composeSelectors, makeActionMaterializer(runSelector, iterateSelector), makeAggregateRealizer(runSelector, iterateSelector), defaultViews);
exports.makeAdapter = function (composeSelectors, runSelector, iterateSelector, printSelector, printElement, defaultViews) {
return makeTestViewConstructor(composeSelectors, makeActionMaterializer(runSelector, iterateSelector, printSelector, printElement), makeAggregateRealizer(runSelector, iterateSelector), printSelector, printElement, defaultViews);
};
{
"name": "@mojotech/prismatest",
"version": "0.2.3",
"version": "0.3.0",
"description": "Use test views to decouple tests from implementation details",

@@ -21,3 +21,3 @@ "main": "dist/index.js",

"clean": "rm -rf ./dist",
"format": "prettier --write \"*.ts\" \"types/*.ts\"",
"format": "prettier --write \"*.ts\"",
"test": "yarn dtslint && jest",

@@ -24,0 +24,0 @@ "dtslint": "tsc -d --emitDeclarationOnly --outDir ./types && dtslint --expectOnly --localTs node_modules/typescript/lib types && rm ./types/index.d.ts"

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