Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

71 #76

Merged
merged 1 commit into from
Jan 14, 2019
Merged

71 #76

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "standard",
"rules": {
"no-useless-constructor": ["off", "always"]
"no-useless-constructor": ["off", "always"],
"standard/no-callback-literal": ["off", "always"]
}
}
2 changes: 1 addition & 1 deletion build.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ new ExecutedLint(process, './src').after(
new ExecutedLint(process, './test').after(
new ExecutedTestCoverageCheck(
new ExecutedTestCoverage(
process, './test/simple-test.js'
process, './test/test.js'
),
{ 'lines': 100, 'functions': 100, 'branches': 100 }
)
Expand Down
3 changes: 1 addition & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module.exports = {

AsyncObject: require('./src/AsyncObject'),
Event: require('./src/Event'),
as: require('./src/As'),
NullError: require('./src/NullError')
as: require('./src/As')

}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"test": "test"
},
"scripts": {
"test": "node test/simple-test",
"test": "node test/test",
"build": "node build"
},
"repository": {
Expand Down
27 changes: 12 additions & 15 deletions src/AsyncTreeNode.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

const TreeNode = require('./TreeNode')
const NullError = require('./NullError')

class AsyncTreeNode extends TreeNode {
/*
Expand All @@ -28,7 +27,11 @@ class AsyncTreeNode extends TreeNode {
}
} catch (error) {
if (error.message !== 'asyncCall or syncCall must be defined') {
this.field.onError(error)
if (this.field.continueAfterFail()) {
this.field.onErrorAndResult(error)
} else {
this.field.onError(error)
}
} else {
let syncCall = this.field.definedSyncCall()
this.invokeSyncCall(syncCall, ...args)
Expand Down Expand Up @@ -82,22 +85,16 @@ class AsyncTreeNode extends TreeNode {
let isProcessed = false
// It's not possible to get rid of null here :(
if (error != null) {
if (this.hasParent()) {
if (this.field.continueAfterFail()) {
let totalResult = this.field.onErrorAndResult(error, ...results)
this.field.saveValueIntoCacheIfNeeded(totalResult)
if (this.field.continueAfterFail()) {
let totalResult = this.field.onErrorAndResult(error, ...results)
this.field.saveValueIntoCacheIfNeeded(totalResult)
if (this.hasParent()) {
super.callParent(totalResult)
} else {
this.field.onError(error)
}
} else {
if (this.field.continueAfterFail()) {
let totalResult = this.field.onErrorAndResult(error, ...results)
this.field.saveValueIntoCacheIfNeeded(totalResult)
this.field.callNextTreeIfExists()
} else {
this.field.onError(error)
}
} else {
this.field.onError(error)
}
isProcessed = true
}
Expand All @@ -107,7 +104,7 @@ class AsyncTreeNode extends TreeNode {
processedResult (...results) {
let totalResult
if (this.field.continueAfterFail()) {
totalResult = this.field.onErrorAndResult(new NullError(), ...results)
totalResult = this.field.onErrorAndResult(null, ...results)
} else {
totalResult = this.field.onResult(...results)
}
Expand Down
10 changes: 0 additions & 10 deletions src/NullError.js

This file was deleted.

18 changes: 18 additions & 0 deletions test/AsyncObjectWithArgs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict'

const AsyncObject = require('./../src/AsyncObject')

class AsyncObjectWithArgs extends AsyncObject {
constructor (...args) {
super(...args)
}

definedAsyncCall () {
return (...args) => {
let callback = args[args.length - 1]
return callback(null, ...args.slice(0, args.length - 1))
}
}
}

module.exports = AsyncObjectWithArgs
22 changes: 22 additions & 0 deletions test/AsyncObjectWithAssertedErrorInCallback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict'

const AsyncObject = require('./../src/AsyncObject')
const assert = require('assert')

class AsyncObjectWithAssertedErrorInCallback extends AsyncObject {
constructor () {
super()
}

definedAsyncCall () {
return (callback) => {
return callback(new Error('async error'))
}
}

onError (error) {
assert.deepStrictEqual(error, new Error('async error'))
}
}

module.exports = AsyncObjectWithAssertedErrorInCallback
22 changes: 22 additions & 0 deletions test/AsyncObjectWithAssertedErrorInDefinedCall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict'

const AsyncObject = require('./../src/AsyncObject')
const assert = require('assert')

class AsyncObjectWithAssertedErrorInDefinedCall extends AsyncObject {
constructor () {
super()
}

definedAsyncCall () {
return () => {
throw new Error('async error')
}
}

onError (error) {
assert.deepStrictEqual(error, new Error('async error'))
}
}

module.exports = AsyncObjectWithAssertedErrorInDefinedCall
23 changes: 23 additions & 0 deletions test/AsyncObjectWithAssertedResultInCallback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict'

const AsyncObject = require('./../src/AsyncObject')
const assert = require('assert')

class AsyncObjectWithAssertedResultInCallback extends AsyncObject {
constructor () {
super()
}

definedAsyncCall () {
return (callback) => {
return callback(null, 'result')
}
}

onResult (result) {
assert.strictEqual(result, 'result')
return result
}
}

module.exports = AsyncObjectWithAssertedResultInCallback
27 changes: 27 additions & 0 deletions test/AsyncObjectWithAssertedSafeErrorAndResultInCallback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict'

const AsyncObject = require('./../src/AsyncObject')
const assert = require('assert')

class AsyncObjectWithAssertedSafeErrorAndResultInCallback extends AsyncObject {
constructor () {
super()
}

definedAsyncCall () {
return (callback) => {
return callback(null, 'result')
}
}

onErrorAndResult (error, result) {
assert.strictEqual(super.onErrorAndResult(error, result), 'result')
return result
}

continueAfterFail () {
return true
}
}

module.exports = AsyncObjectWithAssertedSafeErrorAndResultInCallback
28 changes: 28 additions & 0 deletions test/AsyncObjectWithAssertedSafeErrorInCallback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict'

const AsyncObject = require('./../src/AsyncObject')
const assert = require('assert')

class AsyncObjectWithAssertedSafeErrorInCallback extends AsyncObject {
constructor () {
super()
}

definedAsyncCall () {
return (callback) => {
return callback(new Error('safe async error'), 'result')
}
}

onErrorAndResult (error, result) {
assert.deepStrictEqual(error, new Error('safe async error'))
assert.strictEqual(result, 'result')
return error
}

continueAfterFail () {
return true
}
}

module.exports = AsyncObjectWithAssertedSafeErrorInCallback
26 changes: 26 additions & 0 deletions test/AsyncObjectWithAssertedSafeErrorInDefinedCall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict'

const AsyncObject = require('./../src/AsyncObject')
const assert = require('assert')

class AsyncObjectWithAssertedSafeErrorInDefinedCall extends AsyncObject {
constructor () {
super()
}

definedAsyncCall () {
return () => {
throw new Error('safe async error')
}
}

onErrorAndResult (error) {
assert.deepStrictEqual(error, new Error('safe async error'))
}

continueAfterFail () {
return true
}
}

module.exports = AsyncObjectWithAssertedSafeErrorInDefinedCall
28 changes: 28 additions & 0 deletions test/AsyncObjectWithAssertedSafeResultInCallback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict'

const AsyncObject = require('./../src/AsyncObject')
const assert = require('assert')

class AsyncObjectWithAssertedSafeResultInCallback extends AsyncObject {
constructor () {
super()
}

definedAsyncCall () {
return (callback) => {
return callback(null, 'result')
}
}

onErrorAndResult (error, result) {
assert.strictEqual(error, null)
assert.strictEqual(result, 'result')
return result
}

continueAfterFail () {
return true
}
}

module.exports = AsyncObjectWithAssertedSafeResultInCallback
21 changes: 21 additions & 0 deletions test/AsyncObjectWithoutError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict'

const AsyncObject = require('./../src/AsyncObject')

class AsyncObjectWithoutError extends AsyncObject {
constructor () {
super()
}

definedAsyncCall () {
return (callback) => {
callback('value')
}
}

callbackWithError () {
return false
}
}

module.exports = AsyncObjectWithoutError
11 changes: 11 additions & 0 deletions test/BrokenEvent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict'

const Event = require('./../src/Event')

class BrokenEvent extends Event {
constructor () {
super()
}
}

module.exports = BrokenEvent
16 changes: 16 additions & 0 deletions test/BrokenTreeNode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict'

const TreeNode = require('./../src/TreeNode')

class BrokenTreeNode extends TreeNode {
/*
field: simple argument (not AsyncObject, can be Event)
parent: AsyncTreeNode or NotDefinedAsyncTree
position: int
*/
constructor (field, parent, position) {
super(field, parent, position)
}
}

module.exports = BrokenTreeNode
19 changes: 19 additions & 0 deletions test/DeepStrictEqualAssertion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict'

const AsyncObject = require('./../src/AsyncObject')
const assert = require('assert')

class DeepStrictEqualAssertion extends AsyncObject {
constructor (actual, expected) {
super(actual, expected)
}

definedSyncCall () {
return (actual, expected) => {
assert.deepStrictEqual(actual, expected)
return actual
}
}
}

module.exports = DeepStrictEqualAssertion
18 changes: 0 additions & 18 deletions test/ErrorAssertion.js

This file was deleted.

Loading