mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Fix book unit tests (#6633)
* remove sync methods * added assertion to log error * create random folder * change variable name to be more descriptive * Update book.test.ts * Update book.test.ts
This commit is contained in:
@@ -3,89 +3,101 @@
|
|||||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||||
*--------------------------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
// import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
// import * as should from 'should';
|
import * as should from 'should';
|
||||||
// import * as TypeMoq from 'typemoq';
|
import * as TypeMoq from 'typemoq';
|
||||||
// import * as path from 'path';
|
import * as path from 'path';
|
||||||
// import * as fs from 'fs';
|
import * as fs from 'fs-extra';
|
||||||
// import * as rimraf from 'rimraf';
|
import * as rimraf from 'rimraf';
|
||||||
// import * as os from 'os';
|
import * as os from 'os';
|
||||||
// import { BookTreeViewProvider } from '../../book/bookTreeView';
|
import { BookTreeViewProvider } from '../../book/bookTreeView';
|
||||||
// import { BookTreeItem } from '../../book/bookTreeItem';
|
import { BookTreeItem } from '../../book/bookTreeItem';
|
||||||
|
import * as assert from 'assert';
|
||||||
|
|
||||||
// describe('BookTreeViewProvider.getChildren', function (): void {
|
const SEED = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||||
// const rootFolderPath = path.join(os.tmpdir(), 'testBook');
|
|
||||||
// const dataFolderPath = path.join(rootFolderPath, '_data');
|
|
||||||
// const contentFolderPath = path.join(rootFolderPath, 'content');
|
|
||||||
// const configFile = path.join(rootFolderPath, '_config.yml');
|
|
||||||
// const tableOfContentsFile = path.join(dataFolderPath, 'toc.yml');
|
|
||||||
// const notebookFile = path.join(contentFolderPath, 'notebook.ipynb');
|
|
||||||
// const markdownFile = path.join(contentFolderPath, 'markdown.md');
|
|
||||||
// const expectedNotebook = {
|
|
||||||
// title: 'Notebook',
|
|
||||||
// url: '/notebook'
|
|
||||||
// };
|
|
||||||
// const expectedMarkdown = {
|
|
||||||
// title: 'Markdown',
|
|
||||||
// url: '/markdown'
|
|
||||||
// };
|
|
||||||
// const expectedExternalLink = {
|
|
||||||
// title: 'GitHub',
|
|
||||||
// url: 'https://github.com/',
|
|
||||||
// external: true
|
|
||||||
// };
|
|
||||||
// const expectedBook = {
|
|
||||||
// sections: [expectedNotebook, expectedMarkdown, expectedExternalLink],
|
|
||||||
// title: 'Test Book'
|
|
||||||
// };
|
|
||||||
|
|
||||||
// let mockExtensionContext: TypeMoq.IMock<vscode.ExtensionContext>;
|
describe('BookTreeViewProvider.getChildren', function (): void {
|
||||||
// let bookTreeViewProvider: BookTreeViewProvider;
|
let rootFolderPath: string;
|
||||||
// let book: BookTreeItem;
|
const expectedNotebook = {
|
||||||
|
title: 'Notebook',
|
||||||
|
url: '/notebook'
|
||||||
|
};
|
||||||
|
const expectedMarkdown = {
|
||||||
|
title: 'Markdown',
|
||||||
|
url: '/markdown'
|
||||||
|
};
|
||||||
|
const expectedExternalLink = {
|
||||||
|
title: 'GitHub',
|
||||||
|
url: 'https://github.com/',
|
||||||
|
external: true
|
||||||
|
};
|
||||||
|
const expectedBook = {
|
||||||
|
sections: [expectedNotebook, expectedMarkdown, expectedExternalLink],
|
||||||
|
title: 'Test Book'
|
||||||
|
};
|
||||||
|
|
||||||
// this.beforeAll(async () => {
|
let mockExtensionContext: TypeMoq.IMock<vscode.ExtensionContext>;
|
||||||
// fs.mkdirSync(rootFolderPath);
|
let bookTreeViewProvider: BookTreeViewProvider;
|
||||||
// fs.mkdirSync(dataFolderPath);
|
let book: BookTreeItem;
|
||||||
// fs.mkdirSync(contentFolderPath);
|
|
||||||
// fs.writeFileSync(configFile, 'title: Test Book');
|
|
||||||
// fs.writeFileSync(tableOfContentsFile, '- title: Notebook\n url: /notebook\n- title: Markdown\n url: /markdown\n- title: GitHub\n url: https://github.com/\n external: true');
|
|
||||||
// fs.writeFileSync(notebookFile, '');
|
|
||||||
// fs.writeFileSync(markdownFile, '');
|
|
||||||
// mockExtensionContext = TypeMoq.Mock.ofType<vscode.ExtensionContext>();
|
|
||||||
// let folder: vscode.WorkspaceFolder = {
|
|
||||||
// uri: vscode.Uri.parse(rootFolderPath),
|
|
||||||
// name: '',
|
|
||||||
// index: 0
|
|
||||||
// };
|
|
||||||
// bookTreeViewProvider = new BookTreeViewProvider([folder], mockExtensionContext.object);
|
|
||||||
// });
|
|
||||||
|
|
||||||
// it('should return all book nodes when element is undefined', async function (): Promise<void> {
|
this.beforeAll(async () => {
|
||||||
// const children = await bookTreeViewProvider.getChildren();
|
try {
|
||||||
// should(children).be.Array();
|
let testFolder = '';
|
||||||
// should(children.length).equal(1);
|
for (let i = 0; i < 8; i++) {
|
||||||
// book = children[0];
|
testFolder += SEED.charAt(Math.floor(Math.random() * SEED.length));
|
||||||
// should(book.title).equal(expectedBook.title);
|
}
|
||||||
// });
|
rootFolderPath = path.join(os.tmpdir(), 'BookTestData_' + testFolder);
|
||||||
|
let dataFolderPath = path.join(rootFolderPath, '_data');
|
||||||
|
let contentFolderPath = path.join(rootFolderPath, 'content');
|
||||||
|
let configFile = path.join(rootFolderPath, '_config.yml');
|
||||||
|
let tableOfContentsFile = path.join(dataFolderPath, 'toc.yml');
|
||||||
|
let notebookFile = path.join(contentFolderPath, 'notebook.ipynb');
|
||||||
|
let markdownFile = path.join(contentFolderPath, 'markdown.md');
|
||||||
|
await fs.mkdir(rootFolderPath);
|
||||||
|
await fs.mkdir(dataFolderPath);
|
||||||
|
await fs.mkdir(contentFolderPath);
|
||||||
|
await fs.writeFile(configFile, 'title: Test Book');
|
||||||
|
await fs.writeFile(tableOfContentsFile, '- title: Notebook\n url: /notebook\n- title: Markdown\n url: /markdown\n- title: GitHub\n url: https://github.com/\n external: true');
|
||||||
|
await fs.writeFile(notebookFile, '');
|
||||||
|
await fs.writeFile(markdownFile, '');
|
||||||
|
mockExtensionContext = TypeMoq.Mock.ofType<vscode.ExtensionContext>();
|
||||||
|
let folder: vscode.WorkspaceFolder = {
|
||||||
|
uri: vscode.Uri.file(rootFolderPath),
|
||||||
|
name: '',
|
||||||
|
index: 0
|
||||||
|
};
|
||||||
|
bookTreeViewProvider = new BookTreeViewProvider([folder], mockExtensionContext.object);
|
||||||
|
} catch (e) {
|
||||||
|
assert.ok(false, e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// it('should return all page nodes when element is a book', async function (): Promise<void> {
|
it('should return all book nodes when element is undefined', async function (): Promise<void> {
|
||||||
// const children = await bookTreeViewProvider.getChildren(book);
|
const children = await bookTreeViewProvider.getChildren();
|
||||||
// should(children).be.Array();
|
should(children).be.Array();
|
||||||
// should(children.length).equal(3);
|
should(children.length).equal(1);
|
||||||
// const notebook = children[0];
|
book = children[0];
|
||||||
// const markdown = children[1];
|
should(book.title).equal(expectedBook.title);
|
||||||
// const externalLink = children[2];
|
});
|
||||||
// should(notebook.title).equal(expectedNotebook.title);
|
|
||||||
// should(notebook.uri).equal(expectedNotebook.url);
|
|
||||||
// should(markdown.title).equal(expectedMarkdown.title);
|
|
||||||
// should(markdown.uri).equal(expectedMarkdown.url);
|
|
||||||
// should(externalLink.title).equal(expectedExternalLink.title);
|
|
||||||
// should(externalLink.uri).equal(expectedExternalLink.url);
|
|
||||||
// });
|
|
||||||
|
|
||||||
// after(async function () {
|
it('should return all page nodes when element is a book', async function (): Promise<void> {
|
||||||
// if (fs.existsSync(rootFolderPath)) {
|
const children = await bookTreeViewProvider.getChildren(book);
|
||||||
// rimraf.sync(rootFolderPath);
|
should(children).be.Array();
|
||||||
// }
|
should(children.length).equal(3);
|
||||||
// });
|
const notebook = children[0];
|
||||||
// });
|
const markdown = children[1];
|
||||||
|
const externalLink = children[2];
|
||||||
|
should(notebook.title).equal(expectedNotebook.title);
|
||||||
|
should(notebook.uri).equal(expectedNotebook.url);
|
||||||
|
should(markdown.title).equal(expectedMarkdown.title);
|
||||||
|
should(markdown.uri).equal(expectedMarkdown.url);
|
||||||
|
should(externalLink.title).equal(expectedExternalLink.title);
|
||||||
|
should(externalLink.uri).equal(expectedExternalLink.url);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.afterAll(async function () {
|
||||||
|
if (fs.existsSync(rootFolderPath)) {
|
||||||
|
rimraf.sync(rootFolderPath);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user