diff --git a/core/base-service/loader.js b/core/base-service/loader.js index 9bbf0c948d..af708ef53c 100644 --- a/core/base-service/loader.js +++ b/core/base-service/loader.js @@ -27,11 +27,13 @@ class InvalidService extends Error { } } +function getServicePaths(pattern) { + return glob.sync(toUnixPath(path.join(serviceDir, '**', pattern))) +} + async function loadServiceClasses(servicePaths) { if (!servicePaths) { - servicePaths = glob.sync( - toUnixPath(path.join(serviceDir, '**', '*.service.js')) - ) + servicePaths = getServicePaths('*.service.js') } const serviceClasses = [] @@ -102,15 +104,16 @@ async function collectDefinitions() { async function loadTesters() { return Promise.all( - glob - .sync(path.join(serviceDir, '**', '*.tester.js')) - .map(async path => await import(`file://${path}`)) + getServicePaths('*.tester.js').map( + async path => await import(`file://${path}`) + ) ) } export { InvalidService, loadServiceClasses, + getServicePaths, checkNames, collectDefinitions, loadTesters, diff --git a/core/base-service/loader.spec.js b/core/base-service/loader.spec.js index e26c28fc1e..bb920a398e 100644 --- a/core/base-service/loader.spec.js +++ b/core/base-service/loader.spec.js @@ -2,7 +2,11 @@ import path from 'path' import { fileURLToPath } from 'url' import chai from 'chai' import chaiAsPromised from 'chai-as-promised' -import { loadServiceClasses, InvalidService } from './loader.js' +import { + loadServiceClasses, + getServicePaths, + InvalidService, +} from './loader.js' chai.use(chaiAsPromised) const { expect } = chai @@ -65,3 +69,15 @@ describe('loadServiceClasses function', function () { ).to.eventually.have.length(5) }) }) + +describe('getServicePaths', function () { + // these tests just make sure we discover a + // plausibly large number of .service and .tester files + it('finds a non-zero number of services in the project', function () { + expect(getServicePaths('*.service.js')).to.have.length.above(400) + }) + + it('finds a non-zero number of testers in the project', function () { + expect(getServicePaths('*.tester.js')).to.have.length.above(400) + }) +})