Files
shields/core/base-service/loader.spec.js
Paul Melnikow be7cb93773 Refactor service loader (#2861)
This moves the loader code into `core/base-service`, leaving behind in `services/index.js` only the convenience imports.

Ref #2832
2019-01-24 22:55:10 -05:00

58 lines
1.9 KiB
JavaScript

'use strict'
const { expect } = require('chai')
const { loadServiceClasses, InvalidService } = require('./loader')
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)
})
})