diff --git a/aio/tools/transforms/examples-package/processors/collect-examples.js b/aio/tools/transforms/examples-package/processors/collect-examples.js index 5bb6a94c50..ebf66658a9 100644 --- a/aio/tools/transforms/examples-package/processors/collect-examples.js +++ b/aio/tools/transforms/examples-package/processors/collect-examples.js @@ -27,6 +27,7 @@ module.exports = function collectExamples(exampleMap, regionParser, log, createD }, $process(docs) { const exampleFolders = this.exampleFolders; + exampleFolders.forEach(folder => exampleMap[folder] = exampleMap[folder] || {}); const regionDocs = []; docs = docs.filter((doc) => { if (doc.docType === 'example-file') { @@ -36,7 +37,6 @@ module.exports = function collectExamples(exampleMap, regionParser, log, createD if (doc.fileInfo.relativePath.indexOf(folder) === 0) { const relativePath = doc.fileInfo.relativePath.substr(folder.length).replace(/^\//, ''); - exampleMap[folder] = exampleMap[folder] || {}; exampleMap[folder][relativePath] = doc; // We treat files that end in `.annotated` specially diff --git a/aio/tools/transforms/examples-package/processors/collect-examples.spec.js b/aio/tools/transforms/examples-package/processors/collect-examples.spec.js index 583c3a1029..85f10ca02e 100644 --- a/aio/tools/transforms/examples-package/processors/collect-examples.spec.js +++ b/aio/tools/transforms/examples-package/processors/collect-examples.spec.js @@ -25,6 +25,12 @@ describe('collectExampleRegions processor', () => { describe('$process', () => { + it('should initialise the `exampleMap` even if there are no examples to collect', () => { + processor.$process([]); + expect(exampleMap['examples-1']).toEqual(jasmine.any(Object)); + expect(exampleMap['examples-2']).toEqual(jasmine.any(Object)); + }); + it('should identify example files that are in the exampleFolders', () => { const docs = [ createDoc('A', 'examples-1/x/app.js'), createDoc('B', 'examples-1/y/index.html'),