Skip to content

Commit

Permalink
Merge pull request #1006 from TriliumNext/chore_move-test-files
Browse files Browse the repository at this point in the history
chore: clean up and move test files next to actual files
  • Loading branch information
eliandoran authored Jan 18, 2025
2 parents 6583177 + c9619e1 commit 9025516
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 457 deletions.
5 changes: 0 additions & 5 deletions spec/etapi/notes.spec.ts

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it, expect } from "vitest";
import attributeParser from "../src/public/app/services/attribute_parser.ts";
import attributeParser from "./attribute_parser.js";


describe("Lexing", () => {
Expand Down Expand Up @@ -41,7 +41,9 @@ describe("Lexing", () => {
});

describe.todo("Parser", () => {
/* #TODO
it("simple label", () => {
const attrs = attributeParser.parse(["#token"].map((t: any) => ({ text: t })));
expect(attrs.length).toEqual(1);
Expand Down Expand Up @@ -85,6 +87,7 @@ describe.todo("Parser", () => {
expect(attrs[0].name).toEqual("token");
expect(attrs[0].value).toEqual("NFi2gL4xtPxM");
});
*/
});

describe("error cases", () => {
Expand Down
14 changes: 7 additions & 7 deletions spec-es6/data_dir.spec.ts → src/services/data_dir.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it, expect, beforeEach, vi } from "vitest";

import type { getTriliumDataDir as getTriliumDataDirType, getDataDirs as getDataDirsType, getPlatformAppDataDir as getPlatformAppDataDirType } from "../src/services/data_dir";
import type { getTriliumDataDir as getTriliumDataDirType, getDataDirs as getDataDirsType, getPlatformAppDataDir as getPlatformAppDataDirType } from "./data_dir.js";

describe("data_dir.ts unit tests", async () => {
let getTriliumDataDir: typeof getTriliumDataDirType;
Expand Down Expand Up @@ -42,9 +42,9 @@ describe("data_dir.ts unit tests", async () => {
});

// import function to test now, after creating the mocks
({ getTriliumDataDir } = await import("../src/services/data_dir.ts"));
({ getPlatformAppDataDir } = await import("../src/services/data_dir.ts"));
({ getDataDirs } = await import("../src/services/data_dir.ts"));
({ getTriliumDataDir } = await import("./data_dir.js"));
({ getPlatformAppDataDir } = await import("./data_dir.js"));
({ getDataDirs } = await import("./data_dir.js"));

// helper to reset call counts
const resetAllMocks = () => {
Expand Down Expand Up @@ -287,7 +287,7 @@ describe("data_dir.ts unit tests", async () => {
const result = getDataDirs(`${mockValuePrefix}_TRILIUM_DATA_DIR`);

for (const key in result) {
expect(result[key]).toEqual(`${mockValuePrefix}_${key}`);
expect(result[key as keyof typeof result]).toEqual(`${mockValuePrefix}_${key}`);
}
});

Expand All @@ -302,7 +302,7 @@ describe("data_dir.ts unit tests", async () => {
const result = getDataDirs(mockDataDir);

for (const key in result) {
expect(result[key].startsWith(mockDataDir)).toBeTruthy();
expect(result[key as keyof typeof result].startsWith(mockDataDir)).toBeTruthy();
}

mockFn.pathJoinMock.mockReset();
Expand Down Expand Up @@ -335,7 +335,7 @@ describe("data_dir.ts unit tests", async () => {
if (typeof changeAttemptResult === "string") {
// if it didn't throw above: assert that it did not change the value of it or any other keys of the object
for (const key in result) {
expect(result[key].startsWith(mockDataDirBase)).toBeTruthy();
expect(result[key as keyof typeof result].startsWith(mockDataDirBase)).toBeTruthy();
}
} else {
expect(changeAttemptResult).toBeInstanceOf(TypeError);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, describe, it } from "vitest";
import sanitizeAttributeName from "../src/services/sanitize_attribute_name";
import sanitizeAttributeName from "./sanitize_attribute_name.js";

// fn value, expected value
const testCases: [fnValue: string, expectedValue: string][] = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it, expect } from "vitest";
import handleParens from "../../src/services/search/services/handle_parens.js";
import type { TokenStructure } from "../../src/services/search/services/types.js";
import handleParens from "./handle_parens.js";
import type { TokenStructure } from "./types.js";

describe("Parens handler", () => {
it("handles parens", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it, expect } from "vitest";
import lex from "../../src/services/search/services/lex.js";
import lex from "./lex.js";

describe("Lexer fulltext", () => {
it("simple lexing", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { describe, it, expect } from "vitest";
import AndExp from "../../src/services/search/expressions/and.js";
import AttributeExistsExp from "../../src/services/search/expressions/attribute_exists.js";
import type Expression from "../../src/services/search/expressions/expression.js";
import LabelComparisonExp from "../../src/services/search/expressions/label_comparison.js";
import NotExp from "../../src/services/search/expressions/not.js";
import NoteContentFulltextExp from "../../src/services/search/expressions/note_content_fulltext.js";
import NoteFlatTextExp from "../../src/services/search/expressions/note_flat_text.js";
import OrExp from "../../src/services/search/expressions/or.js";
import OrderByAndLimitExp from "../../src/services/search/expressions/order_by_and_limit.js";
import PropertyComparisonExp from "../../src/services/search/expressions/property_comparison.js";
import SearchContext from "../../src/services/search/search_context.js";
import { default as parseInternal, type ParseOpts } from "../../src/services/search/services/parse.js";
import AndExp from "../../search/expressions/and.js";
import AttributeExistsExp from "../../search/expressions/attribute_exists.js";
import type Expression from "../../search/expressions/expression.js";
import LabelComparisonExp from "../../search/expressions/label_comparison.js";
import NotExp from "../../search/expressions/not.js";
import NoteContentFulltextExp from "../../search/expressions/note_content_fulltext.js";
import NoteFlatTextExp from "../../search/expressions/note_flat_text.js";
import OrExp from "../../search/expressions/or.js";
import OrderByAndLimitExp from "../../search/expressions/order_by_and_limit.js";
import PropertyComparisonExp from "../../search/expressions/property_comparison.js";
import SearchContext from "../../search/search_context.js";
import { default as parseInternal, type ParseOpts } from "./parse.js";

describe("Parser", () => {
it("fulltext parser without content", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { describe, it, expect, beforeEach, } from "vitest";
import searchService from "../../src/services/search/services/search.js";
import BNote from "../../src/becca/entities/bnote.js";
import BBranch from "../../src/becca/entities/bbranch.js";
import SearchContext from "../../src/services/search/search_context.js";
import dateUtils from "../../src/services/date_utils.js";
import becca from "../../src/becca/becca.js";
import becca_mocking from "./becca_mocking.js";
import searchService from "./search.js";
import BNote from "../../../becca/entities/bnote.js";
import BBranch from "../../../becca/entities/bbranch.js";
import SearchContext from "../search_context.js";
import dateUtils from "../../date_utils.js";
import becca from "../../../becca/becca.js";
import becca_mocking from "../../../../spec/support/becca_mocking.js";

describe("Search", () => {
let rootNote: any;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, it, expect, beforeEach } from "vitest";
import becca_mocking from "./becca_mocking.js";
import ValueExtractor from "../../src/services/search/value_extractor.js";
import becca from "../../src/becca/becca.js";
import SearchContext from "../../src/services/search/search_context.js";
import becca_mocking from "../../../spec/support/becca_mocking.js";
import ValueExtractor from "./value_extractor.js";
import becca from "../../becca/becca.js";
import SearchContext from "./search_context.js";

const dsc = new SearchContext();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, describe, it } from "vitest";
import { formatDownloadTitle } from "../../src/services/utils.ts";
import { formatDownloadTitle } from "./utils.js";

const testCases: [fnValue: Parameters<typeof formatDownloadTitle>, expectedValue: ReturnType<typeof formatDownloadTitle>][] = [
// empty fileName tests
Expand Down
Loading

0 comments on commit 9025516

Please sign in to comment.