-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some error messages for the developer when .service.js is malform…
…ed (#1894) Add some error messages for the developer when .service.js is malformed When loading `.service.js` files which don’t contain services, such as when the export is forgotten, print helpful error messages. This will only occur during development; the unit tests will catch these problems well before code reaches the server.
- Loading branch information
1 parent
8752497
commit e66d92f
Showing
12 changed files
with
154 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use strict' | ||
|
||
const { expect } = require('chai') | ||
const { loadServiceClasses, InvalidService } = require('./index') | ||
|
||
describe('loadServiceClasses function', function() { | ||
it('throws if module exports empty', function() { | ||
expect(() => | ||
loadServiceClasses(['../test-fixtures/empty-undefined.fixture.js']) | ||
).to.throw(InvalidService) | ||
expect(() => | ||
loadServiceClasses(['../test-fixtures/empty-array.fixture.js']) | ||
).to.throw() | ||
expect(() => | ||
loadServiceClasses(['../test-fixtures/empty-object.fixture.js']) | ||
).to.throw(InvalidService) | ||
expect(() => | ||
loadServiceClasses(['../test-fixtures/empty-no-export.fixture.js']) | ||
).to.throw(InvalidService) | ||
expect(() => | ||
loadServiceClasses([ | ||
'../test-fixtures/valid-array.fixture.js', | ||
'../test-fixtures/valid-class.fixture.js', | ||
'../test-fixtures/empty-array.fixture.js', | ||
]) | ||
).to.throw(InvalidService) | ||
}) | ||
|
||
it('throws if module exports invalid', function() { | ||
expect(() => | ||
loadServiceClasses(['../test-fixtures/invalid-no-base.fixture.js']) | ||
).to.throw(InvalidService) | ||
expect(() => | ||
loadServiceClasses(['../test-fixtures/invalid-wrong-base.fixture.js']) | ||
).to.throw(InvalidService) | ||
expect(() => | ||
loadServiceClasses(['../test-fixtures/invalid-mixed.fixture.js']) | ||
).to.throw(InvalidService) | ||
expect(() => | ||
loadServiceClasses([ | ||
'../test-fixtures/valid-array.fixture.js', | ||
'../test-fixtures/valid-class.fixture.js', | ||
'../test-fixtures/invalid-no-base.fixture.js', | ||
]) | ||
).to.throw(InvalidService) | ||
}) | ||
|
||
it('registers services if module exports valid service classes', function() { | ||
expect( | ||
loadServiceClasses([ | ||
'../test-fixtures/valid-array.fixture.js', | ||
'../test-fixtures/valid-object.fixture.js', | ||
'../test-fixtures/valid-class.fixture.js', | ||
]) | ||
).to.have.length(5) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict' | ||
|
||
module.exports = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* eslint-disable */ | ||
'use strict' | ||
|
||
class BadService {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict' | ||
|
||
module.exports = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict' | ||
|
||
module.exports = undefined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict' | ||
|
||
const BaseJsonService = require('../services/base-json') | ||
|
||
class BadBaseService {} | ||
class GoodService extends BaseJsonService {} | ||
class BadService extends BadBaseService {} | ||
|
||
module.exports = [GoodService, BadService] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict' | ||
|
||
class BadService {} | ||
|
||
module.exports = BadService |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict' | ||
|
||
class BadBaseService {} | ||
class BadService extends BadBaseService {} | ||
|
||
module.exports = BadService |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict' | ||
|
||
const BaseJsonService = require('../services/base-json') | ||
const LegacyService = require('../services/legacy-service') | ||
|
||
class GoodServiceOne extends BaseJsonService {} | ||
class GoodServiceTwo extends LegacyService {} | ||
|
||
module.exports = [GoodServiceOne, GoodServiceTwo] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict' | ||
|
||
const BaseJsonService = require('../services/base-json') | ||
|
||
class GoodService extends BaseJsonService {} | ||
|
||
module.exports = GoodService |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict' | ||
|
||
const BaseJsonService = require('../services/base-json') | ||
const LegacyService = require('../services/legacy-service') | ||
|
||
class GoodServiceOne extends BaseJsonService {} | ||
class GoodServiceTwo extends LegacyService {} | ||
|
||
module.exports = { GoodServiceOne, GoodServiceTwo } |