Skip to content

Commit

Permalink
* pretest is no longer needed (jest can parse ts files)
Browse files Browse the repository at this point in the history
* remove unneeded imports
* add mocks to global mocks
*
  • Loading branch information
Jason Williams committed Sep 25, 2020
1 parent 9e610a1 commit d49dff9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 24 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@
"compile": "webpack --mode production",
"lint": "eslint src --ext ts",
"watch": "webpack --mode development --watch",
"pretest": "yarn run compile && yarn run lint",
"test": "jest",
"test-compile": "tsc -p ./",
"vscode:prepublish": "webpack --mode production",
Expand Down
18 changes: 17 additions & 1 deletion src/__mocks__/vscode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,23 @@ const window = {
};

const workspace = {
getConfiguration: jest.fn(),
getConfiguration: jest.fn(() => ({
get: jest.fn((val: string) => {
switch (val) {
case "card.frontBackSeparator":
return "%";
case "card.separator":
return "(?=^##\\s)";
case "card.tagPattern":
return "^\\[#(.*)\\]";
case "card.createTagForTitle":
return true;

default:
break;
}
}),
})),
workspaceFolders: [],
getWorkspaceFolder: jest.fn(),

Expand Down
3 changes: 0 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import {
workspace,
Disposable,
} from "vscode";
import path from "path";
import { readFileSync } from "fs";
import { AnkiService } from "./AnkiService";
import { AnkiCardProvider } from "./AnkiCardProvider";
import {
Expand All @@ -18,7 +16,6 @@ import {
} from "@vscode-logging/logger";
import { initLogger, getLogger } from "./logger";
import { registerCommands } from "./commands";
import { createOrUpdateTemplate } from "./manageTemplate";
import semver from "semver";
import { subscriptions } from "./subscriptions";
import { AnkiFS, initFilesystem } from "./fileSystemProvider";
Expand Down
19 changes: 0 additions & 19 deletions src/markdown/parsers/__tests__/cardParser.test.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,9 @@
import assert from "assert";
import { CardParser } from "../cardParser";
import { workspace } from "vscode";
import { Card } from "../../../models/Card";

// Setup mocks for cardParser
jest.mock("vscode");
const config = workspace.getConfiguration as any;
config.mockImplementation(() => ({
get: jest.fn((val: string) => {
switch (val) {
case "card.frontBackSeparator":
return "%";
case "card.separator":
return "(?=^##\\s)";
case "card.tagPattern":
return "^\\[#(.*)\\]";
case "card.createTagForTitle":
return true;

default:
break;
}
}),
}));

describe("CardParser", () => {
afterAll(() => {
Expand Down

0 comments on commit d49dff9

Please sign in to comment.