mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Tests/book tests (#9075)
* Conditionally add associatedResource t untitled nb * Fix Jupyter Book notebook titles (#9039) * Fix notebook titles * Fix navigation links for books * Added comments Co-authored-by: Chris LaFreniere <40371649+chlafreniere@users.noreply.github.com> * PR comment nit * fix book tests * tslint formatting fixes * merged master and undid formatting * added book path to error message Co-authored-by: Chris LaFreniere <40371649+chlafreniere@users.noreply.github.com> Co-authored-by: Charles Gagnon <chgagnon@microsoft.com>
This commit is contained in:
@@ -15,6 +15,7 @@ import * as fs from 'fs-extra';
|
|||||||
import * as loc from '../common/localizedConstants';
|
import * as loc from '../common/localizedConstants';
|
||||||
import { IJupyterBookToc, IJupyterBookSection } from '../contracts/content';
|
import { IJupyterBookToc, IJupyterBookSection } from '../contracts/content';
|
||||||
import { isNullOrUndefined } from 'util';
|
import { isNullOrUndefined } from 'util';
|
||||||
|
import { ApiWrapper } from '../common/apiWrapper';
|
||||||
|
|
||||||
|
|
||||||
const fsPromises = fileServices.promises;
|
const fsPromises = fileServices.promises;
|
||||||
@@ -25,6 +26,9 @@ export class BookModel implements azdata.nb.NavigationProvider {
|
|||||||
private _tableOfContentPaths: string[] = [];
|
private _tableOfContentPaths: string[] = [];
|
||||||
readonly providerId: string = 'BookNavigator';
|
readonly providerId: string = 'BookNavigator';
|
||||||
|
|
||||||
|
private _errorMessage: string;
|
||||||
|
private apiWrapper: ApiWrapper = new ApiWrapper();
|
||||||
|
|
||||||
constructor(public bookPath: string, public openAsUntitled: boolean, private _extensionContext: vscode.ExtensionContext) {
|
constructor(public bookPath: string, public openAsUntitled: boolean, private _extensionContext: vscode.ExtensionContext) {
|
||||||
this.bookPath = bookPath;
|
this.bookPath = bookPath;
|
||||||
this.openAsUntitled = openAsUntitled;
|
this.openAsUntitled = openAsUntitled;
|
||||||
@@ -51,25 +55,26 @@ export class BookModel implements azdata.nb.NavigationProvider {
|
|||||||
maxDepth = undefined;
|
maxDepth = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
let p = path.join(folderPath, '**', '_data', 'toc.yml').replace(/\\/g, '/');
|
let p: string = path.join(folderPath, '**', '_data', 'toc.yml').replace(/\\/g, '/');
|
||||||
let tableOfContentPaths = await glob(p, { deep: maxDepth });
|
let tableOfContentPaths: string[] = await glob(p, { deep: maxDepth });
|
||||||
if (tableOfContentPaths.length > 0) {
|
if (tableOfContentPaths.length > 0) {
|
||||||
this._tableOfContentPaths = this._tableOfContentPaths.concat(tableOfContentPaths);
|
this._tableOfContentPaths = this._tableOfContentPaths.concat(tableOfContentPaths);
|
||||||
vscode.commands.executeCommand('setContext', 'bookOpened', true);
|
vscode.commands.executeCommand('setContext', 'bookOpened', true);
|
||||||
} else {
|
} else {
|
||||||
|
this._errorMessage = loc.missingTocError;
|
||||||
throw new Error(loc.missingTocError);
|
throw new Error(loc.missingTocError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async readBooks(): Promise<BookTreeItem[]> {
|
public async readBooks(): Promise<BookTreeItem[]> {
|
||||||
for (const contentPath of this._tableOfContentPaths) {
|
for (const contentPath of this._tableOfContentPaths) {
|
||||||
let root = path.dirname(path.dirname(contentPath));
|
let root: string = path.dirname(path.dirname(contentPath));
|
||||||
try {
|
try {
|
||||||
let fileContents = await fsPromises.readFile(path.join(root, '_config.yml'), 'utf-8');
|
let fileContents = await fsPromises.readFile(path.join(root, '_config.yml'), 'utf-8');
|
||||||
const config = yaml.safeLoad(fileContents.toString());
|
const config = yaml.safeLoad(fileContents.toString());
|
||||||
fileContents = await fsPromises.readFile(contentPath, 'utf-8');
|
fileContents = await fsPromises.readFile(contentPath, 'utf-8');
|
||||||
const tableOfContents = yaml.safeLoad(fileContents.toString());
|
const tableOfContents: any = yaml.safeLoad(fileContents.toString());
|
||||||
let book = new BookTreeItem({
|
let book: BookTreeItem = new BookTreeItem({
|
||||||
title: config.title,
|
title: config.title,
|
||||||
root: root,
|
root: root,
|
||||||
tableOfContents: { sections: this.parseJupyterSections(tableOfContents) },
|
tableOfContents: { sections: this.parseJupyterSections(tableOfContents) },
|
||||||
@@ -85,8 +90,8 @@ export class BookModel implements azdata.nb.NavigationProvider {
|
|||||||
);
|
);
|
||||||
this._bookItems.push(book);
|
this._bookItems.push(book);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
let error = e instanceof Error ? e.message : e;
|
this._errorMessage = loc.readBookError(this.bookPath, e instanceof Error ? e.message : e);
|
||||||
vscode.window.showErrorMessage(error);
|
this.apiWrapper.showErrorMessage(this._errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this._bookItems;
|
return this._bookItems;
|
||||||
@@ -101,7 +106,7 @@ export class BookModel implements azdata.nb.NavigationProvider {
|
|||||||
for (let i = 0; i < sections.length; i++) {
|
for (let i = 0; i < sections.length; i++) {
|
||||||
if (sections[i].url) {
|
if (sections[i].url) {
|
||||||
if (sections[i].external) {
|
if (sections[i].external) {
|
||||||
let externalLink = new BookTreeItem({
|
let externalLink: BookTreeItem = new BookTreeItem({
|
||||||
title: sections[i].title,
|
title: sections[i].title,
|
||||||
root: root,
|
root: root,
|
||||||
tableOfContents: tableOfContents,
|
tableOfContents: tableOfContents,
|
||||||
@@ -143,15 +148,14 @@ export class BookModel implements azdata.nb.NavigationProvider {
|
|||||||
this._allNotebooks.set(path.basename(pathToNotebook), notebook);
|
this._allNotebooks.set(path.basename(pathToNotebook), notebook);
|
||||||
notebooks.push(notebook);
|
notebooks.push(notebook);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (!this._allNotebooks.get(pathToNotebook)) {
|
if (!this._allNotebooks.get(pathToNotebook)) {
|
||||||
this._allNotebooks.set(pathToNotebook, notebook);
|
this._allNotebooks.set(pathToNotebook, notebook);
|
||||||
notebooks.push(notebook);
|
notebooks.push(notebook);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (await fs.pathExists(pathToMarkdown)) {
|
} else if (await fs.pathExists(pathToMarkdown)) {
|
||||||
let markdown = new BookTreeItem({
|
let markdown: BookTreeItem = new BookTreeItem({
|
||||||
title: sections[i].title,
|
title: sections[i].title,
|
||||||
root: root,
|
root: root,
|
||||||
tableOfContents: tableOfContents,
|
tableOfContents: tableOfContents,
|
||||||
@@ -167,8 +171,8 @@ export class BookModel implements azdata.nb.NavigationProvider {
|
|||||||
);
|
);
|
||||||
notebooks.push(markdown);
|
notebooks.push(markdown);
|
||||||
} else {
|
} else {
|
||||||
let error = loc.missingFileError(sections[i].title);
|
this._errorMessage = loc.missingFileError(sections[i].title);
|
||||||
vscode.window.showErrorMessage(error);
|
this.apiWrapper.showErrorMessage(this._errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -184,29 +188,31 @@ export class BookModel implements azdata.nb.NavigationProvider {
|
|||||||
*/
|
*/
|
||||||
private parseJupyterSections(section: any[]): IJupyterBookSection[] {
|
private parseJupyterSections(section: any[]): IJupyterBookSection[] {
|
||||||
try {
|
try {
|
||||||
return section.reduce((acc, val) => Array.isArray(val.sections) ? acc.concat(val).concat(this.parseJupyterSections(val.sections)) : acc.concat(val), []);
|
return section.reduce((acc, val) => Array.isArray(val.sections) ?
|
||||||
} catch (error) {
|
acc.concat(val).concat(this.parseJupyterSections(val.sections)) : acc.concat(val), []);
|
||||||
let err: string = loc.invalidTocFileError(error);
|
} catch (e) {
|
||||||
|
this._errorMessage = loc.invalidTocFileError();
|
||||||
if (section.length > 0) {
|
if (section.length > 0) {
|
||||||
err = loc.invalidTocError(section[0].title);
|
this._errorMessage = loc.invalidTocError(section[0].title);
|
||||||
}
|
}
|
||||||
vscode.window.showErrorMessage(err);
|
throw this._errorMessage;
|
||||||
throw err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public get tableOfContentPaths() {
|
public get tableOfContentPaths(): string[] {
|
||||||
return this._tableOfContentPaths;
|
return this._tableOfContentPaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
getNavigation(uri: vscode.Uri): Thenable<azdata.nb.NavigationResult> {
|
getNavigation(uri: vscode.Uri): Thenable<azdata.nb.NavigationResult> {
|
||||||
let notebook = !this.openAsUntitled ? this._allNotebooks.get(uri.fsPath) : this._allNotebooks.get(path.basename(uri.fsPath));
|
let notebook: BookTreeItem =
|
||||||
|
!this.openAsUntitled ? this._allNotebooks.get(uri.fsPath) : this._allNotebooks.get(path.basename(uri.fsPath));
|
||||||
let result: azdata.nb.NavigationResult;
|
let result: azdata.nb.NavigationResult;
|
||||||
if (notebook) {
|
if (notebook) {
|
||||||
result = {
|
result = {
|
||||||
hasNavigation: true,
|
hasNavigation: true,
|
||||||
previous: notebook.previousUri ? this.openAsUntitled ? this.getUntitledUri(notebook.previousUri) : vscode.Uri.file(notebook.previousUri) : undefined,
|
previous: notebook.previousUri ?
|
||||||
|
this.openAsUntitled ? this.getUntitledUri(notebook.previousUri) : vscode.Uri.file(notebook.previousUri) : undefined,
|
||||||
next: notebook.nextUri ? this.openAsUntitled ? this.getUntitledUri(notebook.nextUri) : vscode.Uri.file(notebook.nextUri) : undefined
|
next: notebook.nextUri ? this.openAsUntitled ? this.getUntitledUri(notebook.nextUri) : vscode.Uri.file(notebook.nextUri) : undefined
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
@@ -222,4 +228,9 @@ export class BookModel implements azdata.nb.NavigationProvider {
|
|||||||
getUntitledUri(resource: string): vscode.Uri {
|
getUntitledUri(resource: string): vscode.Uri {
|
||||||
return vscode.Uri.parse(`untitled:${resource}`);
|
return vscode.Uri.parse(`untitled:${resource}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get errorMessage(): string {
|
||||||
|
return this._errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,8 +24,6 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
|||||||
private prompter: IPrompter;
|
private prompter: IPrompter;
|
||||||
private _initializeDeferred: Deferred<void> = new Deferred<void>();
|
private _initializeDeferred: Deferred<void> = new Deferred<void>();
|
||||||
|
|
||||||
// For testing
|
|
||||||
private _errorMessage: string;
|
|
||||||
private _openAsUntitled: boolean;
|
private _openAsUntitled: boolean;
|
||||||
public viewId: string;
|
public viewId: string;
|
||||||
public books: BookModel[];
|
public books: BookModel[];
|
||||||
@@ -292,10 +290,6 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public get errorMessage() {
|
|
||||||
return this._errorMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
getUntitledNotebookUri(resource: string): vscode.Uri {
|
getUntitledNotebookUri(resource: string): vscode.Uri {
|
||||||
let untitledFileName = vscode.Uri.parse(`untitled:${resource}`);
|
let untitledFileName = vscode.Uri.parse(`untitled:${resource}`);
|
||||||
if (!this.currentBook.getAllBooks().get(untitledFileName.fsPath) && !this.currentBook.getAllBooks().get(path.basename(untitledFileName.fsPath))) {
|
if (!this.currentBook.getAllBooks().get(untitledFileName.fsPath) && !this.currentBook.getAllBooks().get(path.basename(untitledFileName.fsPath))) {
|
||||||
|
|||||||
@@ -24,10 +24,11 @@ export const openExternalLinkCommand = localize('openExternalLinkCommand', "Open
|
|||||||
|
|
||||||
export const missingTocError = localize('bookInitializeFailed', "Failed to find a toc.yml.");
|
export const missingTocError = localize('bookInitializeFailed', "Failed to find a toc.yml.");
|
||||||
export function missingFileError(title: string): string { return localize('missingFileError', "Missing file : {0}", title); }
|
export function missingFileError(title: string): string { return localize('missingFileError', "Missing file : {0}", title); }
|
||||||
export function invalidTocFileError(error: string): string { return localize('InvalidError.tocFile', "{0}", error); }
|
export function invalidTocFileError(): string { return localize('InvalidError.tocFile', "Invalid toc file"); }
|
||||||
export function invalidTocError(title: string): string { return localize('Invalid toc.yml', "Error: {0} has an incorrect toc.yml file", title); }
|
export function invalidTocError(title: string): string { return localize('Invalid toc.yml', "Error: {0} has an incorrect toc.yml file", title); }
|
||||||
|
|
||||||
export function openFileError(path: string, error: string): string { return localize('openBookError', "Open book {0} failed: {1}", path, error); }
|
export function openFileError(path: string, error: string): string { return localize('openBookError', "Open book {0} failed: {1}", path, error); }
|
||||||
|
export function readBookError(path: string, error: string): string { return localize('readBookError', "Failed to read book {0}: {1}", path, error); }
|
||||||
export function openNotebookError(resource: string, error: string): string { return localize('openNotebookError', "Open notebook {0} failed: {1}", resource, error); }
|
export function openNotebookError(resource: string, error: string): string { return localize('openNotebookError', "Open notebook {0} failed: {1}", resource, error); }
|
||||||
export function openMarkdownError(resource: string, error: string): string { return localize('openMarkdownError', "Open markdown {0} failed: {1}", resource, error); }
|
export function openMarkdownError(resource: string, error: string): string { return localize('openMarkdownError', "Open markdown {0} failed: {1}", resource, error); }
|
||||||
export function openUntitledNotebookError(resource: string, error: string): string { return localize('openUntitledNotebookError', "Open untitled notebook {0} as untitled failed: {1}", resource, error); }
|
export function openUntitledNotebookError(resource: string, error: string): string { return localize('openUntitledNotebookError', "Open untitled notebook {0} as untitled failed: {1}", resource, error); }
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import { promisify } from 'util';
|
|||||||
import { MockExtensionContext } from '../common/stubs';
|
import { MockExtensionContext } from '../common/stubs';
|
||||||
import { exists } from '../../common/utils';
|
import { exists } from '../../common/utils';
|
||||||
|
|
||||||
export interface ExpectedBookItem {
|
export interface IExpectedBookItem {
|
||||||
title: string;
|
title: string;
|
||||||
url?: string;
|
url?: string;
|
||||||
sections?: any[];
|
sections?: any[];
|
||||||
@@ -25,18 +25,20 @@ export interface ExpectedBookItem {
|
|||||||
nextUri?: string | undefined;
|
nextUri?: string | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function equalBookItems(book: BookTreeItem, expectedBook: ExpectedBookItem): void {
|
export function equalBookItems(book: BookTreeItem, expectedBook: IExpectedBookItem): void {
|
||||||
should(book.title).equal(expectedBook.title);
|
should(book.title).equal(expectedBook.title);
|
||||||
should(book.uri).equal(expectedBook.url);
|
should(path.posix.parse(book.uri)).deepEqual(path.posix.parse(expectedBook.url));
|
||||||
if (expectedBook.previousUri || expectedBook.nextUri) {
|
if (expectedBook.previousUri || expectedBook.nextUri) {
|
||||||
let prevUri = book.previousUri ? book.previousUri.toLocaleLowerCase() : undefined;
|
let prevUri = book.previousUri ? book.previousUri.toLocaleLowerCase() : undefined;
|
||||||
should(prevUri).equal(expectedBook.previousUri);
|
let expectedPrevUri = expectedBook.previousUri ? expectedBook.previousUri.replace(/\\/g, '/') : undefined;
|
||||||
|
should(prevUri).equal(expectedPrevUri);
|
||||||
let nextUri = book.nextUri ? book.nextUri.toLocaleLowerCase() : undefined;
|
let nextUri = book.nextUri ? book.nextUri.toLocaleLowerCase() : undefined;
|
||||||
should(nextUri).equal(expectedBook.nextUri);
|
let expectedNextUri = expectedBook.nextUri ? expectedBook.nextUri.replace(/\\/g, '/') : undefined;
|
||||||
|
should(nextUri).equal(expectedNextUri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('BookTreeViewProviderTests', function() {
|
describe('BookTreeViewProviderTests', function () {
|
||||||
|
|
||||||
describe('BookTreeViewProvider', () => {
|
describe('BookTreeViewProvider', () => {
|
||||||
|
|
||||||
@@ -44,27 +46,28 @@ describe('BookTreeViewProviderTests', function() {
|
|||||||
let nonBookFolderPath: string;
|
let nonBookFolderPath: string;
|
||||||
let bookFolderPath: string;
|
let bookFolderPath: string;
|
||||||
let rootFolderPath: string;
|
let rootFolderPath: string;
|
||||||
let expectedNotebook1: ExpectedBookItem;
|
let expectedNotebook1: IExpectedBookItem;
|
||||||
let expectedNotebook2: ExpectedBookItem;
|
let expectedNotebook2: IExpectedBookItem;
|
||||||
let expectedNotebook3: ExpectedBookItem;
|
let expectedNotebook3: IExpectedBookItem;
|
||||||
let expectedMarkdown: ExpectedBookItem;
|
let expectedMarkdown: IExpectedBookItem;
|
||||||
let expectedExternalLink: ExpectedBookItem;
|
let expectedExternalLink: IExpectedBookItem;
|
||||||
let expectedBook: ExpectedBookItem;
|
let expectedBook: IExpectedBookItem;
|
||||||
|
|
||||||
this.beforeAll(async () => {
|
this.beforeAll(async () => {
|
||||||
mockExtensionContext = new MockExtensionContext();
|
mockExtensionContext = new MockExtensionContext();
|
||||||
rootFolderPath = path.join(os.tmpdir(), `BookTestData_${uuid.v4()}`);
|
rootFolderPath = path.join(os.tmpdir(), `BookTestData_${uuid.v4()}`);
|
||||||
nonBookFolderPath = path.join(rootFolderPath, `NonBook`);
|
nonBookFolderPath = path.join(rootFolderPath, `NonBook`);
|
||||||
bookFolderPath = path.join(rootFolderPath, `Book`);
|
bookFolderPath = path.join(rootFolderPath, `Book`);
|
||||||
let dataFolderPath = path.join(bookFolderPath, '_data');
|
let dataFolderPath: string = path.join(bookFolderPath, '_data');
|
||||||
let contentFolderPath = path.join(bookFolderPath, 'content');
|
let contentFolderPath: string = path.join(bookFolderPath, 'content');
|
||||||
let configFile = path.join(bookFolderPath, '_config.yml');
|
let configFile: string = path.join(bookFolderPath, '_config.yml');
|
||||||
let tableOfContentsFile = path.join(dataFolderPath, 'toc.yml');
|
let tableOfContentsFile: string = path.join(dataFolderPath, 'toc.yml');
|
||||||
let notebook1File = path.join(contentFolderPath, 'notebook1.ipynb');
|
let notebook1File: string = path.join(contentFolderPath, 'notebook1.ipynb');
|
||||||
let notebook2File = path.join(contentFolderPath, 'notebook2.ipynb');
|
let notebook2File: string = path.join(contentFolderPath, 'notebook2.ipynb');
|
||||||
let notebook3File = path.join(contentFolderPath, 'notebook3.ipynb');
|
let notebook3File: string = path.join(contentFolderPath, 'notebook3.ipynb');
|
||||||
let markdownFile = path.join(contentFolderPath, 'markdown.md');
|
let markdownFile: string = path.join(contentFolderPath, 'markdown.md');
|
||||||
expectedNotebook1 = {
|
expectedNotebook1 = {
|
||||||
|
// tslint:disable-next-line: quotemark
|
||||||
title: 'Notebook1',
|
title: 'Notebook1',
|
||||||
url: '/notebook1',
|
url: '/notebook1',
|
||||||
previousUri: undefined,
|
previousUri: undefined,
|
||||||
@@ -185,7 +188,7 @@ describe('BookTreeViewProviderTests', function() {
|
|||||||
equalBookItems(notebook3, expectedNotebook3);
|
equalBookItems(notebook3, expectedNotebook3);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.afterAll(async function () {
|
this.afterAll(async function (): Promise<void> {
|
||||||
console.log('Removing temporary files...');
|
console.log('Removing temporary files...');
|
||||||
if (await exists(rootFolderPath)) {
|
if (await exists(rootFolderPath)) {
|
||||||
await promisify(rimraf)(rootFolderPath);
|
await promisify(rimraf)(rootFolderPath);
|
||||||
@@ -204,9 +207,9 @@ describe('BookTreeViewProviderTests', function() {
|
|||||||
|
|
||||||
this.beforeAll(async () => {
|
this.beforeAll(async () => {
|
||||||
rootFolderPath = path.join(os.tmpdir(), `BookTestData_${uuid.v4()}`);
|
rootFolderPath = path.join(os.tmpdir(), `BookTestData_${uuid.v4()}`);
|
||||||
let dataFolderPath = path.join(rootFolderPath, '_data');
|
let dataFolderPath: string = path.join(rootFolderPath, '_data');
|
||||||
tableOfContentsFile = path.join(dataFolderPath, 'toc.yml');
|
tableOfContentsFile = path.join(dataFolderPath, 'toc.yml');
|
||||||
let tableOfContentsFileIgnore = path.join(rootFolderPath, 'toc.yml');
|
let tableOfContentsFileIgnore: string = path.join(rootFolderPath, 'toc.yml');
|
||||||
await fs.mkdir(rootFolderPath);
|
await fs.mkdir(rootFolderPath);
|
||||||
await fs.mkdir(dataFolderPath);
|
await fs.mkdir(dataFolderPath);
|
||||||
await fs.writeFile(tableOfContentsFile, '- title: Notebook1\n url: /notebook1\n sections:\n - title: Notebook2\n url: /notebook2\n - title: Notebook3\n url: /notebook3\n- title: Markdown\n url: /markdown\n- title: GitHub\n url: https://github.com/\n external: true');
|
await fs.writeFile(tableOfContentsFile, '- title: Notebook1\n url: /notebook1\n sections:\n - title: Notebook2\n url: /notebook2\n - title: Notebook3\n url: /notebook3\n- title: Markdown\n url: /markdown\n- title: GitHub\n url: https://github.com/\n external: true');
|
||||||
@@ -229,7 +232,7 @@ describe('BookTreeViewProviderTests', function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.afterAll(async function () {
|
this.afterAll(async function (): Promise<void> {
|
||||||
if (await exists(rootFolderPath)) {
|
if (await exists(rootFolderPath)) {
|
||||||
await promisify(rimraf)(rootFolderPath);
|
await promisify(rimraf)(rootFolderPath);
|
||||||
}
|
}
|
||||||
@@ -237,7 +240,7 @@ describe('BookTreeViewProviderTests', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('BookTreeViewProvider.getBooks @UNSTABLE@', function (): void {
|
describe('BookTreeViewProvider.getBooks', function (): void {
|
||||||
let rootFolderPath: string;
|
let rootFolderPath: string;
|
||||||
let configFile: string;
|
let configFile: string;
|
||||||
let folder: vscode.WorkspaceFolder;
|
let folder: vscode.WorkspaceFolder;
|
||||||
@@ -246,7 +249,7 @@ describe('BookTreeViewProviderTests', function() {
|
|||||||
|
|
||||||
this.beforeAll(async () => {
|
this.beforeAll(async () => {
|
||||||
rootFolderPath = path.join(os.tmpdir(), `BookTestData_${uuid.v4()}`);
|
rootFolderPath = path.join(os.tmpdir(), `BookTestData_${uuid.v4()}`);
|
||||||
let dataFolderPath = path.join(rootFolderPath, '_data');
|
let dataFolderPath: string = path.join(rootFolderPath, '_data');
|
||||||
configFile = path.join(rootFolderPath, '_config.yml');
|
configFile = path.join(rootFolderPath, '_config.yml');
|
||||||
tocFile = path.join(dataFolderPath, 'toc.yml');
|
tocFile = path.join(dataFolderPath, 'toc.yml');
|
||||||
await fs.mkdir(rootFolderPath);
|
await fs.mkdir(rootFolderPath);
|
||||||
@@ -265,16 +268,16 @@ describe('BookTreeViewProviderTests', function() {
|
|||||||
|
|
||||||
it('should show error message if config.yml file not found', async () => {
|
it('should show error message if config.yml file not found', async () => {
|
||||||
await bookTreeViewProvider.currentBook.readBooks();
|
await bookTreeViewProvider.currentBook.readBooks();
|
||||||
should(bookTreeViewProvider.errorMessage.toLocaleLowerCase()).equal(('ENOENT: no such file or directory, open \'' + configFile + '\'').toLocaleLowerCase());
|
should(bookTreeViewProvider.currentBook.errorMessage.toLocaleLowerCase()).equal(('Failed to read book '+ bookTreeViewProvider.currentBook.bookPath +': ENOENT: no such file or directory, open \'' + configFile + '\'').toLocaleLowerCase());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show error if toc.yml file format is invalid', async function(): Promise<void> {
|
it('should show error if toc.yml file format is invalid', async function (): Promise<void> {
|
||||||
await fs.writeFile(configFile, 'title: Test Book');
|
await fs.writeFile(configFile, 'title: Test Book');
|
||||||
await bookTreeViewProvider.currentBook.readBooks();
|
await bookTreeViewProvider.currentBook.readBooks();
|
||||||
should(bookTreeViewProvider.errorMessage).equal('Error: Test Book has an incorrect toc.yml file');
|
should(bookTreeViewProvider.currentBook.errorMessage.toLocaleLowerCase()).equal(('Failed to read book '+ bookTreeViewProvider.currentBook.bookPath +': Invalid toc file').toLocaleLowerCase());
|
||||||
});
|
});
|
||||||
|
|
||||||
this.afterAll(async function () {
|
this.afterAll(async function (): Promise<void> {
|
||||||
if (await exists(rootFolderPath)) {
|
if (await exists(rootFolderPath)) {
|
||||||
await promisify(rimraf)(rootFolderPath);
|
await promisify(rimraf)(rootFolderPath);
|
||||||
}
|
}
|
||||||
@@ -282,12 +285,12 @@ describe('BookTreeViewProviderTests', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('BookTreeViewProvider.getSections @UNSTABLE@', function (): void {
|
describe('BookTreeViewProvider.getSections', function (): void {
|
||||||
let rootFolderPath: string;
|
let rootFolderPath: string;
|
||||||
let tableOfContentsFile: string;
|
let tableOfContentsFile: string;
|
||||||
let bookTreeViewProvider: BookTreeViewProvider;
|
let bookTreeViewProvider: BookTreeViewProvider;
|
||||||
let folder: vscode.WorkspaceFolder;
|
let folder: vscode.WorkspaceFolder;
|
||||||
let expectedNotebook2: ExpectedBookItem;
|
let expectedNotebook2: IExpectedBookItem;
|
||||||
|
|
||||||
this.beforeAll(async () => {
|
this.beforeAll(async () => {
|
||||||
rootFolderPath = path.join(os.tmpdir(), `BookTestData_${uuid.v4()}`);
|
rootFolderPath = path.join(os.tmpdir(), `BookTestData_${uuid.v4()}`);
|
||||||
@@ -320,15 +323,15 @@ describe('BookTreeViewProviderTests', function() {
|
|||||||
await Promise.race([bookTreeViewProvider.initialized, errorCase.then(() => { throw new Error('BookTreeViewProvider did not initialize in time'); })]);
|
await Promise.race([bookTreeViewProvider.initialized, errorCase.then(() => { throw new Error('BookTreeViewProvider did not initialize in time'); })]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show error if notebook or markdown file is missing', async function(): Promise<void> {
|
it('should show error if notebook or markdown file is missing', async function (): Promise<void> {
|
||||||
let books = bookTreeViewProvider.currentBook.bookItems;
|
let books: BookTreeItem[] = bookTreeViewProvider.currentBook.bookItems;
|
||||||
let children = await bookTreeViewProvider.currentBook.getSections({ sections: [] }, books[0].sections, rootFolderPath);
|
let children = await bookTreeViewProvider.currentBook.getSections({ sections: [] }, books[0].sections, rootFolderPath);
|
||||||
should(bookTreeViewProvider.errorMessage).equal('Missing file : Notebook1');
|
should(bookTreeViewProvider.currentBook.errorMessage).equal('Missing file : Notebook1');
|
||||||
// Rest of book should be detected correctly even with a missing file
|
// rest of book should be detected correctly even with a missing file
|
||||||
equalBookItems(children[0], expectedNotebook2);
|
equalBookItems(children[0], expectedNotebook2);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.afterAll(async function () {
|
this.afterAll(async function (): Promise<void> {
|
||||||
if (await exists(rootFolderPath)) {
|
if (await exists(rootFolderPath)) {
|
||||||
await promisify(rimraf)(rootFolderPath);
|
await promisify(rimraf)(rootFolderPath);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user