Socket
Socket
Sign inDemoInstall

prescript

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prescript - npm Package Compare versions

Comparing version 0.555555.0 to 0.5555555.0-1

2

lib/createTestIterator.js

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

}
else if (child.cleanup || stillOk) {
else if (child.cleanup || child.independent || stillOk) {
stillOk = (yield* walk(child)) && stillOk;

@@ -95,0 +95,0 @@ }

@@ -129,2 +129,70 @@ "use strict";

});
describe('a test with independent step', () => {
const test = load(({ to, defer, action, independent }) => {
action `Arrange`(async () => { });
defer `Teardown`(async () => { });
action `Act`(async () => { });
to `Asserts`(() => {
independent(() => {
action `Assert 1`(async () => { });
action `Assert 2`(async () => { });
to `Child asserts`(() => {
action `Assert 3`(async () => { });
action `Assert 4`(async () => { });
});
to `Independent child asserts`(() => {
independent(() => {
action `Assert 5`(async () => { });
action `Assert 6`(async () => { });
});
});
});
});
action `Follow up`(async () => { });
});
it('should run all assertions normally', () => {
const sequence = getStepSequence(test);
expect(sequence).toEqual([
'Arrange',
'Act',
'Assert 1',
'Assert 2',
'Assert 3',
'Assert 4',
'Assert 5',
'Assert 6',
'Follow up',
'Teardown'
]);
});
it('should keep on running independent assertions', () => {
const sequence = getStepSequence(test, { failingSteps: ['Assert 1'] });
expect(sequence).toEqual([
'Arrange',
'Act',
'Assert 1',
'Assert 2',
'Assert 3',
'Assert 4',
'Assert 5',
'Assert 6',
'Teardown'
]);
});
it('should keep independent one level only', () => {
const sequence = getStepSequence(test, {
failingSteps: ['Assert 1', 'Assert 3', 'Assert 5']
});
expect(sequence).toEqual([
'Arrange',
'Act',
'Assert 1',
'Assert 2',
'Assert 3',
'Assert 5',
'Assert 6',
'Teardown'
]);
});
});
describe('replacing test', () => {

@@ -162,2 +230,23 @@ it('clears the program counter', () => {

});
function getStepSequence(test, { failingSteps = [] } = {}) {
const tester = createTestIterator_1.default();
tester.setTest(test);
tester.begin();
const out = [];
const fail = new Set(failingSteps);
for (;;) {
const step = tester.getCurrentStepNumber();
if (step === null)
break;
const name = tester.getCurrentStep().name.toString();
out.push(name);
if (fail.has(name)) {
tester.actionFailed(new Error(`Fail on ${name}`));
}
else {
tester.actionPassed();
}
}
return out;
}
//# sourceMappingURL=createTestIterator.test.js.map

@@ -29,6 +29,7 @@ "use strict";

const logger = inLogger || createNullLogger();
const independentContextSet = new Set();
function appendStep(options, f) {
const { name, creator, definition, cleanup, defer, pending } = options;
if (!currentStep) {
throw new Error('Invalid state... This should not happen! currentState is null.');
throw new Error('Invalid state... This should not happen! currentStep is null.');
}

@@ -42,2 +43,3 @@ if (currentStep.action) {

}
const independent = independentContextSet.has(parentStep);
const number = (parentStep.number ? parentStep.number + '.' : '') +

@@ -47,2 +49,3 @@ (parentStep.children.length + 1);

name,
independent,
creator,

@@ -127,2 +130,10 @@ definition,

}
const DEFAULT_COMPOSITE_STEP = () => {
context.pending();
};
const DEFAULT_ACTION_STEP = async () => {
const error = new Error('[pending]');
error.__prescriptPending = true;
throw error;
};
const context = {

@@ -169,3 +180,3 @@ step(inName, f) {

const definition = getSource(error_stack_parser_1.default.parse(new Error(`Action Step: ${name}`)));
return (f) => appendStep({ name, definition }, () => {
return (f = DEFAULT_ACTION_STEP) => appendStep({ name, definition }, () => {
return setAction(f, definition);

@@ -192,3 +203,3 @@ });

const definition = getSource(error_stack_parser_1.default.parse(new Error(`Deferred Action Step: ${name}`)));
return (f) => appendStep({ name, definition, defer: true }, () => {
return (f = DEFAULT_ACTION_STEP) => appendStep({ name, definition, defer: true }, () => {
return setAction(f, definition);

@@ -210,3 +221,3 @@ });

const definition = getSource(error_stack_parser_1.default.parse(new Error(`Composite Step: ${name}`)));
return (f) => appendStep({ name, definition }, f);
return (f = DEFAULT_COMPOSITE_STEP) => appendStep({ name, definition }, f);
}

@@ -229,2 +240,14 @@ else {

});
},
independent(f) {
if (!currentStep) {
throw new Error('Invalid state... This should not happen! currentStep is null.');
}
independentContextSet.add(currentStep);
try {
return f();
}
finally {
independentContextSet.delete(currentStep);
}
}

@@ -231,0 +254,0 @@ };

@@ -18,3 +18,3 @@ import { ActionFunction, StepDefName } from './types';

*/
export declare function to(nameParts: TemplateStringsArray, ...substitutions: any[]): <X>(f: () => X) => X;
export declare function to(nameParts: TemplateStringsArray, ...substitutions: any[]): <X>(f?: () => X) => X;
/**

@@ -27,3 +27,3 @@ * Creates an Action Step to be performed at runtime.

*/
export declare function action(nameParts: TemplateStringsArray, ...substitutions: any[]): (f: ActionFunction) => void;
export declare function action(nameParts: TemplateStringsArray, ...substitutions: any[]): (f?: ActionFunction) => void;
/**

@@ -41,3 +41,3 @@ * Makes the enclosing `step()` an Action Step.

*/
export declare function defer(nameParts: TemplateStringsArray, ...substitutions: any[]): (f: ActionFunction) => void;
export declare function defer(nameParts: TemplateStringsArray, ...substitutions: any[]): (f?: ActionFunction) => void;
/**

@@ -48,2 +48,6 @@ * Creates a Pending step to make the test end with pending state.

export declare function pending(): void;
/**
* Marks the steps inside as independent
*/
export declare function independent<X>(f: () => X): X;
/** @deprecated Use `to()` instead. */

@@ -50,0 +54,0 @@ export declare function step<X>(name: StepDefName, f: () => X): X;

@@ -44,2 +44,9 @@ "use strict";

exports.pending = pending;
/**
* Marks the steps inside as independent
*/
function independent(f) {
return getInstance().independent(f);
}
exports.independent = independent;
/** @deprecated Use `to()` instead. */

@@ -46,0 +53,0 @@ function step(...args) {

@@ -24,2 +24,3 @@ /// <reference types="node" />

definition?: string;
independent?: boolean;
action?: ActionFunction;

@@ -49,2 +50,3 @@ actionDefinition?: string;

onFinish(f: () => void): void;
independent<X>(f: () => X): X;
use(f: (api: IPrescriptAPI) => void): void;

@@ -51,0 +53,0 @@ }

{
"name": "prescript",
"version": "0.555555.0",
"version": "0.5555555.0-1",
"description": "Object-oriented acceptance test tool",

@@ -5,0 +5,0 @@ "main": "./lib/singletonApi.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

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