use runner.LookChromeNames in TestMain
It supports alternative names for Chrome such as chromium, as well as extra names to look for like headless-shell. Also swap the os.Getenv logic, so that we only do the exec.LookPath work if the env var is unset.
This commit is contained in:
		
							parent
							
								
									5dc1e0f3af
								
							
						
					
					
						commit
						5ca52f3e1b
					
				@ -4,7 +4,6 @@ import (
 | 
				
			|||||||
	"context"
 | 
						"context"
 | 
				
			||||||
	"log"
 | 
						"log"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"os/exec"
 | 
					 | 
				
			||||||
	"path"
 | 
						"path"
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
@ -78,16 +77,9 @@ func TestMain(m *testing.M) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// its worth noting that newer versions of chrome (64+) run much faster
 | 
						// its worth noting that newer versions of chrome (64+) run much faster
 | 
				
			||||||
	// than older ones -- same for headless_shell ...
 | 
						// than older ones -- same for headless_shell ...
 | 
				
			||||||
	execPath := runner.DefaultChromePath
 | 
						execPath := os.Getenv("CHROMEDP_TEST_RUNNER")
 | 
				
			||||||
	if testRunner := os.Getenv("CHROMEDP_TEST_RUNNER"); testRunner != "" {
 | 
						if execPath == "" {
 | 
				
			||||||
		execPath = testRunner
 | 
							execPath = runner.LookChromeNames("headless_shell")
 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		// use headless_shell, if on path
 | 
					 | 
				
			||||||
		var hsPath string
 | 
					 | 
				
			||||||
		hsPath, err = exec.LookPath("headless_shell")
 | 
					 | 
				
			||||||
		if err == nil {
 | 
					 | 
				
			||||||
			execPath = hsPath
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	cliOpts = append(cliOpts, runner.ExecPath(execPath))
 | 
						cliOpts = append(cliOpts, runner.ExecPath(execPath))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user