Skip to content

Commit a4b943f

Browse files
authored
Merge pull request #111 from KubrickCode/develop/shlee/90
test: standardize test file location and improve Jest configuration
2 parents 6e778a0 + aa58a44 commit a4b943f

17 files changed

+70
-40
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@
271271
"install-package": "code --install-extension quick-command-buttons-$npm_package_version.vsix",
272272
"lint": "pnpm lint:format && pnpm lint:extension && pnpm lint:view",
273273
"lint:config": "npx prettier --write \"**/*.{json,yml,yaml,md}\"",
274-
"lint:extension": "cd src && npx eslint --fix extension/main.ts internal pkg shared tests",
275-
"lint:format": "npx prettier --write \"src/{extension,internal,pkg,shared,tests}/**/*.ts\" \"src/view/src/**/*.{ts,tsx}\" \"**/*.{json,yml,yaml,md}\"",
274+
"lint:extension": "cd src && npx eslint --fix extension/main.ts internal pkg shared",
275+
"lint:format": "npx prettier --write \"src/{extension,internal,pkg,shared}/**/*.ts\" \"src/view/src/**/*.{ts,tsx}\" \"**/*.{json,yml,yaml,md}\"",
276276
"lint:view": "cd src/view && npx eslint --fix src/**/*.{ts,tsx}",
277277
"ovsx-publish": "ovsx publish",
278278
"package": "vsce package --no-dependencies --allow-star-activation && find . -maxdepth 1 -name '*.vsix' ! -name '*'$npm_package_version'.vsix' -delete",

src/eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default [
2727
},
2828
},
2929
{
30-
files: ["tests/**/*.ts"],
30+
files: ["**/*.spec.ts"],
3131
languageOptions: {
3232
parser: tseslint.parser,
3333
parserOptions: {

src/extension/__mocks__/zod.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Mock zod for Jest
2+
const mockZodObject = () => ({
3+
optional: () => mockZodObject(),
4+
parse: (value) => value,
5+
safeParse: (value) => ({ success: true, data: value }),
6+
});
7+
8+
const z = {
9+
string: () => mockZodObject(),
10+
boolean: () => mockZodObject(),
11+
array: () => mockZodObject(),
12+
object: () => mockZodObject(),
13+
lazy: () => mockZodObject(),
14+
ZodType: class ZodType {},
15+
};
16+
17+
module.exports = { z };

src/extension/jest.config.cjs

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,40 @@
11
/** @type {import('jest').Config} */
22
module.exports = {
3-
preset: "ts-jest",
4-
testEnvironment: "node",
5-
roots: ["<rootDir>/../tests"],
6-
testMatch: ["**/*.spec.ts"],
7-
transform: {
8-
"^.+\\.ts$": "ts-jest",
9-
},
3+
clearMocks: true,
104
collectCoverageFrom: [
11-
"../extension/**/*.ts",
12-
"../internal/**/*.ts",
13-
"../pkg/**/*.ts",
5+
"<rootDir>/extension/**/*.ts",
6+
"<rootDir>/internal/**/*.ts",
7+
"<rootDir>/pkg/**/*.ts",
148
"!**/*.d.ts",
159
"!**/*.spec.ts",
10+
"!**/__mocks__/**",
1611
],
17-
coverageDirectory: "coverage",
12+
coverageDirectory: "<rootDir>/extension/coverage",
1813
coverageReporters: ["text", "lcov", "html"],
14+
moduleDirectories: [
15+
"node_modules",
16+
"<rootDir>/extension/node_modules",
17+
"<rootDir>/../node_modules",
18+
],
1919
moduleFileExtensions: ["ts", "js", "json"],
20-
moduleDirectories: ["node_modules", "<rootDir>/node_modules"],
21-
verbose: true,
22-
clearMocks: true,
23-
restoreMocks: true,
2420
moduleNameMapper: {
25-
"^vscode$": "<rootDir>/__mocks__/vscode.js",
21+
"^vscode$": "<rootDir>/extension/__mocks__/vscode.js",
22+
"^zod$": "<rootDir>/extension/__mocks__/zod.js",
23+
},
24+
preset: "ts-jest",
25+
restoreMocks: true,
26+
rootDir: "..",
27+
roots: ["<rootDir>/extension", "<rootDir>/internal", "<rootDir>/pkg"],
28+
testEnvironment: "node",
29+
testMatch: ["**/*.spec.ts"],
30+
transform: {
31+
"^.+\\.ts$": [
32+
"ts-jest",
33+
{
34+
tsconfig: "<rootDir>/extension/tsconfig.json",
35+
},
36+
],
2637
},
38+
transformIgnorePatterns: ["node_modules/(?!(zod)/)"],
39+
verbose: true,
2740
};

src/tests/main.spec.ts renamed to src/extension/main.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as vscode from "vscode";
2-
import { registerCommands } from "../extension/main";
2+
import { registerCommands } from "./main";
33
import { ConfigManager } from "../internal/managers/config-manager";
44
import { StatusBarManager } from "../internal/managers/status-bar-manager";
55
import { TerminalManager } from "../internal/managers/terminal-manager";

src/extension/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "quick-command-buttons-extension",
33
"private": true,
44
"scripts": {
5-
"lint": "cd ../.. && npx prettier --write \"src/{extension,internal,pkg,shared,tests}/**/*.ts\" && cd src && npx eslint --fix extension/main.ts internal pkg shared tests"
5+
"lint": "cd ../.. && npx prettier --write \"src/{extension,internal,pkg,shared}/**/*.ts\" && cd src && npx eslint --fix extension/main.ts internal pkg shared"
66
},
77
"dependencies": {
88
"@indic-transliteration/sanscript": "1.3.3",

src/tests/adapters.spec.ts renamed to src/internal/adapters.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as vscode from "vscode";
2-
import { createVSCodeConfigReader } from "../internal/adapters";
2+
import { createVSCodeConfigReader } from "./adapters";
33

44
describe("adapters", () => {
55
beforeEach(() => {

src/tests/command-executor.spec.ts renamed to src/internal/command-executor.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
import { ButtonConfig } from "../pkg/types";
12
import {
23
determineButtonExecutionType,
34
executeCommandsRecursively,
45
executeTerminalCommand,
56
findShortcutItem,
67
validateShortcuts,
7-
} from "../internal/command-executor";
8-
import { createQuickPickItems } from "../internal/utils/ui-items";
9-
import { ButtonConfig } from "../pkg/types";
8+
} from "./command-executor";
9+
import { createQuickPickItems } from "./utils/ui-items";
1010

1111
describe("command-executor", () => {
1212
describe("validateShortcuts", () => {

src/tests/keyboard-layout-converter.spec.ts renamed to src/internal/keyboard-layout-converter.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
exactMatcher,
55
caseInsensitiveMatcher,
66
layoutAwareMatcher,
7-
} from "../internal/keyboard-layout-converter";
7+
} from "./keyboard-layout-converter";
88

99
describe("generateKeyVariants", () => {
1010
it("should return input key with case variations for single character", async () => {

src/tests/config-manager.spec.ts renamed to src/internal/managers/config-manager.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from "vscode";
2-
import { ConfigManager } from "../internal/managers/config-manager";
3-
import { CONFIGURATION_TARGETS } from "../pkg/config-constants";
2+
import { CONFIGURATION_TARGETS } from "../../pkg/config-constants";
3+
import { ConfigManager } from "./config-manager";
44

55
describe("ConfigManager", () => {
66
const createMockConfig = () => ({

0 commit comments

Comments
 (0)