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

feynman

Package Overview
Dependencies
Maintainers
4
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

feynman - npm Package Compare versions

Comparing version 0.0.16 to 0.0.17

25

lib/feynman/core.js
'use strict'
const sentenceCase = require('sentence-case')
/*

@@ -44,3 +46,4 @@ * Actor - attempts actions using its abilities, it knows how to perform

const Task = (id, description, args, fn) => {
const Task = (id, args, fn) => {
const description = sentenceCase(id)
const nestedTasks = []

@@ -52,5 +55,9 @@ const task = (..._params) => {

)
const actionDescription = [description]
.concat(Object.values(params).map(value => `'${value}'`))
.join(' ')
const action = {
id,
params,
description: actionDescription,
}

@@ -61,2 +68,6 @@ nestedTasks.forEach(NestedTask => {

const nestedAction = NestedTask(...args)
nestedAction.description = [actionDescription]
.concat(sentenceCase(nestedTaskName).toLowerCase())
.concat(Object.values(nestedAction.params).map(value => `'${value}'`))
.join(' ')
nestedAction.params = { ...action.params, ...nestedAction.params }

@@ -73,13 +84,9 @@ return nestedAction

if (fn)
fn((id, description, _args, fn) => {
const NestedTask = Task(
`${task.id}.${id}`,
`${task.description} ${description}`,
{ ...args, ..._args },
fn
)
if (fn) {
fn((id, _args, fn) => {
const NestedTask = Task(`${task.id}.${id}`, { ...args, ..._args }, fn)
task[id] = NestedTask
nestedTasks.push(NestedTask)
})
}

@@ -86,0 +93,0 @@ return task

@@ -10,10 +10,5 @@ 'use strict'

it('defines a standalone task with some args', () => {
const StandaloneTask = Task(
'StandaloneTask',
'A task that stands alone',
['arg']
)
const StandaloneTask = Task('StandaloneTask', ['arg'])
assert(typeof StandaloneTask === 'function')
assert.equal(StandaloneTask.id, 'StandaloneTask')
assert.equal(StandaloneTask.description, 'A task that stands alone')
const action = StandaloneTask('value')

@@ -25,8 +20,7 @@ assert.equal(action.id, 'StandaloneTask')

it('nests tasks', () => {
const RootTask = Task('RootTask', 'The root task', ['rootArg'], Task =>
Task('NestedTask', 'with a nested task', ['nestedArg'])
const RootTask = Task('RootTask', ['rootArg'], Task =>
Task('NestedTask', ['nestedArg'])
)
assert(typeof RootTask === 'function')
assert.equal(RootTask.id, 'RootTask')
assert.equal(RootTask.description, 'The root task')

@@ -38,6 +32,2 @@ const action = RootTask('root-value')

assert.equal(RootTask.NestedTask.id, 'RootTask.NestedTask')
assert.equal(
RootTask.NestedTask.description,
'The root task with a nested task'
)

@@ -53,7 +43,5 @@ const nestedAction = RootTask('root-value').NestedTask('nested-value')

it('deeply nests tasks', () => {
const RootTask = Task('RootTask', 'The root task', ['rootArg'], Task =>
Task('NestedTask', 'with a nested task', ['nestedArg'], Task =>
Task('DeeplyNestedTask', 'with a deeply nested task', [
'deeplyNestedArg',
])
const RootTask = Task('RootTask', ['rootArg'], Task =>
Task('NestedTask', ['nestedArg'], Task =>
Task('DeeplyNestedTask', ['deeplyNestedArg'])
)

@@ -77,7 +65,5 @@ )

it('deeply nests tasks without calling the root task', () => {
const RootTask = Task('RootTask', 'The root task', [], Task =>
Task('NestedTask', 'with a nested task', ['nestedArg'], Task =>
Task('DeeplyNestedTask', 'with a deeply nested task', [
'deeplyNestedArg',
])
const RootTask = Task('RootTask', [], Task =>
Task('NestedTask', ['nestedArg'], Task =>
Task('DeeplyNestedTask', ['deeplyNestedArg'])
)

@@ -100,7 +86,5 @@ )

it('allows for sibling nested tasks', () => {
const RootTask = Task('RootTask', 'The root task', [], Task => {
Task('NestedTask', 'with a nested task', ['nestedArg'])
Task('SiblingNestedTask', 'with a sibling nested task', [
'siblingNestedArg',
])
const RootTask = Task('RootTask', [], Task => {
Task('NestedTask', ['nestedArg'])
Task('SiblingNestedTask', ['siblingNestedArg'])
})

@@ -120,2 +104,26 @@

})
it('infers a description for a task', () => {
const CreateUser = Task('CreateUser', [], Task => {
Task('named', ['userName'])
})
assert.equal(CreateUser.named.description, 'Create user named')
assert.equal(
CreateUser.named('matt').description,
"Create user named 'matt'"
)
})
it('infers a description for a nested task', () => {
const CreateUser = Task('CreateUser', [], Task => {
Task('named', ['userName'], Task => {
Task('withBacon', ['flavour'])
})
})
assert.equal(CreateUser.named.description, 'Create user named')
assert.equal(
CreateUser.named('matt').withBacon('smoked').description,
"Create user named 'matt' with bacon 'smoked'"
)
})
})

@@ -129,5 +137,3 @@

const abilities = { browser }
const Refresh = Task('Refresh', 'Refresh', [], Task =>
Task('browser', 'the browser', [])
)
const Refresh = Task('Refresh', [], Task => Task('browser', []))
const perspective = Perspective('web browser', handle => {

@@ -148,5 +154,3 @@ handle(Refresh.browser, () => ({ browser }) => {

const abilities = { browser }
const ClickOn = Task('ClickOn', 'Click on', [], Task =>
Task('button', 'button with $text', ['text'])
)
const ClickOn = Task('ClickOn', [], Task => Task('button', ['text']))

@@ -168,6 +172,4 @@ const perspective = Perspective('web browser', handle => {

const abilities = { browser }
const FillIn = Task('FillIn', 'Fill in', [], Task =>
Task('label', 'label $name', ['name'], Task =>
Task('with', 'with $text', ['text'])
)
const FillIn = Task('FillIn', [], Task =>
Task('label', ['name'], Task => Task('with', ['text']))
)

@@ -189,4 +191,4 @@ const perspective = Perspective('web browser', handle => {

actor.attemptsTo(Book.aRoom, Book.aFlight(destination)),
aRoom: Task('aRoom', 'a room', []),
aFlight: Task('aFlight', 'a flight to $destination', ['destination']),
aRoom: Task('aRoom', []),
aFlight: Task('aFlight', ['destination']),
}

@@ -193,0 +195,0 @@

@@ -25,3 +25,2 @@ 'use strict'

perspectives: {},
defaultPerspective: Perspective('unknown default'),
}

@@ -33,4 +32,2 @@

reset()
module.exports = {

@@ -37,0 +34,0 @@ actor,

@@ -11,66 +11,72 @@ 'use strict'

it('creates, stores and retrieves actors by name', () => {
const dave = actor('dave')
const anotherDave = actor('dave')
assert.deepEqual(dave, anotherDave)
})
describe('actors', () => {
it('creates, stores and retrieves actors by name', () => {
const dave = actor('dave')
const anotherDave = actor('dave')
assert.deepEqual(dave, anotherDave)
})
it('runs an afterCreate callback when the actor is created', async () => {
const setupMyActor = sinon.spy()
const dave = await actor('dave', { afterCreate: setupMyActor })
await actor('dave', { afterCreate: setupMyActor })
sinon.assert.calledOnce(setupMyActor)
sinon.assert.calledWith(setupMyActor, dave)
})
it('runs an afterCreate callback when the actor is created', async () => {
const setupMyActor = sinon.spy()
const dave = await actor('dave', { afterCreate: setupMyActor })
await actor('dave', { afterCreate: setupMyActor })
sinon.assert.calledOnce(setupMyActor)
sinon.assert.calledWith(setupMyActor, dave)
})
it('runs an afterCreate callback when the actor is created', async () => {
const login = sinon.spy()
const setupMyActor = () =>
new Promise(resolve =>
setTimeout(() => {
login()
resolve()
}, 1)
)
await actor('dave', { afterCreate: setupMyActor })
sinon.assert.calledOnce(login)
it('runs an afterCreate callback when the actor is created', async () => {
const login = sinon.spy()
const setupMyActor = () =>
new Promise(resolve =>
setTimeout(() => {
login()
resolve()
}, 1)
)
await actor('dave', { afterCreate: setupMyActor })
sinon.assert.calledOnce(login)
})
})
it('creates and stores perspectives by name', () => {
const createUser = Task('create user')
const onePerspecrtive = perspective('web', handle => {
handle(createUser, () => ({ browser }) => browser.click())
describe('perspectives', () => {
it('creates and stores perspectives by name', () => {
const createUser = Task('create user')
const onePerspecrtive = perspective('web', handle => {
handle(createUser, () => ({ browser }) => browser.click())
})
const anotherPerspective = perspective('web')
assert.deepEqual(onePerspecrtive, anotherPerspective)
})
const anotherPerspective = perspective('web')
assert.deepEqual(onePerspecrtive, anotherPerspective)
})
it('creates actors with the default perspective', async () => {
const createUser = Task('create user')
perspective('web', handle => {
handle(createUser, () => ({ browser }) => browser.click())
it('creates actors with the default perspective', async () => {
const createUser = Task('create user')
perspective('web', handle => {
handle(createUser, () => ({ browser }) => browser.click())
})
perspective.default('web')
const browser = { click: sinon.spy() }
const dave = (await actor('dave')).gainsAbilities({ browser })
await dave.attemptsTo(createUser)
sinon.assert.called(browser.click)
})
perspective.default('web')
const browser = { click: sinon.spy() }
const dave = (await actor('dave')).gainsAbilities({ browser })
await dave.attemptsTo(createUser)
sinon.assert.called(browser.click)
})
it('resets the state between scenarios', async () => {
const dave = await actor('dave')
reset()
const anotherDave = await actor('dave')
assert.notDeepEqual(dave, anotherDave)
})
describe('resetting state between tests', () => {
it('resets the actors', async () => {
const dave = await actor('dave')
reset()
const anotherDave = await actor('dave')
assert.notDeepEqual(dave, anotherDave)
})
it('does not reset perspectives between scenarios', () => {
const createUser = Task('create user')
const onePerspecrtive = perspective('web', handle => {
handle(createUser, () => ({ browser }) => browser.click())
it('does not reset perspectives', () => {
const createUser = Task('create user')
const onePerspecrtive = perspective('web', handle => {
handle(createUser, () => ({ browser }) => browser.click())
})
reset()
const anotherPerspective = perspective('web')
assert.deepEqual(onePerspecrtive, anotherPerspective)
})
reset()
const anotherPerspective = perspective('web')
assert.deepEqual(onePerspecrtive, anotherPerspective)
})
})
{
"name": "feynman",
"version": "0.0.16",
"version": "0.0.17",
"description": "A screenplay pattern library for javascript",

@@ -23,2 +23,3 @@ "main": "lib/feynman.js",

"dependencies": {
"sentence-case": "^2.1.1",
"sinon": "^6.1.4"

@@ -25,0 +26,0 @@ },

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