From ae4716fcf1dc27f11acbd23829b5432cf6a1feb3 Mon Sep 17 00:00:00 2001 From: mpl Date: Fri, 6 Jun 2014 23:29:08 +0200 Subject: [PATCH] ui tests: check both locally and globally for node modules Change-Id: I1378e07c055b85402296ca0bfc5c4ba14ae8c2bf --- pkg/misc/closure/jstest/jstest.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/pkg/misc/closure/jstest/jstest.go b/pkg/misc/closure/jstest/jstest.go index 83e106925..3716a313c 100644 --- a/pkg/misc/closure/jstest/jstest.go +++ b/pkg/misc/closure/jstest/jstest.go @@ -39,13 +39,25 @@ func checkSystemRequirements() error { } } - c := exec.Command("npm", "list", "--depth=0") - b, _ := c.Output() - s := string(b) - modules := []string{"mocha", "assert"} - for _, m := range modules { - if !strings.Contains(s, fmt.Sprintf(" %s@", m)) { - return fmt.Errorf("Required npm module %v not present", m) + checkModules := func(globally bool) error { + args := []string{"list", "--depth=0"} + if globally { + args = append([]string{"-g"}, args...) + } + c := exec.Command("npm", args...) + b, _ := c.Output() + s := string(b) + modules := []string{"mocha", "assert"} + for _, m := range modules { + if !strings.Contains(s, fmt.Sprintf(" %s@", m)) { + return fmt.Errorf("Required npm module %v not present", m) + } + } + return nil + } + if err := checkModules(true); err != nil { + if err := checkModules(false); err != nil { + return err } } return nil