From 6476c43695d020ace82c9024e5461863e3d57257 Mon Sep 17 00:00:00 2001 From: sam hoang Date: Wed, 15 Jan 2025 21:10:14 +0700 Subject: [PATCH] test: enhance jest test setup and add documentation structure Add vscrui to jest transform ignore patterns Add crypto.getRandomValues mock for tests Initialize cline documentation structure with required files --- webview-ui/config-overrides.js | 2 +- webview-ui/src/setupTests.ts | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/webview-ui/config-overrides.js b/webview-ui/config-overrides.js index 2078f36..857b363 100644 --- a/webview-ui/config-overrides.js +++ b/webview-ui/config-overrides.js @@ -15,7 +15,7 @@ module.exports.jest = function(config) { // Configure transform ignore patterns for ES modules config.transformIgnorePatterns = [ - '/node_modules/(?!(rehype-highlight|react-remark|unist-util-visit|unist-util-find-after|vfile|unified|bail|is-plain-obj|trough|vfile-message|unist-util-stringify-position|mdast-util-from-markdown|mdast-util-to-string|micromark|decode-named-character-reference|character-entities|markdown-table|zwitch|longest-streak|escape-string-regexp|unist-util-is|hast-util-to-text|@vscode/webview-ui-toolkit|@microsoft/fast-react-wrapper|@microsoft/fast-element|@microsoft/fast-foundation|@microsoft/fast-web-utilities|exenv-es6)/)' + '/node_modules/(?!(rehype-highlight|react-remark|unist-util-visit|unist-util-find-after|vfile|unified|bail|is-plain-obj|trough|vfile-message|unist-util-stringify-position|mdast-util-from-markdown|mdast-util-to-string|micromark|decode-named-character-reference|character-entities|markdown-table|zwitch|longest-streak|escape-string-regexp|unist-util-is|hast-util-to-text|@vscode/webview-ui-toolkit|@microsoft/fast-react-wrapper|@microsoft/fast-element|@microsoft/fast-foundation|@microsoft/fast-web-utilities|exenv-es6|vscrui)/)' ]; return config; diff --git a/webview-ui/src/setupTests.ts b/webview-ui/src/setupTests.ts index dbba64a..b59e605 100644 --- a/webview-ui/src/setupTests.ts +++ b/webview-ui/src/setupTests.ts @@ -1,14 +1,26 @@ import '@testing-library/jest-dom'; -// Mock window.matchMedia +// Mock crypto.getRandomValues +Object.defineProperty(window, 'crypto', { + value: { + getRandomValues: function(buffer: Uint8Array) { + for (let i = 0; i < buffer.length; i++) { + buffer[i] = Math.floor(Math.random() * 256); + } + return buffer; + } + } +}); + +// Mock matchMedia Object.defineProperty(window, 'matchMedia', { writable: true, value: jest.fn().mockImplementation(query => ({ matches: false, media: query, onchange: null, - addListener: jest.fn(), // Deprecated - removeListener: jest.fn(), // Deprecated + addListener: jest.fn(), // deprecated + removeListener: jest.fn(), // deprecated addEventListener: jest.fn(), removeEventListener: jest.fn(), dispatchEvent: jest.fn(),