fix tests on windows (#14827)

* fix tests on windows

* fix test
This commit is contained in:
Barbara Valdez
2021-03-23 10:03:48 -07:00
committed by GitHub
parent e2b6972ba9
commit 5c67f3dbed

View File

@@ -90,15 +90,18 @@ describe('BookTocManagerTests', function () {
let bookTocManager: BookTocManager = new BookTocManager(); let bookTocManager: BookTocManager = new BookTocManager();
let expectedSection: IJupyterBookSectionV2[] = [{ let expectedSection: IJupyterBookSectionV2[] = [{
title: 'notebook2', title: 'notebook2',
file: path.join(subfolder, 'notebook2') file: path.posix.join(subfolder, 'notebook2')
}, },
{ {
title: 'notebook3', title: 'notebook3',
file: path.join(subfolder, 'notebook3') file: path.posix.join(subfolder, 'notebook3')
}]; }];
await bookTocManager.createBook(bookFolderPath, root2FolderPath); await bookTocManager.createBook(bookFolderPath, root2FolderPath);
should(equalTOC(bookTocManager.tableofContents[1].sections, expectedSection)).be.true; const index = bookTocManager.tableofContents.findIndex(entry => entry.file === path.posix.join(path.posix.sep, subfolder, 'index'));
should((bookTocManager.tableofContents[1] as IJupyterBookSectionV2).file).be.equal(path.join(path.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 () => { it('should ignore invalid file extensions', async () => {
@@ -130,88 +133,88 @@ describe('BookTocManagerTests', function () {
version: BookVersion.v1, version: BookVersion.v1,
sourceBook: { sourceBook: {
'rootBookFolderPath': sourceBookFolderPath, 'rootBookFolderPath': sourceBookFolderPath,
'bookContentFolderPath': path.join(sourceBookFolderPath, 'content'), 'bookContentFolderPath': path.posix.join(sourceBookFolderPath, 'content'),
'tocPath': path.join(sourceBookFolderPath, '_data', 'toc.yml'), 'tocPath': path.posix.join(sourceBookFolderPath, '_data', 'toc.yml'),
'readme': path.join(sourceBookFolderPath, 'content', 'readme.md'), 'readme': path.posix.join(sourceBookFolderPath, 'content', 'readme.md'),
'toc': [ 'toc': [
{ {
'title': 'Notebook 1', 'title': 'Notebook 1',
'file': path.join(path.sep, 'sectionA', 'notebook1') 'file': path.posix.join(path.posix.sep, 'sectionA', 'notebook1')
}, },
{ {
'title': 'Notebook 2', 'title': 'Notebook 2',
'file': path.join(path.sep, 'sectionA', 'notebook2') 'file': path.posix.join(path.posix.sep, 'sectionA', 'notebook2')
} }
] ]
}, },
sectionA: { sectionA: {
'contentPath': path.join(sourceBookFolderPath, 'content', 'sectionA', 'readme.md'), 'contentPath': path.posix.join(sourceBookFolderPath, 'content', 'sectionA', 'readme.md'),
'sectionRoot': path.join(sourceBookFolderPath, 'content', 'sectionA'), 'sectionRoot': path.posix.join(sourceBookFolderPath, 'content', 'sectionA'),
'sectionName': 'Section A', 'sectionName': 'Section A',
'notebook1': path.join(sourceBookFolderPath, 'content', 'sectionA', 'notebook1.ipynb'), 'notebook1': path.posix.join(sourceBookFolderPath, 'content', 'sectionA', 'notebook1.ipynb'),
'notebook2': path.join(sourceBookFolderPath, 'content', 'sectionA', 'notebook2.ipynb'), 'notebook2': path.posix.join(sourceBookFolderPath, 'content', 'sectionA', 'notebook2.ipynb'),
'sectionFormat': [ 'sectionFormat': [
{ {
'title': 'Notebook 1', 'title': 'Notebook 1',
'file': path.join(path.sep, 'sectionA', 'notebook1') 'file': path.posix.join(path.posix.sep, 'sectionA', 'notebook1')
}, },
{ {
'title': 'Notebook 2', 'title': 'Notebook 2',
'file': path.join(path.sep, 'sectionA', 'notebook2') 'file': path.posix.join(path.posix.sep, 'sectionA', 'notebook2')
} }
] ]
}, },
sectionB: { sectionB: {
'contentPath': path.join(sourceBookFolderPath, 'content', 'sectionB', 'readme.md'), 'contentPath': path.posix.join(sourceBookFolderPath, 'content', 'sectionB', 'readme.md'),
'sectionRoot': path.join(sourceBookFolderPath, 'content', 'sectionB'), 'sectionRoot': path.posix.join(sourceBookFolderPath, 'content', 'sectionB'),
'sectionName': 'Section B', 'sectionName': 'Section B',
'notebook3': path.join(sourceBookFolderPath, 'content', 'sectionB', 'notebook3.ipynb'), 'notebook3': path.posix.join(sourceBookFolderPath, 'content', 'sectionB', 'notebook3.ipynb'),
'notebook4': path.join(sourceBookFolderPath, 'content', 'sectionB', 'notebook4.ipynb'), 'notebook4': path.posix.join(sourceBookFolderPath, 'content', 'sectionB', 'notebook4.ipynb'),
'sectionFormat': [ 'sectionFormat': [
{ {
'title': 'Notebook 3', 'title': 'Notebook 3',
'file': path.join(path.sep, 'sectionB', 'notebook3') 'file': path.posix.join(path.posix.sep, 'sectionB', 'notebook3')
}, },
{ {
'title': 'Notebook 4', 'title': 'Notebook 4',
'file': path.join(path.sep, 'sectionB', 'notebook4') 'file': path.posix.join(path.posix.sep, 'sectionB', 'notebook4')
} }
] ]
}, },
notebook5: { notebook5: {
'contentPath': path.join(sourceBookFolderPath, 'content', 'notebook5.ipynb') 'contentPath': path.posix.join(sourceBookFolderPath, 'content', 'notebook5.ipynb')
}, },
targetBook: { targetBook: {
'rootBookFolderPath': targetBookFolderPath, 'rootBookFolderPath': targetBookFolderPath,
'bookContentFolderPath': path.join(targetBookFolderPath, 'content'), 'bookContentFolderPath': path.posix.join(targetBookFolderPath, 'content'),
'tocPath': path.join(targetBookFolderPath, '_data', 'toc.yml'), 'tocPath': path.posix.join(targetBookFolderPath, '_data', 'toc.yml'),
'readme': path.join(targetBookFolderPath, 'content', 'readme.md'), 'readme': path.posix.join(targetBookFolderPath, 'content', 'readme.md'),
'toc': [ 'toc': [
{ {
'title': 'Welcome page', 'title': 'Welcome page',
'file': path.join(path.sep, 'readme'), 'file': path.posix.join(path.posix.sep, 'readme'),
}, },
{ {
'title': 'Section C', 'title': 'Section C',
'file': path.join(path.sep, 'sectionC', 'readme'), 'file': path.posix.join(path.posix.sep, 'sectionC', 'readme'),
'sections': [ 'sections': [
{ {
'title': 'Notebook 6', 'title': 'Notebook 6',
'file': path.join(path.sep, 'sectionC', 'notebook6') 'file': path.posix.join(path.posix.sep, 'sectionC', 'notebook6')
} }
] ]
} }
] ]
}, },
sectionC: { sectionC: {
'contentPath': path.join(targetBookFolderPath, 'content', 'sectionC', 'readme.md'), 'contentPath': path.posix.join(targetBookFolderPath, 'content', 'sectionC', 'readme.md'),
'sectionRoot': path.join(targetBookFolderPath, 'content', 'sectionC'), 'sectionRoot': path.posix.join(targetBookFolderPath, 'content', 'sectionC'),
'sectionName': 'Section C', 'sectionName': 'Section C',
'notebook6': path.join(targetBookFolderPath, 'content', 'sectionC', 'notebook6.ipynb'), 'notebook6': path.posix.join(targetBookFolderPath, 'content', 'sectionC', 'notebook6.ipynb'),
'sectionFormat': [ 'sectionFormat': [
{ {
'title': 'Notebook 6', '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: { sourceBook: {
'rootBookFolderPath': sourceBookFolderPath, 'rootBookFolderPath': sourceBookFolderPath,
'bookContentFolderPath': sourceBookFolderPath, 'bookContentFolderPath': sourceBookFolderPath,
'tocPath': path.join(sourceBookFolderPath, '_toc.yml'), 'tocPath': path.posix.join(sourceBookFolderPath, '_toc.yml'),
'readme': path.join(sourceBookFolderPath, 'readme.md') 'readme': path.posix.join(sourceBookFolderPath, 'readme.md')
}, },
sectionA: { sectionA: {
'contentPath': path.join(sourceBookFolderPath, 'sectionA', 'readme.md'), 'contentPath': path.posix.join(sourceBookFolderPath, 'sectionA', 'readme.md'),
'sectionRoot': path.join(sourceBookFolderPath, 'sectionA'), 'sectionRoot': path.posix.join(sourceBookFolderPath, 'sectionA'),
'sectionName': 'Section A', 'sectionName': 'Section A',
'notebook1': path.join(sourceBookFolderPath, 'sectionA', 'notebook1.ipynb'), 'notebook1': path.posix.join(sourceBookFolderPath, 'sectionA', 'notebook1.ipynb'),
'notebook2': path.join(sourceBookFolderPath, 'sectionA', 'notebook2.ipynb'), 'notebook2': path.posix.join(sourceBookFolderPath, 'sectionA', 'notebook2.ipynb'),
'sectionFormat': [ 'sectionFormat': [
{ {
'title': 'Notebook 1', 'title': 'Notebook 1',
'file': path.join(path.sep, 'sectionA', 'notebook1') 'file': path.posix.join(path.posix.sep, 'sectionA', 'notebook1')
}, },
{ {
'title': 'Notebook 2', 'title': 'Notebook 2',
'file': path.join(path.sep, 'sectionA', 'notebook2') 'file': path.posix.join(path.posix.sep, 'sectionA', 'notebook2')
} }
] ]
}, },
sectionB: { sectionB: {
'contentPath': path.join(sourceBookFolderPath, 'sectionB', 'readme.md'), 'contentPath': path.posix.join(sourceBookFolderPath, 'sectionB', 'readme.md'),
'sectionRoot': path.join(sourceBookFolderPath, 'sectionB'), 'sectionRoot': path.posix.join(sourceBookFolderPath, 'sectionB'),
'sectionName': 'Section B', 'sectionName': 'Section B',
'notebook3': path.join(sourceBookFolderPath, 'sectionB', 'notebook3.ipynb'), 'notebook3': path.posix.join(sourceBookFolderPath, 'sectionB', 'notebook3.ipynb'),
'notebook4': path.join(sourceBookFolderPath, 'sectionB', 'notebook4.ipynb'), 'notebook4': path.posix.join(sourceBookFolderPath, 'sectionB', 'notebook4.ipynb'),
'sectionFormat': [ 'sectionFormat': [
{ {
'title': 'Notebook 3', 'title': 'Notebook 3',
'file': path.join(path.sep, 'sectionB', 'notebook3') 'file': path.posix.join(path.posix.sep, 'sectionB', 'notebook3')
}, },
{ {
'title': 'Notebook 4', 'title': 'Notebook 4',
'file': path.join(path.sep, 'sectionB', 'notebook4') 'file': path.posix.join(path.posix.sep, 'sectionB', 'notebook4')
} }
] ]
}, },
notebook5: { notebook5: {
'contentPath': path.join(sourceBookFolderPath, 'notebook5.ipynb') 'contentPath': path.posix.join(sourceBookFolderPath, 'notebook5.ipynb')
}, },
targetBook: { targetBook: {
'rootBookFolderPath': targetBookFolderPath, 'rootBookFolderPath': targetBookFolderPath,
'bookContentFolderPath': targetBookFolderPath, 'bookContentFolderPath': targetBookFolderPath,
'tocPath': path.join(targetBookFolderPath, '_toc.yml'), 'tocPath': path.posix.join(targetBookFolderPath, '_toc.yml'),
'readme': path.join(targetBookFolderPath, 'readme.md'), 'readme': path.posix.join(targetBookFolderPath, 'readme.md'),
'toc': [ 'toc': [
{ {
'title': 'Welcome', 'title': 'Welcome',
'file': path.join(path.sep, 'readme'), 'file': path.posix.join(path.posix.sep, 'readme'),
}, },
{ {
'title': 'Section C', 'title': 'Section C',
'file': path.join(path.sep, 'sectionC', 'readme'), 'file': path.posix.join(path.posix.sep, 'sectionC', 'readme'),
'sections': [ 'sections': [
{ {
'title': 'Notebook 6', 'title': 'Notebook 6',
'file': path.join(path.sep, 'sectionC', 'notebook6') 'file': path.posix.join(path.posix.sep, 'sectionC', 'notebook6')
} }
] ]
} }
] ]
}, },
sectionC: { sectionC: {
'contentPath': path.join(targetBookFolderPath, 'sectionC', 'readme.md'), 'contentPath': path.posix.join(targetBookFolderPath, 'sectionC', 'readme.md'),
'sectionRoot': path.join(targetBookFolderPath, 'sectionC'), 'sectionRoot': path.posix.join(targetBookFolderPath, 'sectionC'),
'sectionName': 'Section C', 'sectionName': 'Section C',
'notebook6': path.join(targetBookFolderPath, 'sectionC', 'notebook6.ipynb'), 'notebook6': path.posix.join(targetBookFolderPath, 'sectionC', 'notebook6.ipynb'),
'sectionFormat': [ 'sectionFormat': [
{ {
'title': 'Notebook 6', '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, version: run.version,
page: { page: {
title: run.sectionA.sectionName, title: run.sectionA.sectionName,
file: path.join(path.sep, 'sectionA', 'readme'), file: path.posix.join(path.posix.sep, 'sectionA', 'readme'),
sections: run.sectionA.sectionFormat sections: run.sectionA.sectionFormat
} }
}; };
@@ -362,7 +365,7 @@ describe('BookTocManagerTests', function () {
version: run.version, version: run.version,
page: { page: {
title: run.sectionB.sectionName, title: run.sectionB.sectionName,
file: path.join(path.sep, 'sectionB', 'readme'), file: path.posix.join(path.posix.sep, 'sectionB', 'readme'),
sections: run.sectionB.sectionFormat sections: run.sectionB.sectionFormat
} }
}; };
@@ -376,7 +379,7 @@ describe('BookTocManagerTests', function () {
sections: [ sections: [
{ {
'title': 'Notebook 5', '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, version: run.version,
page: { page: {
'title': 'Notebook 5', 'title': 'Notebook 5',
'file': path.join(path.sep, 'notebook5') 'file': path.posix.join(path.posix.sep, 'notebook5')
} }
}; };
let duplicatedNbTreeItemFormat: BookTreeItemFormat = { let duplicatedNbTreeItemFormat: BookTreeItemFormat = {
title: 'Duplicated Notebook', title: 'Duplicated Notebook',
contentPath: path.join(duplicatedNotebookPath, 'notebook5.ipynb'), contentPath: path.posix.join(duplicatedNotebookPath, 'notebook5.ipynb'),
root: duplicatedNotebookPath, root: duplicatedNotebookPath,
tableOfContents: { tableOfContents: {
sections: [ sections: [
{ {
'title': 'Notebook 5', '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, version: run.version,
page: { page: {
'title': 'Notebook 5', '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); duplicatedNotebook = new BookTreeItem(duplicatedNbTreeItemFormat, undefined);
sectionC.uri = path.join('sectionC', 'readme'); sectionC.uri = path.posix.join('sectionC', 'readme');
sectionA.uri = path.join('sectionA', 'readme'); sectionA.uri = path.posix.join('sectionA', 'readme');
sectionB.uri = path.join('sectionB', 'readme'); sectionB.uri = path.posix.join('sectionB', 'readme');
targetBook.contextValue = 'savedBook'; targetBook.contextValue = 'savedBook';
sectionA.contextValue = 'section'; sectionA.contextValue = 'section';
@@ -443,7 +446,7 @@ describe('BookTocManagerTests', function () {
notebook.sections = [ notebook.sections = [
{ {
'title': 'Notebook 5', 'title': 'Notebook 5',
'file': path.join(path.sep, 'notebook5') 'file': path.posix.join(path.posix.sep, 'notebook5')
} }
]; ];
duplicatedNotebook.sections = notebook.sections; duplicatedNotebook.sections = notebook.sections;
@@ -498,7 +501,7 @@ describe('BookTocManagerTests', function () {
bookTocManager = new BookTocManager(targetBookModel, sourceBookModel); bookTocManager = new BookTocManager(targetBookModel, sourceBookModel);
await bookTocManager.updateBook(sectionB, sectionC, { await bookTocManager.updateBook(sectionB, sectionC, {
'title': 'Notebook 6', '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 sectionCFiles = await fs.promises.readdir(path.join(run.targetBook.bookContentFolderPath, 'sectionC'));
const sectionBFiles = await fs.promises.readdir(path.join(run.targetBook.bookContentFolderPath, 'sectionB')); 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 () => { it('Remove notebook from book', async () => {
let toc: JupyterBookSection[] = yaml.safeLoad((await fs.promises.readFile(notebook.tableOfContentsPath)).toString()); let toc: JupyterBookSection[] = yaml.safeLoad((await fs.promises.readFile(notebook.tableOfContentsPath)).toString());
let notebookInToc = toc.some(section => { 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 true;
} }
return false; return false;
@@ -529,7 +532,7 @@ describe('BookTocManagerTests', function () {
const listFiles = await fs.promises.readdir(run.sourceBook.bookContentFolderPath); const listFiles = await fs.promises.readdir(run.sourceBook.bookContentFolderPath);
toc = yaml.safeLoad((await fs.promises.readFile(notebook.tableOfContentsPath)).toString()); toc = yaml.safeLoad((await fs.promises.readFile(notebook.tableOfContentsPath)).toString());
notebookInToc = toc.some(section => { 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 true;
} }
return false; return false;