diff --git a/packages/techdocs-common/src/stages/generate/helpers.test.ts b/packages/techdocs-common/src/stages/generate/helpers.test.ts index 4a862de024..fdb164f44a 100644 --- a/packages/techdocs-common/src/stages/generate/helpers.test.ts +++ b/packages/techdocs-common/src/stages/generate/helpers.test.ts @@ -66,6 +66,8 @@ const mkdocsYmlWithComments = fs.readFileSync( resolvePath(__filename, '../__fixtures__/mkdocs_with_comments.yml'), ); const mockLogger = getVoidLogger(); +const warn = jest.spyOn(mockLogger, 'warn'); + const rootDir = os.platform() === 'win32' ? 'C:\\rootDir' : '/rootDir'; const scmIntegrations = ScmIntegrations.fromConfig(new ConfigReader({})); @@ -288,6 +290,9 @@ describe('helpers', () => { }); describe('patchIndexPreBuild', () => { + afterEach(() => { + warn.mockClear(); + }); it('should have no effect if docs/index.md exists', async () => { mockFs({ '/docs/index.md': 'index.md content', @@ -299,6 +304,7 @@ describe('helpers', () => { expect(fs.readFileSync('/docs/index.md', 'utf-8')).toEqual( 'index.md content', ); + expect(warn).not.toHaveBeenCalledWith(); mockFs.restore(); }); @@ -313,6 +319,7 @@ describe('helpers', () => { expect(fs.readFileSync('/docs/index.md', 'utf-8')).toEqual( 'docs/README.md content', ); + expect(warn.mock.calls).toEqual([['docs/index.md not found.']]); mockFs.restore(); }); @@ -326,6 +333,11 @@ describe('helpers', () => { expect(fs.readFileSync('/docs/index.md', 'utf-8')).toEqual( 'main README.md content', ); + expect(warn.mock.calls).toEqual([ + ['docs/index.md not found.'], + ['docs/README.md not found.'], + ['docs/readme.md not found.'], + ]); mockFs.restore(); }); @@ -335,6 +347,16 @@ describe('helpers', () => { await patchIndexPreBuild({ inputDir: '/', logger: mockLogger }); expect(() => fs.readFileSync('/docs/index.md', 'utf-8')).toThrow(); + expect(warn.mock.calls).toEqual([ + ['docs/index.md not found.'], + ['docs/README.md not found.'], + ['docs/readme.md not found.'], + ['README.md not found.'], + ['readme.md not found.'], + [ + "Could not find any techdocs' index file. Please make sure at least one of /docs/index.md /docs/README.md /docs/readme.md /README.md /readme.md exists.", + ], + ]); mockFs.restore(); }); }); @@ -459,7 +481,7 @@ describe('helpers', () => { it('should return true on when a valid docs_dir is present', async () => { await expect( validateMkdocsYaml(inputDir, mkdocsYmlWithValidDocDir.toString()), - ).resolves.toBeUndefined(); + ).resolves.toBe('docs/'); }); it('should return false on absolute doc_dir path', async () => {