- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 6.9k
 
added keyword matching functionality for real-browser-monitor #6097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Draft
      
      
            bhelm
  wants to merge
  16
  commits into
  louislam:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
bhelm:master
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Draft
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            16 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      e0d7baa
              
                added keyword matching functionality for real-browser-monitor
              
              
                bhelm 859debc
              
                removed obvious comments and empty lines
              
              
                bhelm e4e8600
              
                remove optional handling for keyword description
              
              
                bhelm 127c63b
              
                setup real browser backend testing framework to use a real browser
              
              
                bhelm 0997700
              
                fixed linting errors
              
              
                bhelm 58dc1d3
              
                Merge branch 'master' into master
              
              
                bhelm 94c1b11
              
                Merge branch 'master' into master
              
              
                bhelm b2169ef
              
                damped the tests a bit, made them more diverse
              
              
                bhelm e6570a3
              
                Merge branch 'master' of github.com:bhelm/uptime-kuma
              
              
                bhelm 61eb8ed
              
                also normalize keyword
              
              
                bhelm 2c0a1fc
              
                Merge branch 'master' of https://github.com/louislam/uptime-kuma
              
              
                bhelm 30dd28d
              
                fix lint
              
              
                bhelm 716615a
              
                added   to the html text extraction test
              
              
                bhelm 166d4db
              
                added playwright install to the auto tests for the new backend real bβ¦
              
              
                bhelm 6a5496d
              
                Merge branch 'master' of https://github.com/louislam/uptime-kuma
              
              
                bhelm 453878d
              
                playwright install only chromium
              
              
                bhelm File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| const path = require("path"); | ||
| const { UP, DOWN, PENDING } = require("../../src/util"); | ||
| 
     | 
||
| /** | ||
| * Real Browser Test Helper | ||
| * Common utilities for testing real browser monitor functionality | ||
| */ | ||
| class RealBrowserTestHelper { | ||
| /** | ||
| * Constructor for RealBrowserTestHelper | ||
| */ | ||
| constructor() { | ||
| this.RealBrowserMonitorType = null; | ||
| this.resetChrome = null; | ||
| this.originalModules = {}; | ||
| } | ||
| 
     | 
||
| /** | ||
| * Set up mocks for server dependencies | ||
| * @returns {void} | ||
| */ | ||
| setupMocks() { | ||
| const settingsPath = path.resolve(__dirname, "../../server/settings.js"); | ||
| const databasePath = path.resolve(__dirname, "../../server/database.js"); | ||
| const browserMonitorPath = path.resolve(__dirname, "../../server/monitor-types/real-browser-monitor-type.js"); | ||
| 
     | 
||
| // Store originals for cleanup | ||
| this.originalModules.settings = require.cache[settingsPath]; | ||
| this.originalModules.database = require.cache[databasePath]; | ||
| this.originalModules.browserMonitor = require.cache[browserMonitorPath]; | ||
| 
     | 
||
| delete require.cache[settingsPath]; | ||
| delete require.cache[databasePath]; | ||
| delete require.cache[browserMonitorPath]; | ||
| 
     | 
||
| require.cache[settingsPath] = { | ||
| exports: { | ||
| Settings: { get: async (key) => key === "chromeExecutable" ? "#playwright_chromium" : "default" } | ||
| } | ||
| }; | ||
| require.cache[databasePath] = { | ||
| exports: { screenshotDir: "/tmp/uptime-kuma-test-screenshots" } | ||
| }; | ||
| 
     | 
||
| ({ RealBrowserMonitorType: this.RealBrowserMonitorType, resetChrome: this.resetChrome } = require("../../server/monitor-types/real-browser-monitor-type")); | ||
| } | ||
| 
     | 
||
| /** | ||
| * Clean up mocks and restore original modules | ||
| * @returns {void} | ||
| */ | ||
| cleanupMocks() { | ||
| const settingsPath = path.resolve(__dirname, "../../server/settings.js"); | ||
| const databasePath = path.resolve(__dirname, "../../server/database.js"); | ||
| const browserMonitorPath = path.resolve(__dirname, "../../server/monitor-types/real-browser-monitor-type.js"); | ||
| 
     | 
||
| // Remove our mocks | ||
| delete require.cache[settingsPath]; | ||
| delete require.cache[databasePath]; | ||
| delete require.cache[browserMonitorPath]; | ||
| 
     | 
||
| // Restore originals if they existed | ||
| if (this.originalModules.settings) { | ||
| require.cache[settingsPath] = this.originalModules.settings; | ||
| } | ||
| if (this.originalModules.database) { | ||
| require.cache[databasePath] = this.originalModules.database; | ||
| } | ||
| if (this.originalModules.browserMonitor) { | ||
| require.cache[browserMonitorPath] = this.originalModules.browserMonitor; | ||
| } | ||
| } | ||
| 
     | 
||
| /** | ||
| * Run a monitor test and return the heartbeat result | ||
| * @param {object} monitor - The monitor configuration | ||
| * @returns {Promise<object>} The heartbeat object with test results | ||
| */ | ||
| async runMonitorTest(monitor) { | ||
| const monitorType = new this.RealBrowserMonitorType(); | ||
| const heartbeat = { | ||
| msg: "", | ||
| status: PENDING, | ||
| ping: null | ||
| }; | ||
| const server = { jwtSecret: "test-secret-key" }; | ||
| 
     | 
||
| try { | ||
| await monitorType.check(monitor, heartbeat, server); | ||
| return heartbeat; | ||
| } catch (error) { | ||
| heartbeat.status = DOWN; | ||
| heartbeat.msg = error.message; | ||
| throw error; | ||
| } | ||
| } | ||
| 
     | 
||
| /** | ||
| * Set up test cleanup hooks | ||
| * @param {object} testSuite - The test suite object | ||
| * @returns {void} | ||
| */ | ||
| setupTestCleanup(testSuite) { | ||
| testSuite.after(async () => { | ||
| if (this.resetChrome) { | ||
| await this.resetChrome(); | ||
| } | ||
| this.cleanupMocks(); | ||
| }); | ||
| } | ||
| 
     | 
||
| /** | ||
| * Initialize the test helper with environment and mocks | ||
| * @returns {Promise<void>} | ||
| */ | ||
| async initialize() { | ||
| process.env.TEST_BACKEND = "1"; | ||
| this.setupMocks(); | ||
| } | ||
| } | ||
| 
     | 
||
| module.exports = { | ||
| RealBrowserTestHelper, | ||
| UP, | ||
| DOWN, | ||
| PENDING | ||
| }; | 
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.