Files
azuredatastudio/test/smoke/src/sql/areas/notebook/createBook.test.ts
Charles Gagnon 49562239a0 Add create content folder test (#15849)
* Add create book from content folder test

* Remove hardcoded
2021-06-22 08:56:50 -07:00

69 lines
2.9 KiB
TypeScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Application } from '../../../../../automation';
import { promises as fs } from 'fs';
import * as rimraf from 'rimraf';
import * as path from 'path';
import { assert } from 'console';
import * as tmp from 'tmp';
const CreateBookCommand = 'Jupyter Books: Create Jupyter Book';
const bookName = 'my-book';
export function setup() {
describe('CreateBookDialog', () => {
let tmpDir = '';
it('can create new book with default content folder', async function () {
const app = this.app as Application;
// Add timeout for giving time for the SQL Tools Service to start (it'll error if it's not started yet)
// TODO @chgagnon - Figure out better way to have tests wait for STS
await new Promise(r => setTimeout(r, 10000));
// eslint-disable-next-line no-sync
tmpDir = tmp.dirSync().name;
await app.workbench.quickaccess.runCommand(CreateBookCommand);
await app.workbench.createBookDialog.setName(bookName);
await app.workbench.createBookDialog.setLocation(tmpDir);
await app.workbench.createBookDialog.create();
const bookExists = await fs.stat(path.join(tmpDir, bookName));
assert(!!bookExists, 'Book was not created');
await new Promise(r => setTimeout(r, 2500));
});
it('can create new book with specified content folder', async function () {
const app = this.app as Application;
// Add timeout for giving time for the SQL Tools Service to start (it'll error if it's not started yet)
// TODO @chgagnon - Figure out better way to have tests wait for STS
await new Promise(r => setTimeout(r, 10000));
// eslint-disable-next-line no-sync
tmpDir = tmp.dirSync().name;
// Our content folder is just the workspace folder containing the test notebooks
const contentFolder = path.join(app.workspacePathOrFolder, 'Notebooks');
await app.workbench.quickaccess.runCommand(CreateBookCommand);
await app.workbench.createBookDialog.setName(bookName);
await app.workbench.createBookDialog.setLocation(tmpDir);
await app.workbench.createBookDialog.setContentFolder(contentFolder);
await app.workbench.createBookDialog.create();
const bookExists = await fs.stat(path.join(tmpDir, bookName));
assert(!!bookExists, 'Book was not created');
const contentNotebookExists = await fs.stat(path.join(tmpDir, bookName, 'hello.ipynb'));
assert(!!contentNotebookExists, 'Notebook from content folder wasn\'t copied over');
await new Promise(r => setTimeout(r, 2500));
});
afterEach(async function () {
if (tmpDir) {
try {
rimraf.sync(tmpDir);
} catch (err) {
// Try our best to clean up but don't fail the test if we can't
}
}
});
});
}