- 
          
 - 
                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.
          
          
      
        
          +530
        
        
          β31
        
        
          
        
      
    
  
  
     Draft
                    Changes from 2 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
          Some comments aren't visible on the classic Files Changed page.
        
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
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| const test = require("node:test"); | ||
| const assert = require("node:assert"); | ||
| 
     | 
||
                
      
                  bhelm marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| // Mock monitor configurations for testing | ||
| const monitors = { | ||
| noKeyword: { | ||
| type: "real-browser", | ||
| url: "https://example.com" | ||
| }, | ||
| withKeyword: { | ||
| type: "real-browser", | ||
| url: "https://example.com", | ||
| keyword: "Hello", | ||
| invertKeyword: false | ||
| }, | ||
| withInvertKeyword: { | ||
| type: "real-browser", | ||
| url: "https://example.com", | ||
| keyword: "NotFound", | ||
| invertKeyword: true | ||
| }, | ||
| keywordNotFound: { | ||
| type: "real-browser", | ||
| url: "https://example.com", | ||
| keyword: "NotFound", | ||
| invertKeyword: false | ||
| } | ||
| }; | ||
| 
     | 
||
| test("Test keyword checking logic", async (t) => { | ||
| 
     | 
||
| await t.test("should pass when no keyword is configured", async () => { | ||
| // This simulates backward compatibility - monitors without keywords should work | ||
| const monitor = monitors.noKeyword; | ||
| assert.strictEqual(monitor.keyword, undefined); | ||
| // No keyword means no checking, should always pass the keyword part | ||
| }); | ||
| 
     | 
||
| await t.test("should pass when keyword is found and not inverted", async () => { | ||
| const monitor = monitors.withKeyword; | ||
| const pageText = "Hello World! This is a test page with sample content."; | ||
| 
     | 
||
| // Simulate the keyword checking logic | ||
| const keywordFound = pageText.includes(monitor.keyword); | ||
| const invertKeyword = monitor.invertKeyword === true || monitor.invertKeyword === 1; | ||
| const shouldPass = keywordFound === !invertKeyword; | ||
| 
     | 
||
| assert.strictEqual(keywordFound, true, "Keyword 'Hello' should be found in page text"); | ||
| assert.strictEqual(invertKeyword, false, "Invert keyword should be false"); | ||
| assert.strictEqual(shouldPass, true, "Check should pass when keyword found and not inverted"); | ||
| }); | ||
| 
     | 
||
| await t.test("should pass when keyword is not found and inverted", async () => { | ||
| const monitor = monitors.withInvertKeyword; | ||
| const pageText = "Hello World! This is a test page with sample content."; | ||
| 
     | 
||
| // Simulate the keyword checking logic | ||
| const keywordFound = pageText.includes(monitor.keyword); | ||
| const invertKeyword = monitor.invertKeyword === true || monitor.invertKeyword === 1; | ||
| const shouldPass = keywordFound === !invertKeyword; | ||
| 
     | 
||
| assert.strictEqual(keywordFound, false, "Keyword 'NotFound' should not be found in page text"); | ||
| assert.strictEqual(invertKeyword, true, "Invert keyword should be true"); | ||
| assert.strictEqual(shouldPass, true, "Check should pass when keyword not found and inverted"); | ||
| }); | ||
| 
     | 
||
| await t.test("should fail when keyword is not found and not inverted", async () => { | ||
| const monitor = monitors.keywordNotFound; | ||
| const pageText = "Hello World! This is a test page with sample content."; | ||
| 
     | 
||
| // Simulate the keyword checking logic | ||
| const keywordFound = pageText.includes(monitor.keyword); | ||
| const invertKeyword = monitor.invertKeyword === true || monitor.invertKeyword === 1; | ||
| const shouldPass = keywordFound === !invertKeyword; | ||
| 
     | 
||
| assert.strictEqual(keywordFound, false, "Keyword 'NotFound' should not be found in page text"); | ||
| assert.strictEqual(invertKeyword, false, "Invert keyword should be false"); | ||
| assert.strictEqual(shouldPass, false, "Check should fail when keyword not found and not inverted"); | ||
| }); | ||
| 
     | 
||
| await t.test("should handle empty keyword properly", async () => { | ||
| const monitor = { | ||
| type: "real-browser", | ||
| url: "https://example.com", | ||
| keyword: "", // Empty keyword | ||
| invertKeyword: false | ||
| }; | ||
| 
     | 
||
| // Empty or whitespace-only keywords should be ignored (treated as no keyword) | ||
| const shouldCheckKeyword = !!(monitor.keyword && monitor.keyword.trim()); | ||
| assert.strictEqual(shouldCheckKeyword, false, "Empty keyword should be ignored"); | ||
| }); | ||
| 
     | 
||
| await t.test("should handle whitespace-only keyword properly", async () => { | ||
| const monitor = { | ||
| type: "real-browser", | ||
| url: "https://example.com", | ||
| keyword: " ", // Whitespace-only keyword | ||
| invertKeyword: false | ||
| }; | ||
| 
     | 
||
| // Empty or whitespace-only keywords should be ignored (treated as no keyword) | ||
| const shouldCheckKeyword = !!(monitor.keyword && monitor.keyword.trim()); | ||
| assert.strictEqual(shouldCheckKeyword, false, "Whitespace-only keyword should be ignored"); | ||
| }); | ||
| 
     | 
||
| await t.test("should handle text preprocessing correctly", async () => { | ||
| const originalText = "Hello World!\n\n This is a test page."; | ||
| const processedText = originalText.replace(/\s+/g, " ").trim(); | ||
| const expectedText = "Hello World! This is a test page."; | ||
| 
     | 
||
| assert.strictEqual(processedText, expectedText, "Text should be properly preprocessed"); | ||
| }); | ||
| }); | ||
  
    
      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
    
  
  
    
              
      
      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.