Skip to content

Commit

Permalink
Add unit test for test discovery
Browse files Browse the repository at this point in the history
When directory is not present.
  • Loading branch information
aeisenberg committed Dec 15, 2020
1 parent 303cb32 commit ca9510c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion extensions/ql-vscode/src/databases-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@ 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 () => {
const baseUri = Uri.parse('file:/a/b');
const baseDir = baseUri.fsPath;
const cDir = Uri.parse('file:/a/b/c').fsPath;
const dFile = Uri.parse('file:/a/b/c/d.ql').fsPath;
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 sandbox: sinon.SinonSandbox;

const baseUri = Uri.parse('file:/a/b');
const baseDir = baseUri.fsPath;
const cDir = Uri.parse('file:/a/b/c').fsPath;
const dFile = Uri.parse('file:/a/b/c/d.ql').fsPath;
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;
let qlTestDiscover: QLTestDiscovery;

beforeEach(() => {
sandbox = sinon.createSandbox();
qlTestDiscover = new QLTestDiscovery(
{
uri: baseUri,
name: 'My tests'
Expand All @@ -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);
Expand All @@ -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);
});
});
});

0 comments on commit ca9510c

Please sign in to comment.