Skip to content

Commit a85281e

Browse files
committed
Be able to pass custom db options to mock
We will use this to set/unset the language on a database item. This will then be used to determine whether we need to create a QL pack.
1 parent 99f3d28 commit a85281e

1 file changed

Lines changed: 54 additions & 11 deletions

File tree

extensions/ql-vscode/test/vscode-tests/minimal-workspace/databases.test.ts

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,21 @@ describe("databases", () => {
289289

290290
describe("resolveSourceFile", () => {
291291
it("should fail to resolve when not a uri", () => {
292-
const db = createMockDB(Uri.parse("file:/sourceArchive-uri/"));
292+
const db = createMockDB(
293+
MOCK_DB_OPTIONS,
294+
Uri.parse("file:/sourceArchive-uri/"),
295+
);
293296
(db as any)._contents.sourceArchiveUri = undefined;
294297
expect(() => db.resolveSourceFile("abc")).toThrowError(
295298
"Scheme is missing",
296299
);
297300
});
298301

299302
it("should fail to resolve when not a file uri", () => {
300-
const db = createMockDB(Uri.parse("file:/sourceArchive-uri/"));
303+
const db = createMockDB(
304+
MOCK_DB_OPTIONS,
305+
Uri.parse("file:/sourceArchive-uri/"),
306+
);
301307
(db as any)._contents.sourceArchiveUri = undefined;
302308
expect(() => db.resolveSourceFile("http://abc")).toThrowError(
303309
"Invalid uri scheme",
@@ -306,14 +312,20 @@ describe("databases", () => {
306312

307313
describe("no source archive", () => {
308314
it("should resolve undefined", () => {
309-
const db = createMockDB(Uri.parse("file:/sourceArchive-uri/"));
315+
const db = createMockDB(
316+
MOCK_DB_OPTIONS,
317+
Uri.parse("file:/sourceArchive-uri/"),
318+
);
310319
(db as any)._contents.sourceArchiveUri = undefined;
311320
const resolved = db.resolveSourceFile(undefined);
312321
expect(resolved.toString(true)).toBe(dbLocationUri().toString(true));
313322
});
314323

315324
it("should resolve an empty file", () => {
316-
const db = createMockDB(Uri.parse("file:/sourceArchive-uri/"));
325+
const db = createMockDB(
326+
MOCK_DB_OPTIONS,
327+
Uri.parse("file:/sourceArchive-uri/"),
328+
);
317329
(db as any)._contents.sourceArchiveUri = undefined;
318330
const resolved = db.resolveSourceFile("file:");
319331
expect(resolved.toString()).toBe("file:///");
@@ -323,6 +335,7 @@ describe("databases", () => {
323335
describe("zipped source archive", () => {
324336
it("should encode a source archive url", () => {
325337
const db = createMockDB(
338+
MOCK_DB_OPTIONS,
326339
encodeSourceArchiveUri({
327340
sourceArchiveZipPath: "sourceArchive-uri",
328341
pathWithinSourceArchive: "def",
@@ -342,6 +355,7 @@ describe("databases", () => {
342355

343356
it("should encode a source archive url with trailing slash", () => {
344357
const db = createMockDB(
358+
MOCK_DB_OPTIONS,
345359
encodeSourceArchiveUri({
346360
sourceArchiveZipPath: "sourceArchive-uri",
347361
pathWithinSourceArchive: "def/",
@@ -361,6 +375,7 @@ describe("databases", () => {
361375

362376
it("should encode an empty source archive url", () => {
363377
const db = createMockDB(
378+
MOCK_DB_OPTIONS,
364379
encodeSourceArchiveUri({
365380
sourceArchiveZipPath: "sourceArchive-uri",
366381
pathWithinSourceArchive: "def",
@@ -374,7 +389,10 @@ describe("databases", () => {
374389
});
375390

376391
it("should handle an empty file", () => {
377-
const db = createMockDB(Uri.parse("file:/sourceArchive-uri/"));
392+
const db = createMockDB(
393+
MOCK_DB_OPTIONS,
394+
Uri.parse("file:/sourceArchive-uri/"),
395+
);
378396
const resolved = db.resolveSourceFile("");
379397
expect(resolved.toString()).toBe("file:///sourceArchive-uri/");
380398
});
@@ -417,12 +435,17 @@ describe("databases", () => {
417435
});
418436

419437
it("should return true for testproj database in test directory", async () => {
420-
const db = createMockDB(sourceLocationUri(), Uri.file(projectPath));
438+
const db = createMockDB(
439+
MOCK_DB_OPTIONS,
440+
sourceLocationUri(),
441+
Uri.file(projectPath),
442+
);
421443
expect(await db.isAffectedByTest(directoryPath)).toBe(true);
422444
});
423445

424446
it("should return false for non-existent test directory", async () => {
425447
const db = createMockDB(
448+
MOCK_DB_OPTIONS,
426449
sourceLocationUri(),
427450
Uri.file(join(dir.name, "non-existent/non-existent.testproj")),
428451
);
@@ -436,6 +459,7 @@ describe("databases", () => {
436459
await fs.writeFile(anotherProjectPath, "");
437460

438461
const db = createMockDB(
462+
MOCK_DB_OPTIONS,
439463
sourceLocationUri(),
440464
Uri.file(anotherProjectPath),
441465
);
@@ -449,27 +473,40 @@ describe("databases", () => {
449473
await fs.writeFile(anotherProjectPath, "");
450474

451475
const db = createMockDB(
476+
MOCK_DB_OPTIONS,
452477
sourceLocationUri(),
453478
Uri.file(anotherProjectPath),
454479
);
455480
expect(await db.isAffectedByTest(directoryPath)).toBe(false);
456481
});
457482

458483
it("should return false for testproj database for prefix directory", async () => {
459-
const db = createMockDB(sourceLocationUri(), Uri.file(projectPath));
484+
const db = createMockDB(
485+
MOCK_DB_OPTIONS,
486+
sourceLocationUri(),
487+
Uri.file(projectPath),
488+
);
460489
// /d is a prefix of /dir/dir.testproj, but
461490
// /dir/dir.testproj is not under /d
462491
expect(await db.isAffectedByTest(join(directoryPath, "d"))).toBe(false);
463492
});
464493

465494
it("should return true for testproj database for test file", async () => {
466-
const db = createMockDB(sourceLocationUri(), Uri.file(projectPath));
495+
const db = createMockDB(
496+
MOCK_DB_OPTIONS,
497+
sourceLocationUri(),
498+
Uri.file(projectPath),
499+
);
467500
expect(await db.isAffectedByTest(qlFilePath)).toBe(true);
468501
});
469502

470503
it("should return false for non-existent test file", async () => {
471504
const otherTestFile = join(directoryPath, "other-test.ql");
472-
const db = createMockDB(sourceLocationUri(), Uri.file(projectPath));
505+
const db = createMockDB(
506+
MOCK_DB_OPTIONS,
507+
sourceLocationUri(),
508+
Uri.file(projectPath),
509+
);
473510
expect(await db.isAffectedByTest(otherTestFile)).toBe(false);
474511
});
475512

@@ -478,6 +515,7 @@ describe("databases", () => {
478515
await fs.writeFile(anotherProjectPath, "");
479516

480517
const db = createMockDB(
518+
MOCK_DB_OPTIONS,
481519
sourceLocationUri(),
482520
Uri.file(anotherProjectPath),
483521
);
@@ -488,7 +526,11 @@ describe("databases", () => {
488526
const otherTestFile = join(dir.name, "test.ql");
489527
await fs.writeFile(otherTestFile, "");
490528

491-
const db = createMockDB(sourceLocationUri(), Uri.file(projectPath));
529+
const db = createMockDB(
530+
MOCK_DB_OPTIONS,
531+
sourceLocationUri(),
532+
Uri.file(projectPath),
533+
);
492534
expect(await db.isAffectedByTest(otherTestFile)).toBe(false);
493535
});
494536
});
@@ -533,6 +575,7 @@ describe("databases", () => {
533575
});
534576

535577
function createMockDB(
578+
mockDbOptions = MOCK_DB_OPTIONS,
536579
// source archive location must be a real(-ish) location since
537580
// tests will add this to the workspace location
538581
sourceArchiveUri = sourceLocationUri(),
@@ -544,7 +587,7 @@ describe("databases", () => {
544587
sourceArchiveUri,
545588
datasetUri: databaseUri,
546589
} as DatabaseContents,
547-
MOCK_DB_OPTIONS,
590+
mockDbOptions,
548591
() => void 0,
549592
);
550593
}

0 commit comments

Comments
 (0)