Add unit test for test discovery

When directory is not present.
This commit is contained in:
Andrew Eisenberg
2020-12-14 15:54:46 -08:00
parent 303cb3284c
commit ca9510c08d
2 changed files with 36 additions and 10 deletions

View File

@@ -384,7 +384,7 @@ export class DatabaseUI extends DisposableObject {
!(await fs.pathExists(this.storagePath) ||
!(await fs.stat(this.storagePath)).isDirectory())
) {
// ignore a missing or invalid storage directory.
logger.log('Missing or invalid storage directory. Not trying to remove orphaned databases.');
return;
}

View File

@@ -2,12 +2,15 @@ import 'vscode-test';
import 'mocha';
import { Uri, WorkspaceFolder } from 'vscode';
import { expect } from 'chai';
import * as fs from 'fs-extra';
import * as sinon from 'sinon';
import { QLTestDiscovery } from '../../qltest-discovery';
describe('qltest-discovery', () => {
describe('discoverTests', () => {
it('should run discovery', async () => {
let sandbox: sinon.SinonSandbox;
const baseUri = Uri.parse('file:/a/b');
const baseDir = baseUri.fsPath;
const cDir = Uri.parse('file:/a/b/c').fsPath;
@@ -15,7 +18,11 @@ describe('qltest-discovery', () => {
const eFile = Uri.parse('file:/a/b/c/e.ql').fsPath;
const hDir = Uri.parse('file:/a/b/c/f/g/h').fsPath;
const iFile = Uri.parse('file:/a/b/c/f/g/h/i.ql').fsPath;
const qlTestDiscover = new QLTestDiscovery(
let qlTestDiscover: QLTestDiscovery;
beforeEach(() => {
sandbox = sinon.createSandbox();
qlTestDiscover = new QLTestDiscovery(
{
uri: baseUri,
name: 'My tests'
@@ -31,6 +38,15 @@ describe('qltest-discovery', () => {
} as any
);
});
afterEach(() => {
sandbox.restore();
});
it('should run discovery', async () => {
sandbox.stub(fs, 'pathExists').resolves(true);
const result = await (qlTestDiscover as any).discover();
expect(result.watchPath).to.eq(baseDir);
expect(result.testDirectory.path).to.eq(baseDir);
@@ -56,5 +72,15 @@ describe('qltest-discovery', () => {
expect(children[0].path).to.eq(iFile);
expect(children[0].name).to.eq('i.ql');
});
it('should avoid discovery if a folder does not exist', async () => {
sandbox.stub(fs, 'pathExists').resolves(false);
const result = await (qlTestDiscover as any).discover();
expect(result.watchPath).to.eq(baseDir);
expect(result.testDirectory.path).to.eq(baseDir);
expect(result.testDirectory.name).to.eq('My tests');
expect(result.testDirectory.children.length).to.eq(0);
});
});
});