Skip to content

Commit e84624b

Browse files
committed
Fix npm 8 test: also remove cpu-features require from server.js
The previous fix removed cpu-features from package.json dependencies but server.js still had 'require("cpu-features")' at line 4, causing the app to crash at startup with 'Cannot find module' and never serve requests. Remove the require line from the copied server.js fixture.
1 parent 1ae2288 commit e84624b

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/nodejs/integration/npm_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"os"
66
"path/filepath"
7+
"strings"
78
"testing"
89

910
"github.com/cloudfoundry/switchblade"
@@ -83,6 +84,13 @@ func testNPM(platform switchblade.Platform, fixtures string) func(*testing.T, sp
8384
content, err := json.Marshal(pkg)
8485
Expect(err).NotTo(HaveOccurred())
8586
Expect(os.WriteFile(filepath.Join(source, "package.json"), content, 0600)).To(Succeed())
87+
88+
// Also remove the require('cpu-features') from server.js so the
89+
// app doesn't crash at startup trying to load the missing module.
90+
serverJS, err := os.ReadFile(filepath.Join(source, "server.js"))
91+
Expect(err).NotTo(HaveOccurred())
92+
serverJS = []byte(strings.Replace(string(serverJS), "const features = require('cpu-features')();\n", "", 1))
93+
Expect(os.WriteFile(filepath.Join(source, "server.js"), serverJS, 0600)).To(Succeed())
8694
})
8795

8896
it.After(func() {

0 commit comments

Comments
 (0)