Skip to content

Commit 5b654bb

Browse files
author
Tom Kirkpatrick
committed
Lint code as part of running tests
1 parent cc6381d commit 5b654bb

File tree

7 files changed

+26
-18
lines changed

7 files changed

+26
-18
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/coverage/
2+
test/fullcube-state-machine/server

lib/mixins/state-machine.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ module.exports = function StateMachine(Model, settings) {
108108
Model.__FSM_CONFIG__.callbacks[handler] = function runHandler(options) {
109109
debug('Calling %s: %o', handler, options)
110110
return Model.notifyObserversOf(`fsm:${handler}`, options)
111-
.then(options => {
112-
debug('Result from %s: %o', handler, options)
113-
return options
111+
.then(result => {
112+
debug('Result from %s: %o', handler, result)
113+
return result
114114
})
115115
}
116116
})

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
"main": "lib/index.js",
3131
"scripts": {
3232
"dev": "nodemon test/fullcube-state-machine/server/server.js --ignore db.json --ext js,json",
33+
"lint": "eslint .",
34+
"pretest": "npm run lint",
3335
"test": "nyc --reporter=lcov --reporter=text --reporter=text-summary mocha test/*test.js",
3436
"test:watch": "npm run test -- -w",
3537
"coverage": "nyc report --reporter=text-lcov | coveralls"

test/fullcube-state-machine/common/providers/subscription.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict'
2+
13
const Promise = require('bluebird')
24
const log = require('loglevel')
35

test/fullcube-state-machine/server/boot/root.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
module.exports = function(server) {
24
// Install a `/` route that returns server status
35
var router = server.loopback.Router();

test/fullcube-state-machine/server/server.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var loopback = require('loopback');
24
var boot = require('loopback-boot');
35

test/test.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ describe('State changes', function() {
5050
it('Should save the final state', function() {
5151
return this.subscription.cancel()
5252
.then(subscription => {
53-
console.log('sdfsdfsdfsdd09-934-93409we09w09r0e9', subscription)
5453
expect(subscription).to.have.property('status', 'canceled')
5554
})
5655
})
@@ -94,7 +93,8 @@ describe('Observers', function() {
9493
]
9594
const observersThatRan = []
9695

97-
before(function() {observers.forEach(observer => {
96+
before(function() {
97+
observers.forEach(observer => {
9898
// Clear out all existing observers for this test.
9999
Subscription.clearObservers(observer)
100100

@@ -110,7 +110,6 @@ describe('Observers', function() {
110110
return Subscription.create({ status: 'active' })
111111
.then(subscription => subscription.cancel())
112112
})
113-
114113
describe('Cancel', function() {
115114
observers.forEach(observer => {
116115
it(`should run the ${observer} observer`, function() {
@@ -142,7 +141,7 @@ describe('Validation', function() {
142141
return Subscription.create({ status: 'unknown' })
143142
.catch(err => {
144143
expect(err).to.have.property('name', 'ValidationError')
145-
expect(err).to.have.property('message', 'The `Subscription` instance is not valid. Details: `status` is not included in the list (value: \"unknown\").')
144+
expect(err.message).to.include('`status` is not included in the list (value: \"unknown\").')
146145
expect(err).to.have.property('statusCode', 422)
147146
})
148147
})
@@ -190,6 +189,7 @@ describe('Cache', function() {
190189

191190
it('should create and cache a new state machine', function() {
192191
const fsm = app.getStateMachine(subscription)
192+
193193
expect(app.locals).to.have.deep.property('loopback-component-fsm.Subscription.id:1', fsm)
194194
})
195195
})
@@ -224,24 +224,22 @@ describe('Cache', function() {
224224

225225
it('should reuse an existing state machine if one is in use', function(done) {
226226

227-
// Make the subscription.cancel method take 200ms second to run.
228-
Subscription.observe('fsm:oncancel', ctx => {
229-
return Promise.delay(200).return(ctx)
230-
})
227+
// Make the subscription.cancel method take 100ms second to run.
228+
Subscription.observe('fsm:oncancel', ctx => Promise.delay(100).return(ctx))
231229

232230
// Start a cancelation.
233231
this.subscription.cancel()
234-
.then(result => {
232+
.then(() => {
235233
expect(app.locals).to.not.have.deep.property(`loopback-component-fsm.Subscription.id:${this.subscription.id}`)
236234
done()
237235
})
238236

239-
// Start another cancel in 100ms (whilst the other is still running).
240-
Promise.delay(100).then(() => this.subscription.cancel())
241-
.then(() => Promise.reject(new Error('Should not get this far')))
242-
.catch(err => {
243-
expect(err).to.have.property('message', 'Previous transition pending')
244-
})
237+
// Start another cancel in 50ms (whilst the other is still running).
238+
Promise.delay(50).then(() => this.subscription.cancel())
239+
.then(() => Promise.reject(new Error('Should not get this far')))
240+
.catch(err => {
241+
expect(err).to.have.property('message', 'Previous transition pending')
242+
})
245243
})
246244
})
247245
})

0 commit comments

Comments
 (0)