mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -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:
@@ -16,7 +16,7 @@ import { promisify } from 'util';
|
||||
import { MockExtensionContext } from '../common/stubs';
|
||||
import { exists } from '../../common/utils';
|
||||
|
||||
export interface ExpectedBookItem {
|
||||
export interface IExpectedBookItem {
|
||||
title: string;
|
||||
url?: string;
|
||||
sections?: any[];
|
||||
@@ -25,18 +25,20 @@ export interface ExpectedBookItem {
|
||||
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.uri).equal(expectedBook.url);
|
||||
should(path.posix.parse(book.uri)).deepEqual(path.posix.parse(expectedBook.url));
|
||||
if (expectedBook.previousUri || expectedBook.nextUri) {
|
||||
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;
|
||||
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', () => {
|
||||
|
||||
@@ -44,27 +46,28 @@ describe('BookTreeViewProviderTests', function() {
|
||||
let nonBookFolderPath: string;
|
||||
let bookFolderPath: string;
|
||||
let rootFolderPath: string;
|
||||
let expectedNotebook1: ExpectedBookItem;
|
||||
let expectedNotebook2: ExpectedBookItem;
|
||||
let expectedNotebook3: ExpectedBookItem;
|
||||
let expectedMarkdown: ExpectedBookItem;
|
||||
let expectedExternalLink: ExpectedBookItem;
|
||||
let expectedBook: ExpectedBookItem;
|
||||
let expectedNotebook1: IExpectedBookItem;
|
||||
let expectedNotebook2: IExpectedBookItem;
|
||||
let expectedNotebook3: IExpectedBookItem;
|
||||
let expectedMarkdown: IExpectedBookItem;
|
||||
let expectedExternalLink: IExpectedBookItem;
|
||||
let expectedBook: IExpectedBookItem;
|
||||
|
||||
this.beforeAll(async () => {
|
||||
mockExtensionContext = new MockExtensionContext();
|
||||
rootFolderPath = path.join(os.tmpdir(), `BookTestData_${uuid.v4()}`);
|
||||
nonBookFolderPath = path.join(rootFolderPath, `NonBook`);
|
||||
bookFolderPath = path.join(rootFolderPath, `Book`);
|
||||
let dataFolderPath = path.join(bookFolderPath, '_data');
|
||||
let contentFolderPath = path.join(bookFolderPath, 'content');
|
||||
let configFile = path.join(bookFolderPath, '_config.yml');
|
||||
let tableOfContentsFile = path.join(dataFolderPath, 'toc.yml');
|
||||
let notebook1File = path.join(contentFolderPath, 'notebook1.ipynb');
|
||||
let notebook2File = path.join(contentFolderPath, 'notebook2.ipynb');
|
||||
let notebook3File = path.join(contentFolderPath, 'notebook3.ipynb');
|
||||
let markdownFile = path.join(contentFolderPath, 'markdown.md');
|
||||
let dataFolderPath: string = path.join(bookFolderPath, '_data');
|
||||
let contentFolderPath: string = path.join(bookFolderPath, 'content');
|
||||
let configFile: string = path.join(bookFolderPath, '_config.yml');
|
||||
let tableOfContentsFile: string = path.join(dataFolderPath, 'toc.yml');
|
||||
let notebook1File: string = path.join(contentFolderPath, 'notebook1.ipynb');
|
||||
let notebook2File: string = path.join(contentFolderPath, 'notebook2.ipynb');
|
||||
let notebook3File: string = path.join(contentFolderPath, 'notebook3.ipynb');
|
||||
let markdownFile: string = path.join(contentFolderPath, 'markdown.md');
|
||||
expectedNotebook1 = {
|
||||
// tslint:disable-next-line: quotemark
|
||||
title: 'Notebook1',
|
||||
url: '/notebook1',
|
||||
previousUri: undefined,
|
||||
@@ -185,7 +188,7 @@ describe('BookTreeViewProviderTests', function() {
|
||||
equalBookItems(notebook3, expectedNotebook3);
|
||||
});
|
||||
|
||||
this.afterAll(async function () {
|
||||
this.afterAll(async function (): Promise<void> {
|
||||
console.log('Removing temporary files...');
|
||||
if (await exists(rootFolderPath)) {
|
||||
await promisify(rimraf)(rootFolderPath);
|
||||
@@ -204,9 +207,9 @@ describe('BookTreeViewProviderTests', function() {
|
||||
|
||||
this.beforeAll(async () => {
|
||||
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');
|
||||
let tableOfContentsFileIgnore = path.join(rootFolderPath, 'toc.yml');
|
||||
let tableOfContentsFileIgnore: string = path.join(rootFolderPath, 'toc.yml');
|
||||
await fs.mkdir(rootFolderPath);
|
||||
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');
|
||||
@@ -229,7 +232,7 @@ describe('BookTreeViewProviderTests', function() {
|
||||
}
|
||||
});
|
||||
|
||||
this.afterAll(async function () {
|
||||
this.afterAll(async function (): Promise<void> {
|
||||
if (await exists(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 configFile: string;
|
||||
let folder: vscode.WorkspaceFolder;
|
||||
@@ -246,7 +249,7 @@ describe('BookTreeViewProviderTests', function() {
|
||||
|
||||
this.beforeAll(async () => {
|
||||
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');
|
||||
tocFile = path.join(dataFolderPath, 'toc.yml');
|
||||
await fs.mkdir(rootFolderPath);
|
||||
@@ -265,16 +268,16 @@ describe('BookTreeViewProviderTests', function() {
|
||||
|
||||
it('should show error message if config.yml file not found', async () => {
|
||||
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 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)) {
|
||||
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 tableOfContentsFile: string;
|
||||
let bookTreeViewProvider: BookTreeViewProvider;
|
||||
let folder: vscode.WorkspaceFolder;
|
||||
let expectedNotebook2: ExpectedBookItem;
|
||||
let expectedNotebook2: IExpectedBookItem;
|
||||
|
||||
this.beforeAll(async () => {
|
||||
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'); })]);
|
||||
});
|
||||
|
||||
it('should show error if notebook or markdown file is missing', async function(): Promise<void> {
|
||||
let books = bookTreeViewProvider.currentBook.bookItems;
|
||||
it('should show error if notebook or markdown file is missing', async function (): Promise<void> {
|
||||
let books: BookTreeItem[] = bookTreeViewProvider.currentBook.bookItems;
|
||||
let children = await bookTreeViewProvider.currentBook.getSections({ sections: [] }, books[0].sections, rootFolderPath);
|
||||
should(bookTreeViewProvider.errorMessage).equal('Missing file : Notebook1');
|
||||
// Rest of book should be detected correctly even with a missing file
|
||||
should(bookTreeViewProvider.currentBook.errorMessage).equal('Missing file : Notebook1');
|
||||
// rest of book should be detected correctly even with a missing file
|
||||
equalBookItems(children[0], expectedNotebook2);
|
||||
});
|
||||
|
||||
this.afterAll(async function () {
|
||||
this.afterAll(async function (): Promise<void> {
|
||||
if (await exists(rootFolderPath)) {
|
||||
await promisify(rimraf)(rootFolderPath);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user