diff --git a/extensions/notebook/src/test/book/bookTocManager.test.ts b/extensions/notebook/src/test/book/bookTocManager.test.ts index 433e54a08a..1526f8413e 100644 --- a/extensions/notebook/src/test/book/bookTocManager.test.ts +++ b/extensions/notebook/src/test/book/bookTocManager.test.ts @@ -90,15 +90,18 @@ describe('BookTocManagerTests', function () { let bookTocManager: BookTocManager = new BookTocManager(); let expectedSection: IJupyterBookSectionV2[] = [{ title: 'notebook2', - file: path.join(subfolder, 'notebook2') + file: path.posix.join(subfolder, 'notebook2') }, { title: 'notebook3', - file: path.join(subfolder, 'notebook3') + file: path.posix.join(subfolder, 'notebook3') }]; await bookTocManager.createBook(bookFolderPath, root2FolderPath); - should(equalTOC(bookTocManager.tableofContents[1].sections, expectedSection)).be.true; - should((bookTocManager.tableofContents[1] as IJupyterBookSectionV2).file).be.equal(path.join(path.sep, subfolder, 'index')); + const index = bookTocManager.tableofContents.findIndex(entry => entry.file === path.posix.join(path.posix.sep, subfolder, 'index')); + should(index).not.be.equal(-1, 'Should find a section with the Subfolder entry'); + if (index !== -1) { + should(equalTOC(bookTocManager.tableofContents[index].sections, expectedSection)).be.true; + } }); it('should ignore invalid file extensions', async () => { @@ -130,88 +133,88 @@ describe('BookTocManagerTests', function () { version: BookVersion.v1, sourceBook: { 'rootBookFolderPath': sourceBookFolderPath, - 'bookContentFolderPath': path.join(sourceBookFolderPath, 'content'), - 'tocPath': path.join(sourceBookFolderPath, '_data', 'toc.yml'), - 'readme': path.join(sourceBookFolderPath, 'content', 'readme.md'), + 'bookContentFolderPath': path.posix.join(sourceBookFolderPath, 'content'), + 'tocPath': path.posix.join(sourceBookFolderPath, '_data', 'toc.yml'), + 'readme': path.posix.join(sourceBookFolderPath, 'content', 'readme.md'), 'toc': [ { 'title': 'Notebook 1', - 'file': path.join(path.sep, 'sectionA', 'notebook1') + 'file': path.posix.join(path.posix.sep, 'sectionA', 'notebook1') }, { 'title': 'Notebook 2', - 'file': path.join(path.sep, 'sectionA', 'notebook2') + 'file': path.posix.join(path.posix.sep, 'sectionA', 'notebook2') } ] }, sectionA: { - 'contentPath': path.join(sourceBookFolderPath, 'content', 'sectionA', 'readme.md'), - 'sectionRoot': path.join(sourceBookFolderPath, 'content', 'sectionA'), + 'contentPath': path.posix.join(sourceBookFolderPath, 'content', 'sectionA', 'readme.md'), + 'sectionRoot': path.posix.join(sourceBookFolderPath, 'content', 'sectionA'), 'sectionName': 'Section A', - 'notebook1': path.join(sourceBookFolderPath, 'content', 'sectionA', 'notebook1.ipynb'), - 'notebook2': path.join(sourceBookFolderPath, 'content', 'sectionA', 'notebook2.ipynb'), + 'notebook1': path.posix.join(sourceBookFolderPath, 'content', 'sectionA', 'notebook1.ipynb'), + 'notebook2': path.posix.join(sourceBookFolderPath, 'content', 'sectionA', 'notebook2.ipynb'), 'sectionFormat': [ { 'title': 'Notebook 1', - 'file': path.join(path.sep, 'sectionA', 'notebook1') + 'file': path.posix.join(path.posix.sep, 'sectionA', 'notebook1') }, { 'title': 'Notebook 2', - 'file': path.join(path.sep, 'sectionA', 'notebook2') + 'file': path.posix.join(path.posix.sep, 'sectionA', 'notebook2') } ] }, sectionB: { - 'contentPath': path.join(sourceBookFolderPath, 'content', 'sectionB', 'readme.md'), - 'sectionRoot': path.join(sourceBookFolderPath, 'content', 'sectionB'), + 'contentPath': path.posix.join(sourceBookFolderPath, 'content', 'sectionB', 'readme.md'), + 'sectionRoot': path.posix.join(sourceBookFolderPath, 'content', 'sectionB'), 'sectionName': 'Section B', - 'notebook3': path.join(sourceBookFolderPath, 'content', 'sectionB', 'notebook3.ipynb'), - 'notebook4': path.join(sourceBookFolderPath, 'content', 'sectionB', 'notebook4.ipynb'), + 'notebook3': path.posix.join(sourceBookFolderPath, 'content', 'sectionB', 'notebook3.ipynb'), + 'notebook4': path.posix.join(sourceBookFolderPath, 'content', 'sectionB', 'notebook4.ipynb'), 'sectionFormat': [ { 'title': 'Notebook 3', - 'file': path.join(path.sep, 'sectionB', 'notebook3') + 'file': path.posix.join(path.posix.sep, 'sectionB', 'notebook3') }, { 'title': 'Notebook 4', - 'file': path.join(path.sep, 'sectionB', 'notebook4') + 'file': path.posix.join(path.posix.sep, 'sectionB', 'notebook4') } ] }, notebook5: { - 'contentPath': path.join(sourceBookFolderPath, 'content', 'notebook5.ipynb') + 'contentPath': path.posix.join(sourceBookFolderPath, 'content', 'notebook5.ipynb') }, targetBook: { 'rootBookFolderPath': targetBookFolderPath, - 'bookContentFolderPath': path.join(targetBookFolderPath, 'content'), - 'tocPath': path.join(targetBookFolderPath, '_data', 'toc.yml'), - 'readme': path.join(targetBookFolderPath, 'content', 'readme.md'), + 'bookContentFolderPath': path.posix.join(targetBookFolderPath, 'content'), + 'tocPath': path.posix.join(targetBookFolderPath, '_data', 'toc.yml'), + 'readme': path.posix.join(targetBookFolderPath, 'content', 'readme.md'), 'toc': [ { 'title': 'Welcome page', - 'file': path.join(path.sep, 'readme'), + 'file': path.posix.join(path.posix.sep, 'readme'), }, { 'title': 'Section C', - 'file': path.join(path.sep, 'sectionC', 'readme'), + 'file': path.posix.join(path.posix.sep, 'sectionC', 'readme'), 'sections': [ { 'title': 'Notebook 6', - 'file': path.join(path.sep, 'sectionC', 'notebook6') + 'file': path.posix.join(path.posix.sep, 'sectionC', 'notebook6') } ] } ] }, sectionC: { - 'contentPath': path.join(targetBookFolderPath, 'content', 'sectionC', 'readme.md'), - 'sectionRoot': path.join(targetBookFolderPath, 'content', 'sectionC'), + 'contentPath': path.posix.join(targetBookFolderPath, 'content', 'sectionC', 'readme.md'), + 'sectionRoot': path.posix.join(targetBookFolderPath, 'content', 'sectionC'), 'sectionName': 'Section C', - 'notebook6': path.join(targetBookFolderPath, 'content', 'sectionC', 'notebook6.ipynb'), + 'notebook6': path.posix.join(targetBookFolderPath, 'content', 'sectionC', 'notebook6.ipynb'), 'sectionFormat': [ { 'title': 'Notebook 6', - 'file': path.join(path.sep, 'sectionC', 'notebook6') + 'file': path.posix.join(path.posix.sep, 'sectionC', 'notebook6') } ] } @@ -221,77 +224,77 @@ describe('BookTocManagerTests', function () { sourceBook: { 'rootBookFolderPath': sourceBookFolderPath, 'bookContentFolderPath': sourceBookFolderPath, - 'tocPath': path.join(sourceBookFolderPath, '_toc.yml'), - 'readme': path.join(sourceBookFolderPath, 'readme.md') + 'tocPath': path.posix.join(sourceBookFolderPath, '_toc.yml'), + 'readme': path.posix.join(sourceBookFolderPath, 'readme.md') }, sectionA: { - 'contentPath': path.join(sourceBookFolderPath, 'sectionA', 'readme.md'), - 'sectionRoot': path.join(sourceBookFolderPath, 'sectionA'), + 'contentPath': path.posix.join(sourceBookFolderPath, 'sectionA', 'readme.md'), + 'sectionRoot': path.posix.join(sourceBookFolderPath, 'sectionA'), 'sectionName': 'Section A', - 'notebook1': path.join(sourceBookFolderPath, 'sectionA', 'notebook1.ipynb'), - 'notebook2': path.join(sourceBookFolderPath, 'sectionA', 'notebook2.ipynb'), + 'notebook1': path.posix.join(sourceBookFolderPath, 'sectionA', 'notebook1.ipynb'), + 'notebook2': path.posix.join(sourceBookFolderPath, 'sectionA', 'notebook2.ipynb'), 'sectionFormat': [ { 'title': 'Notebook 1', - 'file': path.join(path.sep, 'sectionA', 'notebook1') + 'file': path.posix.join(path.posix.sep, 'sectionA', 'notebook1') }, { 'title': 'Notebook 2', - 'file': path.join(path.sep, 'sectionA', 'notebook2') + 'file': path.posix.join(path.posix.sep, 'sectionA', 'notebook2') } ] }, sectionB: { - 'contentPath': path.join(sourceBookFolderPath, 'sectionB', 'readme.md'), - 'sectionRoot': path.join(sourceBookFolderPath, 'sectionB'), + 'contentPath': path.posix.join(sourceBookFolderPath, 'sectionB', 'readme.md'), + 'sectionRoot': path.posix.join(sourceBookFolderPath, 'sectionB'), 'sectionName': 'Section B', - 'notebook3': path.join(sourceBookFolderPath, 'sectionB', 'notebook3.ipynb'), - 'notebook4': path.join(sourceBookFolderPath, 'sectionB', 'notebook4.ipynb'), + 'notebook3': path.posix.join(sourceBookFolderPath, 'sectionB', 'notebook3.ipynb'), + 'notebook4': path.posix.join(sourceBookFolderPath, 'sectionB', 'notebook4.ipynb'), 'sectionFormat': [ { 'title': 'Notebook 3', - 'file': path.join(path.sep, 'sectionB', 'notebook3') + 'file': path.posix.join(path.posix.sep, 'sectionB', 'notebook3') }, { 'title': 'Notebook 4', - 'file': path.join(path.sep, 'sectionB', 'notebook4') + 'file': path.posix.join(path.posix.sep, 'sectionB', 'notebook4') } ] }, notebook5: { - 'contentPath': path.join(sourceBookFolderPath, 'notebook5.ipynb') + 'contentPath': path.posix.join(sourceBookFolderPath, 'notebook5.ipynb') }, targetBook: { 'rootBookFolderPath': targetBookFolderPath, 'bookContentFolderPath': targetBookFolderPath, - 'tocPath': path.join(targetBookFolderPath, '_toc.yml'), - 'readme': path.join(targetBookFolderPath, 'readme.md'), + 'tocPath': path.posix.join(targetBookFolderPath, '_toc.yml'), + 'readme': path.posix.join(targetBookFolderPath, 'readme.md'), 'toc': [ { 'title': 'Welcome', - 'file': path.join(path.sep, 'readme'), + 'file': path.posix.join(path.posix.sep, 'readme'), }, { 'title': 'Section C', - 'file': path.join(path.sep, 'sectionC', 'readme'), + 'file': path.posix.join(path.posix.sep, 'sectionC', 'readme'), 'sections': [ { 'title': 'Notebook 6', - 'file': path.join(path.sep, 'sectionC', 'notebook6') + 'file': path.posix.join(path.posix.sep, 'sectionC', 'notebook6') } ] } ] }, sectionC: { - 'contentPath': path.join(targetBookFolderPath, 'sectionC', 'readme.md'), - 'sectionRoot': path.join(targetBookFolderPath, 'sectionC'), + 'contentPath': path.posix.join(targetBookFolderPath, 'sectionC', 'readme.md'), + 'sectionRoot': path.posix.join(targetBookFolderPath, 'sectionC'), 'sectionName': 'Section C', - 'notebook6': path.join(targetBookFolderPath, 'sectionC', 'notebook6.ipynb'), + 'notebook6': path.posix.join(targetBookFolderPath, 'sectionC', 'notebook6.ipynb'), 'sectionFormat': [ { 'title': 'Notebook 6', - 'file': path.join(path.sep, 'sectionC', 'notebook6') + 'file': path.posix.join(path.posix.sep, 'sectionC', 'notebook6') } ] } @@ -343,7 +346,7 @@ describe('BookTocManagerTests', function () { version: run.version, page: { title: run.sectionA.sectionName, - file: path.join(path.sep, 'sectionA', 'readme'), + file: path.posix.join(path.posix.sep, 'sectionA', 'readme'), sections: run.sectionA.sectionFormat } }; @@ -362,7 +365,7 @@ describe('BookTocManagerTests', function () { version: run.version, page: { title: run.sectionB.sectionName, - file: path.join(path.sep, 'sectionB', 'readme'), + file: path.posix.join(path.posix.sep, 'sectionB', 'readme'), sections: run.sectionB.sectionFormat } }; @@ -376,7 +379,7 @@ describe('BookTocManagerTests', function () { sections: [ { 'title': 'Notebook 5', - 'file': path.join(path.sep, 'notebook5') + 'file': path.posix.join(path.posix.sep, 'notebook5') } ] }, @@ -386,19 +389,19 @@ describe('BookTocManagerTests', function () { version: run.version, page: { 'title': 'Notebook 5', - 'file': path.join(path.sep, 'notebook5') + 'file': path.posix.join(path.posix.sep, 'notebook5') } }; let duplicatedNbTreeItemFormat: BookTreeItemFormat = { title: 'Duplicated Notebook', - contentPath: path.join(duplicatedNotebookPath, 'notebook5.ipynb'), + contentPath: path.posix.join(duplicatedNotebookPath, 'notebook5.ipynb'), root: duplicatedNotebookPath, tableOfContents: { sections: [ { 'title': 'Notebook 5', - 'file': path.join(path.sep, 'notebook5') + 'file': path.posix.join(path.posix.sep, 'notebook5') } ] }, @@ -408,7 +411,7 @@ describe('BookTocManagerTests', function () { version: run.version, page: { 'title': 'Notebook 5', - 'file': path.join(path.sep, 'notebook5') + 'file': path.posix.join(path.posix.sep, 'notebook5') } }; @@ -420,9 +423,9 @@ describe('BookTocManagerTests', function () { duplicatedNotebook = new BookTreeItem(duplicatedNbTreeItemFormat, undefined); - sectionC.uri = path.join('sectionC', 'readme'); - sectionA.uri = path.join('sectionA', 'readme'); - sectionB.uri = path.join('sectionB', 'readme'); + sectionC.uri = path.posix.join('sectionC', 'readme'); + sectionA.uri = path.posix.join('sectionA', 'readme'); + sectionB.uri = path.posix.join('sectionB', 'readme'); targetBook.contextValue = 'savedBook'; sectionA.contextValue = 'section'; @@ -443,7 +446,7 @@ describe('BookTocManagerTests', function () { notebook.sections = [ { 'title': 'Notebook 5', - 'file': path.join(path.sep, 'notebook5') + 'file': path.posix.join(path.posix.sep, 'notebook5') } ]; duplicatedNotebook.sections = notebook.sections; @@ -498,7 +501,7 @@ describe('BookTocManagerTests', function () { bookTocManager = new BookTocManager(targetBookModel, sourceBookModel); await bookTocManager.updateBook(sectionB, sectionC, { 'title': 'Notebook 6', - 'file': path.join(path.sep, 'sectionC', 'notebook6') + 'file': path.posix.join(path.posix.sep, 'sectionC', 'notebook6') }); const sectionCFiles = await fs.promises.readdir(path.join(run.targetBook.bookContentFolderPath, 'sectionC')); const sectionBFiles = await fs.promises.readdir(path.join(run.targetBook.bookContentFolderPath, 'sectionB')); @@ -516,7 +519,7 @@ describe('BookTocManagerTests', function () { it('Remove notebook from book', async () => { let toc: JupyterBookSection[] = yaml.safeLoad((await fs.promises.readFile(notebook.tableOfContentsPath)).toString()); let notebookInToc = toc.some(section => { - if (section.title === 'Notebook 5' && section.file === path.join(path.sep, 'notebook5')) { + if (section.title === 'Notebook 5' && section.file === path.posix.join(path.posix.sep, 'notebook5')) { return true; } return false; @@ -529,7 +532,7 @@ describe('BookTocManagerTests', function () { const listFiles = await fs.promises.readdir(run.sourceBook.bookContentFolderPath); toc = yaml.safeLoad((await fs.promises.readFile(notebook.tableOfContentsPath)).toString()); notebookInToc = toc.some(section => { - if (section.title === 'Notebook 5' && section.file === path.join(path.sep, 'notebook5')) { + if (section.title === 'Notebook 5' && section.file === path.posix.join(path.posix.sep, 'notebook5')) { return true; } return false;