@haibun/core
Advanced tools
Comparing version 1.2.4 to 1.5.0
@@ -23,2 +23,3 @@ import { DomainContext, WorkspaceContext, WorldContext } from './contexts'; | ||
[name: string]: { | ||
required?: boolean; | ||
desc: string; | ||
@@ -33,2 +34,5 @@ parse: (input: string, existing?: TOptionValue) => { | ||
} | ||
export interface IHasBuilder { | ||
finalize: (workspace: WorkspaceContext) => void; | ||
} | ||
export interface IHasDomains { | ||
@@ -70,4 +74,6 @@ domains: TDomain[]; | ||
options: TOptions; | ||
extraOptions: TExtraOptions; | ||
domains: TModuleDomain[]; | ||
timer: Timer; | ||
base: string; | ||
}; | ||
@@ -95,8 +101,10 @@ export declare type TFeatureMeta = { | ||
}; | ||
export declare type StringOrNumber = string | number; | ||
export declare type TTag = { | ||
sequence: number; | ||
loop: number; | ||
member: number; | ||
params?: any; | ||
trace?: boolean; | ||
sequence: StringOrNumber; | ||
featureNum: StringOrNumber; | ||
loop: StringOrNumber; | ||
member: StringOrNumber; | ||
params: any; | ||
trace: boolean; | ||
}; | ||
@@ -131,2 +139,12 @@ export declare type TVStep = { | ||
}; | ||
export interface CStepper { | ||
new (): AStepper; | ||
prototype: { | ||
steps: { | ||
[name: string]: TStep; | ||
}; | ||
setWorld(world: TWorld, steppers: AStepper[]): void; | ||
getWorld(): TWorld; | ||
}; | ||
} | ||
export declare abstract class AStepper { | ||
@@ -137,3 +155,3 @@ world?: TWorld; | ||
onFailure?(result: TStepResult): void; | ||
setWorld(world: TWorld): void; | ||
setWorld(world: TWorld, steppers: AStepper[]): void; | ||
abstract steps: { | ||
@@ -145,3 +163,4 @@ [name: string]: TStep; | ||
export declare type TFound = { | ||
name: string; | ||
actionName: string; | ||
stepperName: string; | ||
step: TStep; | ||
@@ -168,5 +187,6 @@ named?: TNamed | undefined; | ||
tag: TTag; | ||
shared: WorldContext; | ||
results?: TFeatureResult[]; | ||
failure?: { | ||
stage: 'Collect' | 'Options' | 'Domains' | 'Expand' | 'Resolve' | 'Build' | 'Execute'; | ||
stage: string; | ||
error: TResultError; | ||
@@ -236,6 +256,22 @@ }; | ||
}; | ||
export interface TResultOutput { | ||
export interface IResultOutput { | ||
writeOutput(result: TResult, args: any): Promise<any>; | ||
} | ||
export declare type TLocationOptions = { | ||
tag: TTag; | ||
options: TOptions; | ||
extraOptions: TExtraOptions; | ||
}; | ||
export interface ITraceResult { | ||
writeTraceFile(loc: TLocationOptions, result: TFeatureResult): any; | ||
} | ||
export interface IReviewResult { | ||
writeReview(loc: TLocationOptions, result: TFeatureResult): any; | ||
} | ||
export interface IPublishResults { | ||
publishResults(world: TWorld): any; | ||
} | ||
export declare const HAIBUN = "HAIBUN"; | ||
export declare const BASE_PREFIX: string; | ||
export declare const CAPTURE = "capture"; | ||
export declare const BASE_DOMAINS: { | ||
@@ -251,3 +287,3 @@ name: string; | ||
export declare type TStartRunCallback = (world: TWorld) => void; | ||
export declare type TEndRunCallback = (world: TWorld, result: TResult) => void; | ||
export declare type TendFeatureCallback = (world: TWorld, result: TFeatureResult, steppers: AStepper[]) => void; | ||
export declare type TRunEnv = { | ||
@@ -261,3 +297,3 @@ [name: string]: string; | ||
startRunCallback?: TStartRunCallback; | ||
endRunCallback?: TEndRunCallback; | ||
endFeatureCallback?: TendFeatureCallback; | ||
featureFilter?: string[]; | ||
@@ -264,0 +300,0 @@ specl: TSpecl; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BASE_TYPES = exports.BASE_DOMAINS = exports.HAIBUN = exports.OK = exports.AStepper = exports.WorkspaceBuilder = void 0; | ||
exports.BASE_TYPES = exports.BASE_DOMAINS = exports.CAPTURE = exports.BASE_PREFIX = exports.HAIBUN = exports.OK = exports.AStepper = exports.WorkspaceBuilder = void 0; | ||
class WorkspaceBuilder { | ||
@@ -13,3 +13,3 @@ constructor(name) { | ||
class AStepper { | ||
setWorld(world) { | ||
setWorld(world, steppers) { | ||
this.world = world; | ||
@@ -28,4 +28,6 @@ } | ||
exports.HAIBUN = 'HAIBUN'; | ||
exports.BASE_PREFIX = `${exports.HAIBUN}_`; | ||
exports.CAPTURE = 'capture'; | ||
exports.BASE_DOMAINS = [{ name: 'string', resolve: (inp) => inp }]; | ||
exports.BASE_TYPES = exports.BASE_DOMAINS.map((b) => b.name); | ||
//# sourceMappingURL=defs.js.map |
import { Context } from './contexts'; | ||
import { AStepper, TFound, TWorld } from './defs'; | ||
import { AStepper, TFound, TWorld, TModuleDomain } from './defs'; | ||
export declare const isBaseType: (type: string) => boolean; | ||
export declare const getStepShared: (type: string, world: TWorld) => Context; | ||
export declare const getDomain: (domain: string, world: TWorld) => import("./defs").TModuleDomain | undefined; | ||
export declare const applyDomainsOrError: (steppers: AStepper[], world: TWorld) => void; | ||
export declare const getDomain: (domain: string, world: Partial<TWorld>) => TModuleDomain | undefined; | ||
export declare const getDomains: (steppers: AStepper[], world: TWorld) => Promise<TModuleDomain[]>; | ||
export declare const verifyDomainsOrError: (steppers: AStepper[], world: TWorld) => Promise<void>; | ||
export declare function checkRequiredType({ path }: { | ||
@@ -8,0 +9,0 @@ path: string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.checkRequiredType = exports.applyDomainsOrError = exports.getDomain = exports.getStepShared = exports.isBaseType = void 0; | ||
exports.checkRequiredType = exports.verifyDomainsOrError = exports.getDomains = exports.getDomain = exports.getStepShared = exports.isBaseType = void 0; | ||
const contexts_1 = require("./contexts"); | ||
@@ -10,6 +10,6 @@ const defs_1 = require("./defs"); | ||
// FIXME shouldn't need to check 'feature' | ||
if (type === 'feature' || exports.isBaseType(type)) { | ||
if (type === 'feature' || (0, exports.isBaseType)(type)) { | ||
return world.shared; | ||
} | ||
let source = exports.getDomain(type, world); | ||
let source = (0, exports.getDomain)(type, world); | ||
if (!source || !source.shared) { | ||
@@ -22,3 +22,3 @@ throw Error(`no shared for ${type}, ${source}}`); | ||
} | ||
const fromSource = exports.getDomain(isFrom, world); | ||
const fromSource = (0, exports.getDomain)(isFrom, world); | ||
if (!fromSource || !fromSource.shared) { | ||
@@ -41,4 +41,4 @@ throw Error(`no isFrom shared for ${isFrom}, ${fromSource}}`); | ||
exports.getDomain = getDomain; | ||
const applyDomainsOrError = (steppers, world) => { | ||
// verify no duplicates | ||
const getDomains = async (steppers, world) => { | ||
const domainWorld = { domains: [] }; | ||
for (const module of steppers.filter((s) => !!s.domains).map((s) => s)) { | ||
@@ -48,9 +48,13 @@ const { domains } = module; | ||
for (const d of domains) { | ||
if (exports.getDomain(d.name, world)) { | ||
if ((0, exports.getDomain)(d.name, domainWorld)) { | ||
throw Error(`duplicate domain "${d.name}" in "${module.constructor.name}"`); | ||
} | ||
world.domains.push({ ...d, module, shared: new contexts_1.DomainContext(d.name) }); | ||
domainWorld.domains.push({ ...d, module, shared: new contexts_1.DomainContext(d.name) }); | ||
} | ||
} | ||
} | ||
return domainWorld.domains; | ||
}; | ||
exports.getDomains = getDomains; | ||
const verifyDomainsOrError = async (steppers, world) => { | ||
// verify all required are present | ||
@@ -62,3 +66,3 @@ for (const s of steppers.filter((s) => !!s.requireDomains).map((s) => s)) { | ||
for (const name of requireDomains) { | ||
if (!exports.getDomain(name, world)) { | ||
if (!(0, exports.getDomain)(name, world)) { | ||
throw Error(`missing required domain "${name}" for ${module} from ${Object.keys(world.domains)}`); | ||
@@ -71,3 +75,3 @@ // return { result: { ok: false, failure: { stage: 'Options', error: { details: `missing required domain ${name} in ${name}`, context: world.domains } } } }; | ||
}; | ||
exports.applyDomainsOrError = applyDomainsOrError; | ||
exports.verifyDomainsOrError = verifyDomainsOrError; | ||
// if there is a fileType for the domain type, get it from the match and make sure it is ok | ||
@@ -74,0 +78,0 @@ function checkRequiredType({ path }, featureLine, actions, world) { |
@@ -53,4 +53,4 @@ "use strict"; | ||
let lines = []; | ||
exports.featureSplit(feature.content).forEach((l) => { | ||
const actionable = util_1.getActionable(l); | ||
(0, exports.featureSplit)(feature.content).forEach((l) => { | ||
const actionable = (0, util_1.getActionable)(l); | ||
if (actionable.match(/^Backgrounds: .*$/)) { | ||
@@ -63,3 +63,3 @@ lines = lines.concat(doIncludes(l, backgrounds)); | ||
else { | ||
lines.push(exports.asFeatureLine(l, feature)); | ||
lines.push((0, exports.asFeatureLine)(l, feature)); | ||
} | ||
@@ -90,4 +90,4 @@ }); | ||
const origin = bg[0]; | ||
for (const l of exports.featureSplit(origin.content)) { | ||
ret.push(exports.asFeatureLine(l, origin)); | ||
for (const l of (0, exports.featureSplit)(origin.content)) { | ||
ret.push((0, exports.asFeatureLine)(l, origin)); | ||
} | ||
@@ -94,0 +94,0 @@ } |
@@ -28,3 +28,3 @@ "use strict"; | ||
test('simple', async () => { | ||
const features = lib_1.asFeatures([{ path: '/f1', content: 'f1_step' }]); | ||
const features = (0, lib_1.asFeatures)([{ path: '/f1', content: 'f1_step' }]); | ||
const res = await steps.expandBackgrounds(features); | ||
@@ -34,7 +34,7 @@ expect(res).toEqual(features); | ||
test('hierarchical', async () => { | ||
const features = lib_1.asFeatures([ | ||
const features = (0, lib_1.asFeatures)([ | ||
{ path: '/f1', content: 'f1_step' }, | ||
{ path: '/f1/l1f1', content: 'l1f1_step' }, | ||
]); | ||
const expected = lib_1.asFeatures([ | ||
const expected = (0, lib_1.asFeatures)([ | ||
{ path: '/f1', content: 'f1_step' }, | ||
@@ -47,3 +47,3 @@ { path: '/f1/l1f1', content: 'f1_step\nl1f1_step' }, | ||
test('multiple hierarchical', async () => { | ||
const features = lib_1.asFeatures([ | ||
const features = (0, lib_1.asFeatures)([ | ||
{ path: '/f1', content: 'f1_step' }, | ||
@@ -53,3 +53,3 @@ { path: '/l1/l1f1', content: 'l1_step' }, | ||
]); | ||
const expected = lib_1.asFeatures([ | ||
const expected = (0, lib_1.asFeatures)([ | ||
{ path: '/f1', content: 'f1_step' }, | ||
@@ -64,3 +64,3 @@ { path: '/l1/l1f1', content: 'f1_step\nl1_step' }, | ||
describe('feature finding', () => { | ||
const features = lib_1.asFeatures([ | ||
const features = (0, lib_1.asFeatures)([ | ||
{ path: '/l0.feature', content: 'l0_feature' }, | ||
@@ -75,11 +75,11 @@ { path: '/l0/l1.feature', content: 'l1_feature' }, | ||
const res = steps.findFeatures('l0', features); | ||
expect(res).toEqual(lib_1.asFeatures([{ path: '/l0.feature', content: 'l0_feature' }])); | ||
expect(res).toEqual((0, lib_1.asFeatures)([{ path: '/l0.feature', content: 'l0_feature' }])); | ||
}); | ||
test('finds l1 feature', () => { | ||
const res = steps.findFeatures('l1', features); | ||
expect(res).toEqual(lib_1.asFeatures([{ path: '/l0/l1.feature', content: 'l1_feature' }])); | ||
expect(res).toEqual((0, lib_1.asFeatures)([{ path: '/l0/l1.feature', content: 'l1_feature' }])); | ||
}); | ||
test('finds multiple', () => { | ||
const res = steps.findFeatures('l1', lib_1.asFeatures([...features, { path: '/l1/l1.feature', content: 'l1_l1_feature' }])); | ||
expect(res).toEqual(lib_1.asFeatures([ | ||
const res = steps.findFeatures('l1', (0, lib_1.asFeatures)([...features, { path: '/l1/l1.feature', content: 'l1_l1_feature' }])); | ||
expect(res).toEqual((0, lib_1.asFeatures)([ | ||
{ path: '/l0/l1.feature', content: 'l1_feature' }, | ||
@@ -90,4 +90,4 @@ { path: '/l1/l1.feature', content: 'l1_l1_feature' }, | ||
test('finds fileType', () => { | ||
const res = steps.findFeatures('l1', lib_1.asFeatures([...features, { path: '/l1/l1.mytype.feature', content: 'l1_l1_mytype.feature' }]), 'mytype'); | ||
expect(res).toEqual(lib_1.asFeatures([{ path: '/l1/l1.mytype.feature', content: 'l1_l1_mytype.feature' }])); | ||
const res = steps.findFeatures('l1', (0, lib_1.asFeatures)([...features, { path: '/l1/l1.mytype.feature', content: 'l1_l1_mytype.feature' }]), 'mytype'); | ||
expect(res).toEqual((0, lib_1.asFeatures)([{ path: '/l1/l1.mytype.feature', content: 'l1_l1_mytype.feature' }])); | ||
}); | ||
@@ -97,11 +97,11 @@ }); | ||
test('applies backgrounds', async () => { | ||
const features = lib_1.asFeatures([{ path: '/f1', content: 'Backgrounds: b1\nextant' }]); | ||
const backgrounds = lib_1.asFeatures([{ path: '/b1.feature', content: 'result' }]); | ||
const features = (0, lib_1.asFeatures)([{ path: '/f1', content: 'Backgrounds: b1\nextant' }]); | ||
const backgrounds = (0, lib_1.asFeatures)([{ path: '/b1.feature', content: 'result' }]); | ||
const res = await steps.expandFeatures(features, backgrounds); | ||
const expected = lib_1.asExpandedFeatures([{ path: '/f1', content: '\nresult\nextant' }]); | ||
const expected = (0, lib_1.asExpandedFeatures)([{ path: '/f1', content: '\nresult\nextant' }]); | ||
expect(res[0].expanded).toEqual(expected[0].expanded); | ||
}); | ||
test('applies backgrounds hierarchical', async () => { | ||
const features = lib_1.asFeatures([{ path: '/l1/f1', content: 'Backgrounds: b2' }]); | ||
const backgrounds = lib_1.asFeatures([ | ||
const features = (0, lib_1.asFeatures)([{ path: '/l1/f1', content: 'Backgrounds: b2' }]); | ||
const backgrounds = (0, lib_1.asFeatures)([ | ||
{ path: '/l1/b1.feature', content: 'non-result' }, | ||
@@ -111,3 +111,3 @@ { path: '/l2/b2.feature', content: 'result' }, | ||
const res = await steps.expandFeatures(features, backgrounds); | ||
expect(res).toEqual(lib_1.asExpandedFeatures([{ path: '/l1/f1', content: '\nresult\n' }])); | ||
expect(res).toEqual((0, lib_1.asExpandedFeatures)([{ path: '/l1/f1', content: '\nresult\n' }])); | ||
}); | ||
@@ -127,3 +127,3 @@ }); | ||
index++; | ||
return util_1.actionOK(); | ||
return (0, util_1.actionOK)(); | ||
}, | ||
@@ -136,3 +136,3 @@ }, | ||
const env = { what: [0, 1] }; | ||
const { world } = await lib_1.testWithDefaults([feature], [TestEnvcStepper], { options: { env }, extraOptions: {} }); | ||
const { world } = await (0, lib_1.testWithDefaults)([feature], [TestEnvcStepper], { options: { env }, extraOptions: {} }); | ||
expect(world.options._index_what).toBe(1); | ||
@@ -139,0 +139,0 @@ }); |
@@ -63,3 +63,3 @@ "use strict"; | ||
} | ||
const tag = messageContext?.tag ? util_1.descTag(messageContext.tag) : ''; | ||
const tag = messageContext?.tag ? (0, util_1.descTag)(messageContext.tag) : ''; | ||
console[level](`${ln}${tag}: `.padStart(WIDTH), args, level.padStart(6)); | ||
@@ -66,0 +66,0 @@ } |
@@ -59,3 +59,3 @@ "use strict"; | ||
}; | ||
const dlogger = new Logger_1.default({ output, tag: lib_1.getDefaultTag(0) }); | ||
const dlogger = new Logger_1.default({ output, tag: (0, lib_1.getDefaultTag)(0) }); | ||
dlogger.log('test'); | ||
@@ -62,0 +62,0 @@ }); |
@@ -10,4 +10,5 @@ import { TStep, TNamedVar, TFound, TNamed, TWorld } from './defs'; | ||
} | undefined; | ||
export declare const getMatch: (actionable: string, r: RegExp, name: string, step: TStep, vars?: TNamedVar[] | undefined) => { | ||
name: string; | ||
export declare const getMatch: (actionable: string, r: RegExp, actionName: string, stepperName: string, step: TStep, vars?: TNamedVar[] | undefined) => { | ||
actionName: string; | ||
stepperName: string; | ||
step: TStep; | ||
@@ -14,0 +15,0 @@ named: { |
@@ -42,3 +42,3 @@ "use strict"; | ||
last = be + 1; | ||
str += exports.matchGroups(matches++); | ||
str += (0, exports.matchGroups)(matches++); | ||
} | ||
@@ -63,3 +63,3 @@ str += inp.substr(be + 1); | ||
exports.getNamedMatches = getNamedMatches; | ||
const getMatch = (actionable, r, name, step, vars) => { | ||
const getMatch = (actionable, r, actionName, stepperName, step, vars) => { | ||
if (!r.test(actionable)) { | ||
@@ -69,3 +69,3 @@ return; | ||
const named = getNamedMatches(r, actionable); | ||
return { name, step, named, vars }; | ||
return { actionName, stepperName, step, named, vars }; | ||
}; | ||
@@ -85,3 +85,3 @@ exports.getMatch = getMatch; | ||
const { name, type } = v; | ||
const shared = domain_1.getStepShared(type, world); | ||
const shared = (0, domain_1.getStepShared)(type, world); | ||
const namedKey = Object.keys(named).find((c) => c.endsWith(`_${i}`) && named[c] !== undefined); | ||
@@ -104,6 +104,6 @@ if (!namedKey) { | ||
// must be from source | ||
if (!shared.get(credentials_1.cred(namedValue))) { | ||
if (!shared.get((0, credentials_1.cred)(namedValue))) { | ||
throw Error(`no value for credential "${namedValue}" from ${JSON.stringify({ keys: Object.keys(shared), type })}`); | ||
} | ||
namedFromVars[name] = shared.get(credentials_1.cred(namedValue)); | ||
namedFromVars[name] = shared.get((0, credentials_1.cred)(namedValue)); | ||
} | ||
@@ -110,0 +110,0 @@ else if (namedKey.startsWith(TYPE_ENV)) { |
@@ -12,6 +12,6 @@ "use strict"; | ||
match: /^(?<one>.*?) is (?<two>.*?)$/, | ||
action: async () => util_1.actionNotOK('test'), | ||
action: async () => (0, util_1.actionNotOK)('test'), | ||
}; | ||
it('gets named matches', () => { | ||
expect(namedVars_1.getNamedMatches(step.match, 'It is set')).toEqual({ one: 'It', two: 'set' }); | ||
expect((0, namedVars_1.getNamedMatches)(step.match, 'It is set')).toEqual({ one: 'It', two: 'set' }); | ||
}); | ||
@@ -21,16 +21,16 @@ }); | ||
test('gets string', () => { | ||
expect(namedVars_1.namedInterpolation('hi').str).toEqual('hi'); | ||
expect((0, namedVars_1.namedInterpolation)('hi').str).toEqual('hi'); | ||
}); | ||
test('gets var', () => { | ||
expect(namedVars_1.namedInterpolation('{hi}')).toEqual({ str: `${namedVars_1.matchGroups(0)}`, vars: [{ name: 'hi', type: 'string' }] }); | ||
expect((0, namedVars_1.namedInterpolation)('{hi}')).toEqual({ str: `${(0, namedVars_1.matchGroups)(0)}`, vars: [{ name: 'hi', type: 'string' }] }); | ||
}); | ||
test('gets var with type', () => { | ||
expect(namedVars_1.namedInterpolation('{hi: string}')).toEqual({ str: `${namedVars_1.matchGroups(0)}`, vars: [{ name: 'hi', type: 'string' }] }); | ||
expect((0, namedVars_1.namedInterpolation)('{hi: string}')).toEqual({ str: `${(0, namedVars_1.matchGroups)(0)}`, vars: [{ name: 'hi', type: 'string' }] }); | ||
}); | ||
test('gets var with post string', () => { | ||
expect(namedVars_1.namedInterpolation('{hi} eh')).toEqual({ str: `${namedVars_1.matchGroups(0)} eh`, vars: [{ name: 'hi', type: 'string' }] }); | ||
expect((0, namedVars_1.namedInterpolation)('{hi} eh')).toEqual({ str: `${(0, namedVars_1.matchGroups)(0)} eh`, vars: [{ name: 'hi', type: 'string' }] }); | ||
}); | ||
test('gets vars', () => { | ||
expect(namedVars_1.namedInterpolation('{hi} and {there}')).toEqual({ | ||
str: `${namedVars_1.matchGroups(0)} and ${namedVars_1.matchGroups(1)}`, | ||
expect((0, namedVars_1.namedInterpolation)('{hi} and {there}')).toEqual({ | ||
str: `${(0, namedVars_1.matchGroups)(0)} and ${(0, namedVars_1.matchGroups)(1)}`, | ||
vars: [ | ||
@@ -43,4 +43,4 @@ { name: 'hi', type: 'string' }, | ||
test('gets vars with post text', () => { | ||
expect(namedVars_1.namedInterpolation('{hi} and {there} eh')).toEqual({ | ||
str: `${namedVars_1.matchGroups(0)} and ${namedVars_1.matchGroups(1)} eh`, | ||
expect((0, namedVars_1.namedInterpolation)('{hi} and {there} eh')).toEqual({ | ||
str: `${(0, namedVars_1.matchGroups)(0)} and ${(0, namedVars_1.matchGroups)(1)} eh`, | ||
vars: [ | ||
@@ -53,3 +53,3 @@ { name: 'hi', type: 'string' }, | ||
test('throws for bad type', () => { | ||
expect(() => namedVars_1.namedInterpolation('{hi: wtw}')).toThrow(); | ||
expect(() => (0, namedVars_1.namedInterpolation)('{hi: wtw}')).toThrow(); | ||
}); | ||
@@ -59,3 +59,3 @@ }); | ||
test('regexes single', () => { | ||
const r = new RegExp(namedVars_1.namedInterpolation('{ v1: string } ').str); | ||
const r = new RegExp((0, namedVars_1.namedInterpolation)('{ v1: string } ').str); | ||
expect(r.exec('"hi" there')?.groups?.q_0).toBe('hi'); | ||
@@ -67,3 +67,3 @@ expect(r.exec('<hi> there')?.groups?.c_0).toBe('hi'); | ||
test('regexes two', () => { | ||
const r2 = new RegExp(namedVars_1.namedInterpolation('{ v1 } is { v2 }').str); | ||
const r2 = new RegExp((0, namedVars_1.namedInterpolation)('{ v1 } is { v2 }').str); | ||
const x = r2.exec('this is that'); | ||
@@ -74,3 +74,3 @@ expect(x?.groups?.t_0).toBe('this'); | ||
}); | ||
describe('getNamedWithVars', () => { | ||
describe('getNamedWithVars', async () => { | ||
class TestStepper extends defs_1.AStepper { | ||
@@ -87,12 +87,12 @@ constructor() { | ||
} | ||
const steppers = [new TestStepper()]; | ||
const { world } = lib_1.getDefaultWorld(0); | ||
const { world } = (0, lib_1.getDefaultWorld)(0); | ||
const steppers = await (0, util_1.createSteppers)([TestStepper]); | ||
const resolver = new Resolver_1.Resolver(steppers, '', world); | ||
world.shared.set('exact', 'res'); | ||
test('gets var', async () => { | ||
const features = lib_1.asExpandedFeatures([features_1.withNameType('l1', 'is `exact`')]); | ||
const features = (0, lib_1.asExpandedFeatures)([(0, features_1.withNameType)('l1', 'is `exact`')]); | ||
const res = await resolver.resolveSteps(features); | ||
const { vsteps } = res[0]; | ||
expect(vsteps[0].actions[0]).toBeDefined(); | ||
const val = namedVars_1.getNamedToVars(vsteps[0].actions[0], world); | ||
const val = (0, namedVars_1.getNamedToVars)(vsteps[0].actions[0], world); | ||
expect(val?.what).toBe('res'); | ||
@@ -99,0 +99,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
import { TRunOptions, TRunResult } from './defs'; | ||
import { TRunOptions, TRunResult, StringOrNumber } from './defs'; | ||
import Logger from './Logger'; | ||
@@ -9,3 +9,3 @@ export default function runWithOptions(runOptions: TRunOptions): Promise<{ | ||
[message: string]: { | ||
sequence: number; | ||
sequence: StringOrNumber; | ||
runDuration: number; | ||
@@ -12,0 +12,0 @@ fromStart: number; |
@@ -12,3 +12,3 @@ "use strict"; | ||
async function runWithOptions(runOptions) { | ||
const { loops, members, trace, startRunCallback, endRunCallback, featureFilter, specl, base, splits, protoOptions } = runOptions; | ||
const { loops, members, trace, startRunCallback, endFeatureCallback, featureFilter, specl, base, splits, protoOptions } = runOptions; | ||
const { LOG_LEVEL: logLevel, LOG_FOLLOW: logFollow } = protoOptions.options; | ||
@@ -28,8 +28,5 @@ const logger = new Logger_1.default({ level: logLevel || 'debug', follow: logFollow }); | ||
const runtime = {}; | ||
const tag = util_1.getRunTag(totalRan, loop, member, split, trace); | ||
const tag = (0, util_1.getRunTag)(totalRan, loop, member, 0, split, trace); | ||
totalRan++; | ||
const res = await doRun(base, specl, runtime, featureFilter, new contexts_1.WorldContext(tag, split), protoOptions, logger, tag, timer, startRunCallback); | ||
if (endRunCallback) { | ||
endRunCallback(res.world, res.result); | ||
} | ||
const res = await doRun(base, specl, runtime, featureFilter, new contexts_1.WorldContext(tag, split), protoOptions, logger, tag, timer, startRunCallback, endFeatureCallback); | ||
return res; | ||
@@ -80,6 +77,6 @@ }); | ||
exports.default = runWithOptions; | ||
async function doRun(base, specl, runtime, featureFilter, shared, protoOptions, containerLogger, tag, timer, startRunCallback) { | ||
async function doRun(base, specl, runtime, featureFilter, shared, protoOptions, containerLogger, tag, timer, startRunCallback, endFeatureCallback) { | ||
const runStart = process.hrtime(); | ||
const logger = new Logger_1.default({ output: containerLogger, tag }); | ||
const world = { options: protoOptions.options, shared, logger, runtime, domains: [], tag, timer }; | ||
const world = { options: protoOptions.options, extraOptions: protoOptions.extraOptions, shared, logger, runtime, domains: [], tag, timer, base }; | ||
if (startRunCallback) { | ||
@@ -89,6 +86,6 @@ startRunCallback(world); | ||
logger.log(`running with these options: ${JSON.stringify(world.options)})}`); | ||
const { result } = await run_1.run({ specl, base, world, featureFilter, extraOptions: protoOptions.extraOptions }); | ||
const output = await util_1.resultOutput(process.env.HAIBUN_OUTPUT, result); | ||
const result = await (0, run_1.run)({ specl, base, world, featureFilter, extraOptions: protoOptions.extraOptions, endFeatureCallback }); | ||
const output = await (0, util_1.resultOutput)(world.options.OUTPUT, result); | ||
return { world, result, shared, output, tag, runStart: runStart[0], runDuration: process.hrtime(runStart)[0], fromStart: timer.since() }; | ||
} | ||
//# sourceMappingURL=run-with-options.js.map |
@@ -1,14 +0,12 @@ | ||
import { TSpecl, AStepper, TResult, TWorld, TFeature, TExtraOptions } from './defs'; | ||
declare type TrunOptions = { | ||
import { TSpecl, TResult, TWorld, TFeature, TExtraOptions, TendFeatureCallback, CStepper } from './defs'; | ||
declare type TRunOptions = { | ||
specl: TSpecl; | ||
world: TWorld; | ||
base: string; | ||
addSteppers?: typeof AStepper[]; | ||
addSteppers?: CStepper[]; | ||
featureFilter?: string[]; | ||
extraOptions?: TExtraOptions; | ||
endFeatureCallback?: TendFeatureCallback; | ||
}; | ||
export declare function run({ specl, base, world, addSteppers, featureFilter, extraOptions }: TrunOptions): Promise<{ | ||
result: TResult; | ||
steppers?: AStepper[]; | ||
}>; | ||
export declare function run({ specl, base, world, addSteppers, featureFilter, endFeatureCallback }: TRunOptions): Promise<TResult>; | ||
declare type TRunWithOptions = { | ||
@@ -19,4 +17,4 @@ specl: TSpecl; | ||
backgrounds: TFeature[]; | ||
addSteppers: typeof AStepper[]; | ||
extraOptions?: TExtraOptions; | ||
addSteppers: CStepper[]; | ||
endFeatureCallback?: TendFeatureCallback; | ||
}; | ||
@@ -27,7 +25,4 @@ export declare const DEF_PROTO_OPTIONS: { | ||
}; | ||
export declare function runWith({ specl, world, features, backgrounds, addSteppers, extraOptions }: TRunWithOptions): Promise<{ | ||
result: TResult; | ||
steppers?: AStepper[]; | ||
}>; | ||
export declare function runWith({ specl, world, features, backgrounds, addSteppers, endFeatureCallback }: TRunWithOptions): Promise<TResult>; | ||
export {}; | ||
//# sourceMappingURL=run.d.ts.map |
@@ -20,4 +20,4 @@ "use strict"; | ||
action: async ({ what, type }) => { | ||
const location = vars_1.onCurrentTypeForDomain({ name: what, type }, this.getWorld()); | ||
return util_1.actionOK(location); | ||
const location = (0, vars_1.onCurrentTypeForDomain)({ name: what, type }, this.getWorld()); | ||
return (0, util_1.actionOK)(location); | ||
}, | ||
@@ -28,3 +28,3 @@ }, | ||
action: async (named) => { | ||
return util_1.actionOK(); | ||
return (0, util_1.actionOK)(); | ||
}, | ||
@@ -48,4 +48,4 @@ }, | ||
const value = 'xxx'; | ||
vars_1.setShared({ what, value }, vstep, this.getWorld()); | ||
return util_1.actionOK(); | ||
(0, vars_1.setShared)({ what, value }, vstep, this.getWorld()); | ||
return (0, util_1.actionOK)(); | ||
}, | ||
@@ -58,3 +58,3 @@ }, | ||
it('missing domain object', async () => { | ||
const { result } = await lib_1.testWithDefaults([{ path: '/features/test.feature', content: `\nHas a foobar control\n` }], [TestStepsRequiresDomain]); | ||
const result = await (0, lib_1.testWithDefaults)([{ path: '/features/test.feature', content: `\nHas a foobar control\n` }], [TestStepsRequiresDomain]); | ||
expect(result.ok).toBe(false); | ||
@@ -65,11 +65,11 @@ expect(result.failure.error.message.startsWith(`missing required domain "${TTYPE}"`)).toBe(true); | ||
it('domain object from background', async () => { | ||
const specl = util_1.getOptionsOrDefault(); | ||
const specl = (0, util_1.getDefaultOptions)(); | ||
const key = '/backgrounds/p1'; | ||
const { world } = lib_1.getDefaultWorld(0); | ||
const features = lib_1.asFeatures([{ path: '/features/test.feature', content: `Backgrounds: p1.${TTYPE}\n\nOn the /backgrounds/p1 ${TTYPE}\nSee the page control\n` }]); | ||
const backgrounds = lib_1.asFeatures([{ path: `/backgrounds/p1.${TTYPE}.feature`, content: 'Has a lever control' }]); | ||
const { result } = await run_1.runWith({ specl, features, backgrounds, addSteppers: [TestStepsRequiresDomain, TestStepsWithDomain], world }); | ||
const { world } = (0, lib_1.getDefaultWorld)(0); | ||
const features = (0, lib_1.asFeatures)([{ path: '/features/test.feature', content: `Backgrounds: p1.${TTYPE}\n\nOn the /backgrounds/p1 ${TTYPE}\nSee the page control\n` }]); | ||
const backgrounds = (0, lib_1.asFeatures)([{ path: `/backgrounds/p1.${TTYPE}.feature`, content: 'Has a lever control' }]); | ||
const result = await (0, run_1.runWith)({ specl, features, backgrounds, addSteppers: [TestStepsRequiresDomain, TestStepsWithDomain], world }); | ||
expect(result.ok).toBe(true); | ||
expect(world.shared.getCurrent(TTYPE)).toEqual(key); | ||
const page = domain_1.getDomain(TTYPE, world).shared.get(key); | ||
const page = (0, domain_1.getDomain)(TTYPE, world).shared.get(key); | ||
expect(page).toBeDefined(); | ||
@@ -76,0 +76,0 @@ expect(page.get(ACONTROL)).toEqual('xxx'); |
@@ -14,74 +14,54 @@ "use strict"; | ||
const domain_1 = require("./domain"); | ||
async function run({ specl, base, world, addSteppers = [], featureFilter, extraOptions = {} }) { | ||
async function run({ specl, base, world, addSteppers = [], featureFilter, endFeatureCallback }) { | ||
let features; | ||
let backgrounds = []; | ||
try { | ||
features = util_1.debase(base, util_1.recurse(`${base}/features`, 'feature', featureFilter)); | ||
if (fs_1.existsSync(`${base}/backgrounds`)) { | ||
backgrounds = util_1.debase(base, util_1.recurse(`${base}/backgrounds`, 'feature')); | ||
features = (0, util_1.debase)(base, (0, util_1.recurse)(`${base}/features`, 'feature', featureFilter)); | ||
if ((0, fs_1.existsSync)(`${base}/backgrounds`)) { | ||
backgrounds = (0, util_1.debase)(base, (0, util_1.recurse)(`${base}/backgrounds`, 'feature')); | ||
} | ||
} | ||
catch (error) { | ||
return { result: { ok: false, tag: util_1.getRunTag(-1, -1, -1, {}, false), failure: { stage: 'Collect', error: { message: error.message, details: { stack: error.stack } } } } }; | ||
return { ok: false, tag: (0, util_1.getRunTag)(-1, -1, -1, -1, {}, false), failure: { stage: 'Collect', error: { message: error.message, details: { stack: error.stack } } }, shared: world.shared }; | ||
} | ||
return runWith({ specl, world, features, backgrounds, addSteppers, extraOptions }); | ||
return runWith({ specl, world, features, backgrounds, addSteppers, endFeatureCallback }); | ||
} | ||
exports.run = run; | ||
exports.DEF_PROTO_OPTIONS = { options: {}, extraOptions: {} }; | ||
async function runWith({ specl, world, features, backgrounds, addSteppers, extraOptions = {} }) { | ||
async function runWith({ specl, world, features, backgrounds, addSteppers, endFeatureCallback }) { | ||
const { tag } = world; | ||
const steppers = await util_1.getSteppers({ steppers: specl.steppers, addSteppers }); | ||
let result = undefined; | ||
try { | ||
util_1.applyExtraOptions(extraOptions, steppers, world); | ||
} | ||
catch (error) { | ||
console.error(error); | ||
return { result: { ok: false, tag, failure: { stage: 'Options', error: { message: error.message, details: error } } } }; | ||
} | ||
try { | ||
domain_1.applyDomainsOrError(steppers, world); | ||
} | ||
catch (error) { | ||
return { result: { ok: false, tag, failure: { stage: 'Domains', error: { message: error.message, details: { stack: error.stack } } } } }; | ||
} | ||
let expandedFeatures; | ||
try { | ||
expandedFeatures = await features_1.expand(backgrounds, features); | ||
} | ||
catch (error) { | ||
return { result: { ok: false, tag, failure: { stage: 'Expand', error: { message: error.message, details: error } } } }; | ||
} | ||
let mappedValidatedSteps; | ||
try { | ||
const errorBail = (phase, error, details) => { | ||
result = { ok: false, tag, failure: { stage: phase, error: { message: error.message, details: { stack: error.stack, details } } } }; | ||
throw Error(error); | ||
}; | ||
const baseSteppers = await (0, util_1.getSteppers)(specl.steppers).catch(error => errorBail('Steppers', error)); | ||
const csteppers = baseSteppers.concat(addSteppers); | ||
await (0, util_1.verifyRequiredOptions)(csteppers, world.options).catch(error => errorBail('Required Options', error)); | ||
await (0, util_1.verifyExtraOptions)(world.extraOptions, csteppers).catch((error) => errorBail('Options', error)); | ||
const expandedFeatures = await (0, features_1.expand)(backgrounds, features).catch(error => errorBail('Expand', tag, error)); | ||
const steppers = await (0, util_1.createSteppers)(csteppers); | ||
await (0, util_1.setWorldStepperOptions)(steppers, world); | ||
world.domains = await (0, domain_1.getDomains)(steppers, world).catch(error => errorBail('Get Domains', error)); | ||
await (0, domain_1.verifyDomainsOrError)(steppers, world).catch(error => errorBail('Required Domains', error)); | ||
const resolver = new Resolver_1.Resolver(steppers, specl.mode, world); | ||
mappedValidatedSteps = await resolver.resolveSteps(expandedFeatures); | ||
} | ||
catch (error) { | ||
return { result: { ok: false, tag, failure: { stage: 'Resolve', error: { message: error.message, details: { stack: error.stack, steppers, mappedValidatedSteps } } } } }; | ||
} | ||
const builder = new Builder_1.default(world); | ||
try { | ||
const res = await builder.build(mappedValidatedSteps); | ||
const mappedValidatedSteps = await resolver.resolveSteps(expandedFeatures).catch(error => errorBail('Resolve', error)); | ||
const builder = new Builder_1.default(steppers, world); | ||
await builder.build(mappedValidatedSteps).catch(error => errorBail('Build', error, { stack: error.stack, mappedValidatedSteps })); | ||
world.logger.log(`features: ${expandedFeatures.length} backgrounds: ${backgrounds.length} steps: (${expandedFeatures.map((e) => e.path)}), ${mappedValidatedSteps.length}`); | ||
result = await Executor_1.Executor.execute(csteppers, world, mappedValidatedSteps, endFeatureCallback).catch(error => errorBail('Execute', error)); | ||
// if (!result || !result.ok) { | ||
// const message = (result.results![0].stepResults.find(s => !s.ok)?.actionResults[0] as TNotOKActionResult).message; | ||
// result.failure = { stage: 'Execute', error: { message, details: { errors: result.results?.filter((r) => !r.ok).map((r) => r.path) } } }; | ||
// } | ||
} | ||
catch (error) { | ||
console.error(error); | ||
return { result: { ok: false, tag, failure: { stage: 'Build', error: { message: error.message, details: { stack: error.stack, steppers, mappedValidatedSteps } } } } }; | ||
catch (e) { | ||
console.log('fell', e); | ||
} | ||
const executor = new Executor_1.Executor(steppers, world); | ||
let result; | ||
try { | ||
result = { ...await executor.execute(mappedValidatedSteps), tag }; | ||
if (!result.ok) { | ||
const message = result.results[0].stepResults.find(s => !s.ok)?.actionResults[0].message; | ||
result.failure = { stage: 'Execute', error: { message, details: { errors: result.results?.filter((r) => !r.ok).map((r) => r.path) } } }; | ||
} | ||
finally { | ||
return result; | ||
} | ||
catch (e) { | ||
console.error('XXXXXXX', e); | ||
result = { ok: false, tag, failure: e }; | ||
} | ||
return { result, steppers }; | ||
} | ||
exports.runWith = runWith; | ||
//# sourceMappingURL=run.js.map |
@@ -7,2 +7,3 @@ "use strict"; | ||
const haibun_1 = __importDefault(require("../steps/haibun")); | ||
const defs_1 = require("./defs"); | ||
const lib_1 = require("./test/lib"); | ||
@@ -13,3 +14,3 @@ const TestSteps_1 = __importDefault(require("./test/TestSteps")); | ||
const feature = { path: '/features/test.feature', content: `When I have a test\nThen the test should pass` }; | ||
const { result } = await lib_1.testWithDefaults([feature], [TestSteps_1.default]); | ||
const result = await (0, lib_1.testWithDefaults)([feature], [TestSteps_1.default]); | ||
expect(result.ok).toBe(true); | ||
@@ -24,2 +25,23 @@ expect(result.results.length).toBe(1); | ||
}); | ||
it.only('increments feature', async () => { | ||
const TS = class TS extends defs_1.AStepper { | ||
constructor() { | ||
super(...arguments); | ||
this.steps = { | ||
test: { | ||
exact: 'The feature should be incremented', | ||
action: async () => { | ||
const { featureNum } = this.getWorld().tag; | ||
this.getWorld().shared.set('result', `${featureNum}`); | ||
return defs_1.OK; | ||
} | ||
}, | ||
}; | ||
} | ||
}; | ||
const feature = { path: '/features/test.feature', content: `When I have a test` }; | ||
const feature2 = { path: '/features/test.feature', content: `The feature should be incremented` }; | ||
const { world } = await (0, lib_1.testWithDefaults)([feature, feature2], [TestSteps_1.default, TS]); | ||
expect(world.shared.get('result')).toBe(2); | ||
}); | ||
describe('run backgrounds', () => { | ||
@@ -29,3 +51,3 @@ it('background', async () => { | ||
const background = { path: '/backgrounds/included.feature', content: `Then the test should pass` }; | ||
const { result } = await lib_1.testWithDefaults([feature], [TestSteps_1.default], undefined, [background]); | ||
const result = await (0, lib_1.testWithDefaults)([feature], [TestSteps_1.default], undefined, [background]); | ||
expect(result.ok).toBe(true); | ||
@@ -43,3 +65,3 @@ expect(result.results.length).toBe(1); | ||
const feature = { path: '/features/test.feature', content: `When I fail` }; | ||
const { result } = await lib_1.testWithDefaults([feature], [TestSteps_1.default]); | ||
const result = await (0, lib_1.testWithDefaults)([feature], [TestSteps_1.default]); | ||
expect(result.ok).toBe(false); | ||
@@ -53,3 +75,3 @@ expect(result.failure?.stage).toBe('Resolve'); | ||
const feature = { path: '/features/test.feature', content: `When I have a test\nThen the test can fail` }; | ||
const { result } = await lib_1.testWithDefaults([feature], [TestSteps_1.default]); | ||
const result = await (0, lib_1.testWithDefaults)([feature], [TestSteps_1.default]); | ||
expect(result.ok).toBe(false); | ||
@@ -62,3 +84,3 @@ expect(result.failure?.stage).toBe('Execute'); | ||
const features = [{ path: '/features/fails.feature', content: `When I have a test\nThen the test can fail` }, { path: '/features/passes.feature', content: `When I have a test\nThen the test should pass` }]; | ||
const { result } = await lib_1.testWithDefaults(features, [TestSteps_1.default]); | ||
const result = await (0, lib_1.testWithDefaults)(features, [TestSteps_1.default]); | ||
expect(result.ok).toBe(false); | ||
@@ -73,7 +95,8 @@ expect(result.results?.length).toBe(2); | ||
const backgrounds = [{ path: '/backgrounds/vars.feature', content: `Given I set var to 1\nGiven I set Var 2 to 2\nSet Var 3 to 3` }]; | ||
const { world, result } = await lib_1.testWithDefaults(features, [TestSteps_1.default], undefined, backgrounds); | ||
const result = await (0, lib_1.testWithDefaults)(features, [TestSteps_1.default], undefined, backgrounds); | ||
expect(result.ok).toBe(true); | ||
expect(world.shared.get('var')).toBe('1'); | ||
expect(world.shared.get('Var 2')).toBe('2'); | ||
expect(world.shared.get('Var 3')).toBe('3'); | ||
const { shared } = result; | ||
expect(shared.get('var')).toBe('1'); | ||
expect(shared.get('Var 2')).toBe('2'); | ||
expect(shared.get('Var 3')).toBe('3'); | ||
}); | ||
@@ -84,3 +107,3 @@ }); | ||
const feature = { path: '/features/test.feature', content: `When I throw an exception\nThen the test should pass` }; | ||
const { result } = await lib_1.testWithDefaults([feature], [TestSteps_1.default]); | ||
const result = await (0, lib_1.testWithDefaults)([feature], [TestSteps_1.default]); | ||
expect(result.ok).toBe(false); | ||
@@ -93,3 +116,3 @@ expect(result.results?.length).toBe(1); | ||
const feature = { path: '/features/test.feature', content: `Haibun prose allows mixing text descriptions with a functional test.\n When I have a test\n Then the test should pass\n \nProse sections are indicated by the presence of punctuation at the end of paragraphs.` }; | ||
const { result } = await lib_1.testWithDefaults([feature], [haibun_1.default, TestSteps_1.default]); | ||
const result = await (0, lib_1.testWithDefaults)([feature], [haibun_1.default, TestSteps_1.default]); | ||
expect(result.ok).toBe(true); | ||
@@ -96,0 +119,0 @@ expect(result.results?.length).toBe(1); |
@@ -1,7 +0,10 @@ | ||
import { TWorld, TVStep, AStepper, TProtoOptions } from '../defs'; | ||
import { TWorld, TVStep, TProtoOptions, CStepper, TExpandedFeature } from '../defs'; | ||
import { WorldContext } from '../contexts'; | ||
export declare const HAIBUN_O_TESTSTEPSWITHOPTIONS_EXISTS = "HAIBUN_O_TESTSTEPSWITHOPTIONS_EXISTS"; | ||
export declare function getCreateSteppers(steppers: string[], addSteppers?: CStepper[]): Promise<import("../defs").AStepper[]>; | ||
export declare function getTestEnv(useSteppers: string[], test: string, world: TWorld): Promise<{ | ||
world: TWorld; | ||
vstep: TVStep; | ||
steppers: AStepper[]; | ||
csteppers: CStepper[]; | ||
steppers: import("../defs").AStepper[]; | ||
}>; | ||
@@ -12,5 +15,11 @@ declare type TTestFeatures = { | ||
}[]; | ||
export declare function testWithDefaults(inFeatures: TTestFeatures, addSteppers: typeof AStepper[], protoOptions?: TProtoOptions, inBackgrounds?: TTestFeatures): Promise<{ | ||
result: import("../defs").TResult; | ||
steppers?: AStepper[] | undefined; | ||
export declare function testWithDefaults(inFeatures: TTestFeatures, addSteppers: CStepper[], protoOptions?: TProtoOptions, inBackgrounds?: TTestFeatures): Promise<{ | ||
ok: boolean; | ||
tag: import("../defs").TTag; | ||
shared: WorldContext; | ||
results?: import("../defs").TFeatureResult[] | undefined; | ||
failure?: { | ||
stage: string; | ||
error: import("../defs").TResultError; | ||
} | undefined; | ||
world: TWorld; | ||
@@ -30,3 +39,3 @@ }>; | ||
content: string; | ||
}[]) => any[]; | ||
}[]) => TExpandedFeature[]; | ||
export declare function getDefaultWorld(sequence: number): { | ||
@@ -36,6 +45,7 @@ world: TWorld; | ||
export declare function getDefaultTag(sequence: number, desc?: string | undefined): { | ||
sequence: number; | ||
loop: number; | ||
member: number; | ||
params: any; | ||
sequence: import("../defs").StringOrNumber; | ||
loop: import("../defs").StringOrNumber; | ||
member: import("../defs").StringOrNumber; | ||
featureNum: import("../defs").StringOrNumber; | ||
params: {}; | ||
trace: boolean; | ||
@@ -42,0 +52,0 @@ }; |
@@ -22,3 +22,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getDefaultTag = exports.getDefaultWorld = exports.asExpandedFeatures = exports.asFeatures = exports.testWithDefaults = exports.getTestEnv = exports.HAIBUN_O_TESTSTEPSWITHOPTIONS_EXISTS = void 0; | ||
exports.getDefaultTag = exports.getDefaultWorld = exports.asExpandedFeatures = exports.asFeatures = exports.testWithDefaults = exports.getTestEnv = exports.getCreateSteppers = exports.HAIBUN_O_TESTSTEPSWITHOPTIONS_EXISTS = void 0; | ||
const Resolver_1 = require("../../phases/Resolver"); | ||
@@ -33,10 +33,17 @@ const run_1 = require("./../run"); | ||
exports.HAIBUN_O_TESTSTEPSWITHOPTIONS_EXISTS = 'HAIBUN_O_TESTSTEPSWITHOPTIONS_EXISTS'; | ||
async function getCreateSteppers(steppers, addSteppers) { | ||
const csteppers = await (0, util_1.getSteppers)(steppers); | ||
return await (0, util_1.createSteppers)(csteppers.concat(addSteppers || [])); | ||
} | ||
exports.getCreateSteppers = getCreateSteppers; | ||
async function getTestEnv(useSteppers, test, world) { | ||
const steppers = await util_1.getSteppers({ steppers: useSteppers }); | ||
util_1.applyExtraOptions({}, steppers, world); | ||
domain_1.applyDomainsOrError(steppers, world); | ||
const csteppers = await (0, util_1.getSteppers)(useSteppers); | ||
const steppers = await (0, util_1.createSteppers)(csteppers); | ||
(0, util_1.verifyExtraOptions)({}, csteppers); | ||
world.domains = await (0, domain_1.getDomains)(steppers, world); | ||
(0, domain_1.verifyDomainsOrError)(steppers, world); | ||
const resolver = new Resolver_1.Resolver(steppers, 'all', world); | ||
const actions = resolver.findSteps(test); | ||
const vstep = { | ||
source: { ...features_1.withNameType('test', '') }, | ||
source: { ...(0, features_1.withNameType)('test', '') }, | ||
in: test, | ||
@@ -46,7 +53,7 @@ seq: 0, | ||
}; | ||
return { world, vstep, steppers }; | ||
return { world, vstep, csteppers, steppers }; | ||
} | ||
exports.getTestEnv = getTestEnv; | ||
async function testWithDefaults(inFeatures, addSteppers, protoOptions = run_1.DEF_PROTO_OPTIONS, inBackgrounds = []) { | ||
const specl = util_1.getOptionsOrDefault(); | ||
const specl = (0, util_1.getDefaultOptions)(); | ||
const { options, extraOptions } = protoOptions; | ||
@@ -56,13 +63,14 @@ const { world } = getDefaultWorld(0); | ||
world.options = options; | ||
world.extraOptions = protoOptions.extraOptions; | ||
} | ||
const features = exports.asFeatures(inFeatures); | ||
const backgrounds = exports.asFeatures(inBackgrounds); | ||
return { world, ...await run_1.runWith({ specl, features, backgrounds, addSteppers, world, extraOptions }) }; | ||
const features = (0, exports.asFeatures)(inFeatures); | ||
const backgrounds = (0, exports.asFeatures)(inBackgrounds); | ||
return { world, ...await (0, run_1.runWith)({ specl, features, backgrounds, addSteppers, world }) }; | ||
} | ||
exports.testWithDefaults = testWithDefaults; | ||
const asFeatures = (w) => w.map((i) => features_1.withNameType(i.path, i.content)); | ||
const asFeatures = (w) => w.map((i) => (0, features_1.withNameType)(i.path, i.content)); | ||
exports.asFeatures = asFeatures; | ||
// FIXME can't really do this without reproducing resolve | ||
const asExpandedFeatures = (w) => exports.asFeatures(w).map((i) => { | ||
const expanded = features_1.featureSplit(i.content).map((a) => ({ line: a, feature: i })); | ||
const asExpandedFeatures = (w) => (0, exports.asFeatures)(w).map((i) => { | ||
const expanded = (0, features_1.featureSplit)(i.content).map((a) => ({ line: a, feature: i })); | ||
let a = { ...i, expanded }; | ||
@@ -78,3 +86,3 @@ delete a.content; | ||
timer: new Timer_1.Timer(), | ||
tag: { sequence: 0, loop: 0, member: 0 }, | ||
tag: (0, util_1.getRunTag)(sequence, 0, 0, 0), | ||
shared: new contexts_1.WorldContext(getDefaultTag(sequence)), | ||
@@ -84,3 +92,5 @@ logger: new Logger_1.default(process.env.HAIBUN_LOG_LEVEL ? { level: process.env.HAIBUN_LOG_LEVEL } : Logger_1.LOGGER_NONE), | ||
options: {}, | ||
extraOptions: {}, | ||
domains: [], | ||
base: process.cwd() | ||
}, | ||
@@ -91,5 +101,5 @@ }; | ||
function getDefaultTag(sequence, desc = undefined) { | ||
return util_1.getRunTag(sequence, 0, 0, desc ? { desc } : undefined, false); | ||
return (0, util_1.getRunTag)(sequence, 0, 0, -1, desc ? { desc } : undefined, false); | ||
} | ||
exports.getDefaultTag = getDefaultTag; | ||
//# sourceMappingURL=lib.js.map |
@@ -1,2 +0,2 @@ | ||
import { TNamed } from '../defs'; | ||
import { TNamed, AStepper } from '../defs'; | ||
import { WorkspaceContext } from '../contexts'; | ||
@@ -40,3 +40,3 @@ declare const TestSteps: { | ||
onFailure?(result: import("../defs").TStepResult): void; | ||
setWorld(world: import("../defs").TWorld): void; | ||
setWorld(world: import("../defs").TWorld, steppers: AStepper[]): void; | ||
getWorld(): import("../defs").TWorld; | ||
@@ -43,0 +43,0 @@ }; |
@@ -11,11 +11,11 @@ "use strict"; | ||
exact: 'When I have a test', | ||
action: async (input) => util_1.actionOK(), | ||
action: async (input) => (0, util_1.actionOK)(), | ||
}, | ||
passes: { | ||
exact: 'Then the test should pass', | ||
action: async (input) => util_1.actionOK(), | ||
action: async (input) => (0, util_1.actionOK)(), | ||
}, | ||
fails: { | ||
exact: 'Then the test can fail', | ||
action: async (input) => util_1.actionNotOK('test'), | ||
action: async (input) => (0, util_1.actionNotOK)('test'), | ||
}, | ||
@@ -25,3 +25,3 @@ named: { | ||
action: async ({ param }) => { | ||
return param === 'x' ? util_1.actionOK() : util_1.actionNotOK('test'); | ||
return param === 'x' ? (0, util_1.actionOK)() : (0, util_1.actionNotOK)('test'); | ||
}, | ||
@@ -37,6 +37,6 @@ }, | ||
gwta: 'builds with finalizer', | ||
action: async () => util_1.actionOK(), | ||
action: async () => (0, util_1.actionOK)(), | ||
build: async () => { | ||
return { | ||
...util_1.actionOK(), | ||
...(0, util_1.actionOK)(), | ||
finalize: (workspace) => { | ||
@@ -43,0 +43,0 @@ this.getWorld().shared.set('done', 'ok'); |
@@ -0,1 +1,2 @@ | ||
import { AStepper } from '../defs'; | ||
declare const TestStepsWithDomain: { | ||
@@ -20,3 +21,3 @@ new (): { | ||
onFailure?(result: import("../defs").TStepResult): void; | ||
setWorld(world: import("../defs").TWorld): void; | ||
setWorld(world: import("../defs").TWorld, steppers: AStepper[]): void; | ||
getWorld(): import("../defs").TWorld; | ||
@@ -23,0 +24,0 @@ }; |
@@ -13,3 +13,3 @@ "use strict"; | ||
exact: 'The door is open', | ||
action: async (input) => util_1.actionOK(), | ||
action: async (input) => (0, util_1.actionOK)(), | ||
}, | ||
@@ -16,0 +16,0 @@ }; |
@@ -0,1 +1,2 @@ | ||
import { AStepper } from '../defs'; | ||
declare const TestStepsWithOptions: { | ||
@@ -21,3 +22,3 @@ new (): { | ||
onFailure?(result: import("../defs").TStepResult): void; | ||
setWorld(world: import("../defs").TWorld): void; | ||
setWorld(world: import("../defs").TWorld, steppers: AStepper[]): void; | ||
getWorld(): import("../defs").TWorld; | ||
@@ -24,0 +25,0 @@ }; |
@@ -18,4 +18,4 @@ "use strict"; | ||
action: async () => { | ||
const res = util_1.getStepperOption(this, 'EXISTS', this.getWorld().options); | ||
return util_1.actionOK({ options: { summary: 'options', details: res } }); | ||
const res = (0, util_1.getStepperOption)(this, 'EXISTS', this.getWorld().extraOptions); | ||
return (0, util_1.actionOK)({ options: { summary: 'options', details: res } }); | ||
}, | ||
@@ -22,0 +22,0 @@ }, |
import { WorkspaceContext } from '../lib/contexts'; | ||
import { TResolvedFeature, TWorld } from '../lib/defs'; | ||
import { AStepper, TResolvedFeature, TWorld } from '../lib/defs'; | ||
export default class Builder { | ||
world: any; | ||
workspace: WorkspaceContext; | ||
constructor(world: TWorld, workspace?: WorkspaceContext); | ||
steppers: AStepper[]; | ||
constructor(steppers: AStepper[], world: TWorld, workspace?: WorkspaceContext); | ||
build(features: TResolvedFeature[]): Promise<import("../lib/defs").TOKActionResult>; | ||
} | ||
//# sourceMappingURL=Builder.d.ts.map |
@@ -5,6 +5,7 @@ "use strict"; | ||
const defs_1 = require("../lib/defs"); | ||
const namedVars_1 = require("../lib/namedVars"); | ||
const util_1 = require("../lib/util"); | ||
const Executor_1 = require("./Executor"); | ||
class Builder { | ||
constructor(world, workspace = new contexts_1.WorkspaceContext(`builder`)) { | ||
constructor(steppers, world, workspace = new contexts_1.WorkspaceContext(`builder`)) { | ||
this.steppers = steppers; | ||
this.world = world; | ||
@@ -24,7 +25,6 @@ this.workspace = workspace; | ||
} | ||
const namedWithVars = namedVars_1.getNamedToVars(action, this.world); | ||
const res = await action.step.build(namedWithVars, vstep, this.workspace.get(feature.path)); | ||
const shouldContinue = util_1.applyResShouldContinue(this.world, res, action); | ||
const res = await Executor_1.Executor.action(this.steppers, vstep, vstep.actions[0], this.world); | ||
const shouldContinue = (0, util_1.applyResShouldContinue)(this.world, res, action); | ||
if (!shouldContinue) { | ||
throw Error(`${action.name}: ${res.message}`); | ||
throw Error(`${action.actionName}: ${res.message}`); | ||
} | ||
@@ -31,0 +31,0 @@ if (res.finalize) { |
@@ -10,23 +10,4 @@ "use strict"; | ||
const Builder_1 = __importDefault(require("./Builder")); | ||
const feature = (result) => ({ | ||
path: 'passes.feature', | ||
feature: 'test', | ||
vsteps: [ | ||
{ | ||
in: 'test', | ||
seq: 0, | ||
actions: [ | ||
{ | ||
name: 'test', | ||
step: { | ||
exact: 'test', | ||
action: async () => defs_1.OK, | ||
build: result, | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}); | ||
describe('Builder', () => { | ||
describe('Builder', async () => { | ||
const steppers = await (0, lib_1.getCreateSteppers)([]); | ||
test('throws', () => { | ||
@@ -36,3 +17,3 @@ const throws = async () => { | ||
}; | ||
const builder = new Builder_1.default(lib_1.getDefaultWorld(0).world); | ||
const builder = new Builder_1.default(steppers, (0, lib_1.getDefaultWorld)(0).world); | ||
// expect(async () => await builder.build([feature(throws)])).rejects.toThrow('fails'); | ||
@@ -42,3 +23,3 @@ }); | ||
const throws = async () => defs_1.OK; | ||
const builder = new Builder_1.default(lib_1.getDefaultWorld(0).world); | ||
const builder = new Builder_1.default(steppers, (0, lib_1.getDefaultWorld)(0).world); | ||
// const res = await builder.build([feature(throws)]); | ||
@@ -51,3 +32,3 @@ // expect(res).toBe(OK); | ||
const workspace = new contexts_1.WorkspaceContext(`test builder finalizes`); | ||
const builder = new Builder_1.default(lib_1.getDefaultWorld(0).world, workspace); | ||
const builder = new Builder_1.default(steppers, (0, lib_1.getDefaultWorld)(0).world, workspace); | ||
// await builder.build([feature(finalizes)]); | ||
@@ -54,0 +35,0 @@ // expect(workspace['passes.feature'].done).toBe(true); |
@@ -1,13 +0,19 @@ | ||
import { TVStep, TResolvedFeature, TResult, TStepResult, TFeatureResult, TWorld, AStepper } from '../lib/defs'; | ||
import { TVStep, TResolvedFeature, TResult, TStepResult, TFeatureResult, TActionResult, TWorld, AStepper, TendFeatureCallback, CStepper, TFound } from '../lib/defs'; | ||
export declare class Executor { | ||
steppers: AStepper[]; | ||
world: TWorld; | ||
constructor(steppers: AStepper[], world: TWorld); | ||
execute(features: TResolvedFeature[]): Promise<TResult>; | ||
static action(steppers: AStepper[], vstep: TVStep, a: TFound, world: TWorld): Promise<Partial<TActionResult>>; | ||
static execute(csteppers: CStepper[], world: TWorld, features: TResolvedFeature[], endFeatureCallback?: TendFeatureCallback): Promise<TResult>; | ||
} | ||
export declare class FeatureExecutor { | ||
csteppers: CStepper[]; | ||
endFeatureCallback?: TendFeatureCallback; | ||
world?: TWorld; | ||
steppers?: AStepper[]; | ||
constructor(csteppers: CStepper[], endFeatureCallback?: TendFeatureCallback); | ||
setup(world: TWorld): Promise<void>; | ||
doFeature(feature: TResolvedFeature): Promise<TFeatureResult>; | ||
static doFeatureStep(vstep: TVStep, world: TWorld): Promise<TStepResult>; | ||
static doFeatureStep(steppers: AStepper[], vstep: TVStep, world: TWorld): Promise<TStepResult>; | ||
onFailure(result: TStepResult): Promise<void>; | ||
endFeature(): Promise<void>; | ||
endFeature(featureResult: TFeatureResult): Promise<void>; | ||
close(): Promise<void>; | ||
} | ||
//# sourceMappingURL=Executor.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Executor = void 0; | ||
exports.FeatureExecutor = exports.Executor = void 0; | ||
const namedVars_1 = require("../lib/namedVars"); | ||
const util_1 = require("../lib/util"); | ||
class Executor { | ||
constructor(steppers, world) { | ||
this.steppers = steppers; | ||
this.world = world; | ||
// find the stepper and action, call it and return its result | ||
static async action(steppers, vstep, a, world) { | ||
try { | ||
const namedWithVars = (0, namedVars_1.getNamedToVars)(a, world); | ||
const stepper = (0, util_1.findStepper)(steppers, a.stepperName); | ||
return await stepper.steps[a.actionName].action(namedWithVars, vstep); | ||
} | ||
catch (caught) { | ||
world.logger.error(caught.stack); | ||
return (0, util_1.actionNotOK)(`in ${vstep.in}: ${caught.message}`, { topics: { caught: caught.stack.toString() } }); | ||
} | ||
} | ||
async execute(features) { | ||
static async execute(csteppers, world, features, endFeatureCallback) { | ||
let ok = true; | ||
const stay = (this.world.options.STAY === 'always'); | ||
const stay = (world.options.stay === 'always'); | ||
let featureResults = []; | ||
// FIXME | ||
this.world.shared.values._features = features; | ||
this.world.shared.values._scored = []; | ||
// FIXME scoring hack | ||
world.shared.values._features = features; | ||
world.shared.values._scored = []; | ||
let featureNum = 0; | ||
for (const feature of features) { | ||
this.world.logger.log(`*** feature: ${feature.path}`); | ||
const featureResult = await this.doFeature(feature); | ||
featureNum++; | ||
const newWorld = { ...world, tag: { ...world.tag, ...{ featureNum: 0 + featureNum } } }; | ||
const featureExecutor = new FeatureExecutor(csteppers, endFeatureCallback); | ||
await featureExecutor.setup(newWorld); | ||
const featureResult = await featureExecutor.doFeature(feature); | ||
ok = ok && featureResult.ok; | ||
if (!stay) { | ||
await featureExecutor.endFeature(featureResult); | ||
} | ||
featureResults.push(featureResult); | ||
if (!stay) { | ||
await this.endFeature(); | ||
await featureExecutor.close(); | ||
} | ||
} | ||
if (!stay) { | ||
await this.close(); | ||
} | ||
return { ok, results: featureResults, tag: this.world.tag }; | ||
return { ok, results: featureResults, tag: world.tag, shared: world.shared }; | ||
} | ||
} | ||
exports.Executor = Executor; | ||
class FeatureExecutor { | ||
constructor(csteppers, endFeatureCallback) { | ||
this.csteppers = csteppers; | ||
this.endFeatureCallback = endFeatureCallback; | ||
} | ||
async setup(world) { | ||
this.world = world; | ||
const errorBail = (phase, error, extra) => { | ||
console.error('error', phase, error, extra); | ||
throw Error(error); | ||
}; | ||
const steppers = await (0, util_1.createSteppers)(this.csteppers); | ||
await (0, util_1.setWorldStepperOptions)(steppers, world).catch((error) => errorBail('Apply Options', error, world.extraOptions)); | ||
this.steppers = steppers; | ||
} | ||
async doFeature(feature) { | ||
const world = this.world; | ||
world.logger.log(`*** feature ${world.tag.featureNum}: ${feature.path}`); | ||
let ok = true; | ||
@@ -37,6 +68,6 @@ let stepResults = []; | ||
for (const step of feature.vsteps) { | ||
this.world.logger.log(` ${step.in}\r`); | ||
const result = await Executor.doFeatureStep(step, this.world); | ||
if (this.world.options.step_delay) { | ||
await util_1.sleep(this.world.options.step_delay); | ||
world.logger.log(` ${step.in}\r`); | ||
const result = await FeatureExecutor.doFeatureStep(this.steppers, step, world); | ||
if (world.options.step_delay) { | ||
await (0, util_1.sleep)(world.options.step_delay); | ||
} | ||
@@ -47,4 +78,3 @@ ok = ok && result.ok; | ||
} | ||
const topics = result.actionResults.reduce((all, a) => ({ ...all, ...a.topics }), {}); | ||
this.world.logger.log(ok, { topic: { stage: 'Executor', seq, result } }); | ||
world.logger.log(ok, { topic: { stage: 'Executor', seq, result } }); | ||
stepResults.push(result); | ||
@@ -59,3 +89,3 @@ if (!ok) { | ||
} | ||
static async doFeatureStep(vstep, world) { | ||
static async doFeatureStep(steppers, vstep, world) { | ||
let ok = true; | ||
@@ -66,11 +96,4 @@ let actionResults = []; | ||
const start = world.timer.since(); | ||
let res; | ||
try { | ||
const namedWithVars = namedVars_1.getNamedToVars(a, world); | ||
res = await a.step.action(namedWithVars, vstep); | ||
} | ||
catch (caught) { | ||
world.logger.error(caught.stack); | ||
res = util_1.actionNotOK(`in ${vstep.in}: ${caught.message}`, { topics: { caught: caught.stack.toString() } }); | ||
} | ||
const res = await Executor.action(steppers, vstep, a, world); | ||
; | ||
let traces; | ||
@@ -83,5 +106,5 @@ if (world.shared.get('_trace')) { | ||
// FIXME | ||
const stepResult = { ...res, name: a.name, start, end, traces }; | ||
const stepResult = { ...res, name: a.actionName, start, end, traces }; | ||
actionResults.push(stepResult); | ||
const shouldContinue = util_1.applyResShouldContinue(world, res, a); | ||
const shouldContinue = (0, util_1.applyResShouldContinue)(world, res, a); | ||
ok = ok && shouldContinue; | ||
@@ -102,3 +125,3 @@ if (!shouldContinue) { | ||
} | ||
async endFeature() { | ||
async endFeature(featureResult) { | ||
for (const s of this.steppers) { | ||
@@ -110,2 +133,11 @@ if (s.endFeature) { | ||
} | ||
if (this.endFeatureCallback) { | ||
try { | ||
await this.endFeatureCallback(this.world, featureResult, this.steppers); | ||
} | ||
catch (error) { | ||
console.log('e', error); | ||
throw Error(error); | ||
} | ||
} | ||
} | ||
@@ -121,3 +153,3 @@ async close() { | ||
} | ||
exports.Executor = Executor; | ||
exports.FeatureExecutor = FeatureExecutor; | ||
//# sourceMappingURL=Executor.js.map |
@@ -21,2 +21,3 @@ "use strict"; | ||
catch (e) { | ||
this.world.logger.error(e); | ||
throw e; | ||
@@ -29,3 +30,3 @@ } | ||
const vsteps = feature.expanded.map((featureLine, seq) => { | ||
const actionable = util_1.getActionable(featureLine.line); | ||
const actionable = (0, util_1.getActionable)(featureLine.line); | ||
const actions = this.findSteps(actionable); | ||
@@ -40,6 +41,6 @@ try { | ||
if (actions.length > 1) { | ||
throw Error(`more than one step found for "${featureLine.line}" ${JSON.stringify(actions.map(a => a.name))}`); | ||
throw Error(`more than one step found for "${featureLine.line}" ${JSON.stringify(actions.map(a => a.actionName))}`); | ||
} | ||
else if (actions.length < 1 && this.mode !== 'some') { | ||
throw Error(`no step found for ${featureLine.line} in ${feature.path} from ${util_1.describeSteppers(this.steppers)}`); | ||
throw Error(`no step found for ${featureLine.line} in ${feature.path} from ${(0, util_1.describeSteppers)(this.steppers)}`); | ||
} | ||
@@ -56,18 +57,20 @@ return { source: featureLine.feature, in: featureLine.line, seq, actions }; | ||
const types = [...defs_1.BASE_TYPES, ...this.world.domains.map((d) => d.name)]; | ||
for (const { steps } of this.steppers) { | ||
for (const name in steps) { | ||
const step = steps[name]; | ||
for (const stepper of this.steppers) { | ||
const stepperName = stepper.constructor.name; | ||
const { steps } = stepper; | ||
for (const actionName in steps) { | ||
const step = steps[actionName]; | ||
const addIfMatch = (m) => m && found.push(m); | ||
if (step.gwta) { | ||
let { str, vars } = namedVars_1.namedInterpolation(step.gwta, types); | ||
let { str, vars } = (0, namedVars_1.namedInterpolation)(step.gwta, types); | ||
const f = str.charAt(0); | ||
const s = util_1.isLowerCase(f) ? ['[', f, f.toUpperCase(), ']', str.substring(1)].join('') : str; | ||
const s = (0, util_1.isLowerCase)(f) ? ['[', f, f.toUpperCase(), ']', str.substring(1)].join('') : str; | ||
const r = new RegExp(`^(Given|When|Then|And)?( the )?( I('m)? (am )?)? ?${s}`); | ||
addIfMatch(namedVars_1.getMatch(actionable, r, name, step, vars)); | ||
addIfMatch((0, namedVars_1.getMatch)(actionable, r, actionName, stepperName, step, vars)); | ||
} | ||
else if (step.match) { | ||
addIfMatch(namedVars_1.getMatch(actionable, step.match, name, step)); | ||
addIfMatch((0, namedVars_1.getMatch)(actionable, step.match, actionName, stepperName, step)); | ||
} | ||
else if (actionable.length > 0 && step.exact === actionable) { | ||
found.push({ name, step }); | ||
found.push({ actionName, stepperName, step }); | ||
} | ||
@@ -85,3 +88,4 @@ } | ||
const comment = { | ||
name: 'comment', | ||
stepperName: 'Haibun', | ||
actionName: 'comment', | ||
step: { | ||
@@ -88,0 +92,0 @@ match: /.*/, |
@@ -5,2 +5,3 @@ "use strict"; | ||
const lib_1 = require("../lib/test/lib"); | ||
const util_1 = require("../lib/util"); | ||
const Resolver_1 = require("./Resolver"); | ||
@@ -31,10 +32,13 @@ describe('validate map steps', () => { | ||
} | ||
const steppers = [new TestStepper()]; | ||
const getResolver = () => new Resolver_1.Resolver(steppers, '', { | ||
...lib_1.getDefaultWorld(0).world, | ||
}); | ||
const getResolvedSteps = async (features) => { | ||
const steppers = await (0, util_1.createSteppers)([TestStepper]); | ||
const resolver = new Resolver_1.Resolver(steppers, '', { | ||
...(0, lib_1.getDefaultWorld)(0).world, | ||
}); | ||
return await resolver.resolveSteps(features); | ||
}; | ||
describe('exact', () => { | ||
test('exact', async () => { | ||
const features = lib_1.asExpandedFeatures([{ path: 'l1', content: `exact1` }]); | ||
const res = await getResolver().resolveSteps(features); | ||
const features = (0, lib_1.asExpandedFeatures)([{ path: 'l1', content: `exact1` }]); | ||
const res = await getResolvedSteps(features); | ||
const { vsteps } = res[0]; | ||
@@ -46,4 +50,4 @@ expect(vsteps[0].actions[0].named).toBeUndefined(); | ||
test('match', async () => { | ||
const features = lib_1.asExpandedFeatures([{ path: 'l1', content: `match1` }]); | ||
const res = await getResolver().resolveSteps(features); | ||
const features = (0, lib_1.asExpandedFeatures)([{ path: 'l1', content: `match1` }]); | ||
const res = await getResolvedSteps(features); | ||
const { vsteps } = res[0]; | ||
@@ -55,4 +59,4 @@ expect(vsteps[0].actions[0].named).toEqual({ num: '1' }); | ||
test('gwta', async () => { | ||
const features = lib_1.asExpandedFeatures([{ path: 'l1', content: `gwta2\nGiven I'm gwta3\nWhen I am gwta4\nGwta5\nThen the gwta6` }]); | ||
const res = await getResolver().resolveSteps(features); | ||
const features = (0, lib_1.asExpandedFeatures)([{ path: 'l1', content: `gwta2\nGiven I'm gwta3\nWhen I am gwta4\nGwta5\nThen the gwta6` }]); | ||
const res = await getResolvedSteps(features); | ||
const { vsteps } = res[0]; | ||
@@ -68,4 +72,4 @@ expect(vsteps[0].actions[0].named).toEqual({ num: '2' }); | ||
test('gets quoted', async () => { | ||
const features = lib_1.asExpandedFeatures([{ path: 'l1', content: 'is "string"' }]); | ||
const res = await getResolver().resolveSteps(features); | ||
const features = (0, lib_1.asExpandedFeatures)([{ path: 'l1', content: 'is "string"' }]); | ||
const res = await getResolvedSteps(features); | ||
const { vsteps } = res[0]; | ||
@@ -75,4 +79,4 @@ expect(vsteps[0].actions[0].named?.q_0).toEqual('string'); | ||
test('gets uri', async () => { | ||
const features = lib_1.asExpandedFeatures([{ path: 'l1', content: 'is http://url' }]); | ||
const res = await getResolver().resolveSteps(features); | ||
const features = (0, lib_1.asExpandedFeatures)([{ path: 'l1', content: 'is http://url' }]); | ||
const res = await getResolvedSteps(features); | ||
const { vsteps } = res[0]; | ||
@@ -79,0 +83,0 @@ expect(vsteps[0].actions[0].named?.t_0).toEqual('http://url'); |
@@ -0,1 +1,2 @@ | ||
import { AStepper } from '../lib/defs'; | ||
declare const Conformance: { | ||
@@ -13,3 +14,3 @@ new (): { | ||
onFailure?(result: import("../lib/defs").TStepResult): void; | ||
setWorld(world: import("../lib/defs").TWorld): void; | ||
setWorld(world: import("../lib/defs").TWorld, steppers: AStepper[]): void; | ||
getWorld(): import("../lib/defs").TWorld; | ||
@@ -16,0 +17,0 @@ }; |
@@ -11,3 +11,3 @@ "use strict"; | ||
match: /(?!\n|. )\b([A-Z].*? must .*?\.)/, | ||
action: async (input) => util_1.actionNotOK('not implemented'), | ||
action: async (input) => (0, util_1.actionNotOK)('not implemented'), | ||
}, | ||
@@ -14,0 +14,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
import { TNamed } from '../lib/defs'; | ||
import { TNamed, AStepper } from '../lib/defs'; | ||
export declare const cred: (key: string) => string; | ||
@@ -22,3 +22,3 @@ declare const Credentials: { | ||
onFailure?(result: import("../lib/defs").TStepResult): void; | ||
setWorld(world: import("../lib/defs").TWorld): void; | ||
setWorld(world: import("../lib/defs").TWorld, steppers: AStepper[]): void; | ||
getWorld(): import("../lib/defs").TWorld; | ||
@@ -25,0 +25,0 @@ }; |
@@ -28,7 +28,7 @@ "use strict"; | ||
generateRandomUsername(ref) { | ||
this.getWorld().shared.set(exports.cred(ref), ['rnd', Math.floor(Date.now() / 1000).toString(36), Math.floor(Math.random() * 1e8).toString(36)].join('_')); | ||
return this.getWorld().shared.get(exports.cred(ref)); | ||
this.getWorld().shared.set((0, exports.cred)(ref), ['rnd', Math.floor(Date.now() / 1000).toString(36), Math.floor(Math.random() * 1e8).toString(36)].join('_')); | ||
return this.getWorld().shared.get((0, exports.cred)(ref)); | ||
} | ||
generateRandomPassword(ref) { | ||
this.getWorld().shared.set(exports.cred(ref), [ | ||
this.getWorld().shared.set((0, exports.cred)(ref), [ | ||
'testpass', | ||
@@ -39,6 +39,6 @@ Math.floor(Math.random() * 1e8) | ||
].join('_')); | ||
return this.getWorld().shared.get(exports.cred(ref)); | ||
return this.getWorld().shared.get((0, exports.cred)(ref)); | ||
} | ||
getRandom(name) { | ||
return this.getWorld().shared.get(exports.cred(name)); | ||
return this.getWorld().shared.get((0, exports.cred)(name)); | ||
} | ||
@@ -45,0 +45,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
import { TNamed } from '../lib/defs'; | ||
import { TNamed, AStepper } from '../lib/defs'; | ||
declare const Haibun: { | ||
@@ -17,2 +17,6 @@ new (): { | ||
}; | ||
fails: { | ||
gwta: string; | ||
action: ({ message }: TNamed) => Promise<import("../lib/defs").TNotOKActionResult>; | ||
}; | ||
stopStepDelay: { | ||
@@ -26,2 +30,6 @@ gwta: string; | ||
}; | ||
showTag: { | ||
gwta: string; | ||
action: ({ which }: TNamed) => Promise<import("../lib/defs").TOKActionResult>; | ||
}; | ||
pauseSeconds: { | ||
@@ -31,2 +39,6 @@ gwta: string; | ||
}; | ||
comment: { | ||
gwta: string; | ||
action: ({ comment }: TNamed) => Promise<import("../lib/defs").TOKActionResult>; | ||
}; | ||
}; | ||
@@ -37,3 +49,3 @@ world?: import("../lib/defs").TWorld | undefined; | ||
onFailure?(result: import("../lib/defs").TStepResult): void; | ||
setWorld(world: import("../lib/defs").TWorld): void; | ||
setWorld(world: import("../lib/defs").TWorld, steppers: AStepper[]): void; | ||
getWorld(): import("../lib/defs").TWorld; | ||
@@ -40,0 +52,0 @@ }; |
@@ -16,3 +16,3 @@ "use strict"; | ||
action: async () => { | ||
return util_1.actionOK({ features: this.getWorld().shared.values._features }); | ||
return (0, util_1.actionOK)({ features: this.getWorld().shared.values._features }); | ||
}, | ||
@@ -27,2 +27,8 @@ }, | ||
}, | ||
fails: { | ||
gwta: `fails with {message}`, | ||
action: async ({ message }) => { | ||
return (0, util_1.actionNotOK)(`fails: ${message}`); | ||
}, | ||
}, | ||
stopStepDelay: { | ||
@@ -41,2 +47,10 @@ gwta: 'stop step delay', | ||
}, | ||
showTag: { | ||
gwta: 'show stepper tag {which}', | ||
action: async ({ which }) => { | ||
const what = which ? this.getWorld().tag[which] : this.getWorld().tag; | ||
this.world?.logger.log(`tag ${which}: ${JSON.stringify(what)}`); | ||
return defs_1.OK; | ||
}, | ||
}, | ||
pauseSeconds: { | ||
@@ -46,6 +60,13 @@ gwta: 'pause for {ms}s', | ||
const seconds = parseInt(ms, 10) * 1000; | ||
await util_1.sleep(seconds); | ||
await (0, util_1.sleep)(seconds); | ||
return defs_1.OK; | ||
}, | ||
}, | ||
comment: { | ||
gwta: '#{what}', | ||
action: async ({ comment }) => { | ||
this.getWorld().logger.log(`comment: ${comment}`); | ||
return defs_1.OK; | ||
} | ||
} | ||
}; | ||
@@ -52,0 +73,0 @@ } |
@@ -7,4 +7,4 @@ "use strict"; | ||
it('finds prose', async () => { | ||
const { world, vstep } = await lib_1.getTestEnv(['haibun'], 'A sentence.', lib_1.getDefaultWorld(0).world); | ||
const res = await Executor_1.Executor.doFeatureStep(vstep, world); | ||
const { world, vstep, steppers } = await (0, lib_1.getTestEnv)(['haibun'], 'A sentence.', (0, lib_1.getDefaultWorld)(0).world); | ||
const res = await Executor_1.FeatureExecutor.doFeatureStep(steppers, vstep, world); | ||
expect(res.ok).toBe(true); | ||
@@ -11,0 +11,0 @@ expect(res.actionResults[0].name).toBe('prose'); |
import { Context } from '../lib/contexts'; | ||
import { TNamed, TVStep, TWorld } from '../lib/defs'; | ||
import { TNamed, TVStep, TWorld, AStepper } from '../lib/defs'; | ||
declare const vars: { | ||
@@ -71,3 +71,3 @@ new (): { | ||
onFailure?(result: import("../lib/defs").TStepResult): void; | ||
setWorld(world: TWorld): void; | ||
setWorld(world: TWorld, steppers: AStepper[]): void; | ||
getWorld(): TWorld; | ||
@@ -74,0 +74,0 @@ }; |
@@ -16,3 +16,3 @@ "use strict"; | ||
const emptyOnly = !!vstep.in.match(/set empty /); | ||
return exports.setShared(named, vstep, this.getWorld(), emptyOnly); | ||
return (0, exports.setShared)(named, vstep, this.getWorld(), emptyOnly); | ||
}; | ||
@@ -75,3 +75,3 @@ this.steps = { | ||
} | ||
return util_1.actionNotOK(`${what} not set${orCond && ': ' + orCond}`, { score: 10, topics }); | ||
return (0, util_1.actionNotOK)(`${what} not set${orCond && ': ' + orCond}`, { score: 10, topics }); | ||
} | ||
@@ -85,3 +85,3 @@ }; | ||
const { type, name } = vstep.source; | ||
let shared = domain_1.getStepShared(type, world); | ||
let shared = (0, domain_1.getStepShared)(type, world); | ||
if (shared instanceof contexts_1.DomainContext) { | ||
@@ -95,3 +95,3 @@ const dc = shared; | ||
} | ||
return { ...defs_1.OK, topics: { ...exports.didNotOverwrite(what, shared.get(what), value) } }; | ||
return { ...defs_1.OK, topics: { ...(0, exports.didNotOverwrite)(what, shared.get(what), value) } }; | ||
}; | ||
@@ -103,3 +103,3 @@ exports.setShared = setShared; | ||
world.shared.setDomainValues(type, name); | ||
const domain = domain_1.getDomain(type, world); | ||
const domain = (0, domain_1.getDomain)(type, world); | ||
const page = domain?.shared.get(name); | ||
@@ -106,0 +106,0 @@ if (!page) { |
@@ -8,34 +8,34 @@ "use strict"; | ||
describe('vars', () => { | ||
it('assigns', async () => { | ||
const { world, vstep } = await lib_1.getTestEnv(['vars'], 'set x to y', lib_1.getDefaultWorld(0).world); | ||
await Executor_1.Executor.doFeatureStep(vstep, world); | ||
it.only('assigns', async () => { | ||
const { world, vstep, steppers } = await (0, lib_1.getTestEnv)(['vars'], 'set x to y', (0, lib_1.getDefaultWorld)(0).world); | ||
await Executor_1.FeatureExecutor.doFeatureStep(steppers, vstep, world); | ||
expect(world.shared.get('x')).toBe('y'); | ||
}); | ||
it('assigns empty', async () => { | ||
const { world, vstep } = await lib_1.getTestEnv(['vars'], 'set empty "x" to y', lib_1.getDefaultWorld(0).world); | ||
await Executor_1.Executor.doFeatureStep(vstep, world); | ||
const { world, vstep, steppers } = await (0, lib_1.getTestEnv)(['vars'], 'set empty "x" to y', (0, lib_1.getDefaultWorld)(0).world); | ||
await Executor_1.FeatureExecutor.doFeatureStep(steppers, vstep, world); | ||
expect(world.shared.get('x')).toBe('y'); | ||
}); | ||
it('empty does not overwrite', async () => { | ||
const { world, vstep } = await lib_1.getTestEnv(['vars'], 'set empty "x" to newValue', { | ||
...lib_1.getDefaultWorld(0).world, | ||
shared: new contexts_1.WorldContext(lib_1.getDefaultTag(0, 'test vars empty does not overwrite'), { x: 'notY' }), | ||
const { world, vstep, steppers } = await (0, lib_1.getTestEnv)(['vars'], 'set empty "x" to newValue', { | ||
...(0, lib_1.getDefaultWorld)(0).world, | ||
shared: new contexts_1.WorldContext((0, lib_1.getDefaultTag)(0, 'test vars empty does not overwrite'), { x: 'notY' }), | ||
}); | ||
const res = await Executor_1.Executor.doFeatureStep(vstep, world); | ||
const res = await Executor_1.FeatureExecutor.doFeatureStep(steppers, vstep, world); | ||
expect(world.shared.get('x')).toBe('notY'); | ||
expect(res.actionResults[0].topics).toEqual({ ...vars_1.didNotOverwrite('x', 'notY', 'newValue') }); | ||
expect(res.actionResults[0].topics).toEqual({ ...(0, vars_1.didNotOverwrite)('x', 'notY', 'newValue') }); | ||
}); | ||
it('is not set', async () => { | ||
const { world, vstep } = await lib_1.getTestEnv(['vars'], '"x 1" is set', { ...lib_1.getDefaultWorld(0).world }); | ||
const res = await Executor_1.Executor.doFeatureStep(vstep, world); | ||
const { world, vstep, steppers } = await (0, lib_1.getTestEnv)(['vars'], '"x 1" is set', { ...(0, lib_1.getDefaultWorld)(0).world }); | ||
const res = await Executor_1.FeatureExecutor.doFeatureStep(steppers, vstep, world); | ||
expect(res.ok).toBe(false); | ||
}); | ||
it('is set', async () => { | ||
const { world, vstep } = await lib_1.getTestEnv(['vars'], '"x 1" is set', { ...lib_1.getDefaultWorld(0).world, shared: new contexts_1.WorldContext(lib_1.getDefaultTag(0, 'is set'), { 'x 1': '1' }) }); | ||
const res = await Executor_1.Executor.doFeatureStep(vstep, world); | ||
const { world, vstep, steppers } = await (0, lib_1.getTestEnv)(['vars'], '"x 1" is set', { ...(0, lib_1.getDefaultWorld)(0).world, shared: new contexts_1.WorldContext((0, lib_1.getDefaultTag)(0, 'is set'), { 'x 1': '1' }) }); | ||
const res = await Executor_1.FeatureExecutor.doFeatureStep(steppers, vstep, world); | ||
expect(res.ok).toBe(true); | ||
}); | ||
it('is set with or', async () => { | ||
const { world, vstep } = await lib_1.getTestEnv(['vars'], '"x 1" is set or do something', { ...lib_1.getDefaultWorld(0).world }); | ||
const res = await Executor_1.Executor.doFeatureStep(vstep, world); | ||
const { world, vstep, steppers } = await (0, lib_1.getTestEnv)(['vars'], '"x 1" is set or do something', { ...(0, lib_1.getDefaultWorld)(0).world }); | ||
const res = await Executor_1.FeatureExecutor.doFeatureStep(steppers, vstep, world); | ||
expect(res.ok).toBe(false); | ||
@@ -42,0 +42,0 @@ expect(res.actionResults[0].message).toBe('x 1 not set: do something'); |
{ | ||
"name": "@haibun/core", | ||
"version": "1.2.4", | ||
"version": "1.5.0", | ||
"description": "", | ||
@@ -22,2 +22,3 @@ "author": "", | ||
"jest": "^27.0.4", | ||
"node-notifier": "^10.0.1", | ||
"prettier": "^2.3.1", | ||
@@ -42,3 +43,6 @@ "ts-jest": "^27.0.3", | ||
"version": "npm run format && git add -A src" | ||
}, | ||
"dependencies": { | ||
"source-map-support": "^0.5.21" | ||
} | ||
} |
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
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
272849
153
3639
1
16
9
+ Addedsource-map-support@^0.5.21
+ Addedbuffer-from@1.1.2(transitive)
+ Addedsource-map@0.6.1(transitive)
+ Addedsource-map-support@0.5.21(transitive)