Bury the loader fixtures with the code that uses them (#3407)

One less thing to have in the root of the project!
This commit is contained in:
Paul Melnikow
2019-05-02 12:36:00 -04:00
committed by GitHub
parent c3bc0ac96f
commit a0da978886
12 changed files with 27 additions and 25 deletions

View File

@@ -0,0 +1,3 @@
'use strict'
module.exports = []

View File

@@ -0,0 +1,4 @@
/* eslint-disable */
'use strict'
class BadService {}

View File

@@ -0,0 +1,3 @@
'use strict'
module.exports = {}

View File

@@ -0,0 +1,3 @@
'use strict'
module.exports = undefined

View File

@@ -0,0 +1,9 @@
'use strict'
const BaseJsonService = require('../base-json')
class BadBaseService {}
class GoodService extends BaseJsonService {}
class BadService extends BadBaseService {}
module.exports = [GoodService, BadService]

View File

@@ -0,0 +1,5 @@
'use strict'
class BadService {}
module.exports = BadService

View File

@@ -0,0 +1,6 @@
'use strict'
class BadBaseService {}
class BadService extends BadBaseService {}
module.exports = BadService

View File

@@ -0,0 +1,30 @@
'use strict'
const BaseJsonService = require('../base-json')
class GoodServiceOne extends BaseJsonService {
static get category() {
return 'build'
}
static get route() {
return {
base: 'good',
pattern: 'one',
}
}
}
class GoodServiceTwo extends BaseJsonService {
static get category() {
return 'build'
}
static get route() {
return {
base: 'good',
pattern: 'two',
}
}
}
module.exports = [GoodServiceOne, GoodServiceTwo]

View File

@@ -0,0 +1,18 @@
'use strict'
const BaseJsonService = require('../base-json')
class GoodService extends BaseJsonService {
static get category() {
return 'build'
}
static get route() {
return {
base: 'it/is',
pattern: 'good',
}
}
}
module.exports = GoodService

View File

@@ -0,0 +1,30 @@
'use strict'
const BaseJsonService = require('../base-json')
class GoodServiceOne extends BaseJsonService {
static get category() {
return 'build'
}
static get route() {
return {
base: 'good',
pattern: 'one',
}
}
}
class GoodServiceTwo extends BaseJsonService {
static get category() {
return 'build'
}
static get route() {
return {
base: 'good',
pattern: 'two',
}
}
}
module.exports = { GoodServiceOne, GoodServiceTwo }

View File

@@ -6,41 +6,43 @@ const { loadServiceClasses, InvalidService } = require('./loader')
describe('loadServiceClasses function', function() {
it('throws if module exports empty', function() {
expect(() =>
loadServiceClasses(['../../test-fixtures/empty-undefined.fixture.js'])
loadServiceClasses(['./loader-test-fixtures/empty-undefined.fixture.js'])
).to.throw(InvalidService)
expect(() =>
loadServiceClasses(['../../test-fixtures/empty-array.fixture.js'])
loadServiceClasses(['./loader-test-fixtures/empty-array.fixture.js'])
).to.throw()
expect(() =>
loadServiceClasses(['../../test-fixtures/empty-object.fixture.js'])
loadServiceClasses(['./loader-test-fixtures/empty-object.fixture.js'])
).to.throw(InvalidService)
expect(() =>
loadServiceClasses(['../../test-fixtures/empty-no-export.fixture.js'])
loadServiceClasses(['./loader-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',
'./loader-test-fixtures/valid-array.fixture.js',
'./loader-test-fixtures/valid-class.fixture.js',
'./loader-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'])
loadServiceClasses(['./loader-test-fixtures/invalid-no-base.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',
'./loader-test-fixtures/invalid-wrong-base.fixture.js',
])
).to.throw(InvalidService)
expect(() =>
loadServiceClasses(['./loader-test-fixtures/invalid-mixed.fixture.js'])
).to.throw(InvalidService)
expect(() =>
loadServiceClasses([
'./loader-test-fixtures/valid-array.fixture.js',
'./loader-test-fixtures/valid-class.fixture.js',
'./loader-test-fixtures/invalid-no-base.fixture.js',
])
).to.throw(InvalidService)
})
@@ -48,9 +50,9 @@ describe('loadServiceClasses function', function() {
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',
'./loader-test-fixtures/valid-array.fixture.js',
'./loader-test-fixtures/valid-object.fixture.js',
'./loader-test-fixtures/valid-class.fixture.js',
])
).to.have.length(5)
})