Skip to content

Commit

Permalink
add ut
Browse files Browse the repository at this point in the history
  • Loading branch information
beyondkmp committed Sep 20, 2024
1 parent d4a2ae7 commit 0f42aa0
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ test:
cd pkg/node-modules/tar-demo/ && npm install
cd pkg/node-modules/yarn-demo/ && yarn
cd pkg/node-modules/parse-demo/ && yarn
cd pkg/node-modules/es5-demo/ && pnpm install
go test -v ./pkg/...

assets:
Expand Down
15 changes: 15 additions & 0 deletions pkg/node-modules/es5-demo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "pnpm-demo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"es5-ext": "0.10.53"
}
}
105 changes: 105 additions & 0 deletions pkg/node-modules/es5-demo/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions pkg/node-modules/nodeModuleCollector_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package node_modules

import (
"fmt"
"path"
"path/filepath"
"testing"
Expand Down Expand Up @@ -157,3 +158,33 @@ func TestReadDependencyTreeForParse(t *testing.T) {
g.Expect(collector.HoiestedDependencyMap["asn1.js"].dir).To(Equal(filepath.Join(Dirname(), "parse-demo/node_modules/asn1.js")))
g.Expect(collector.HoiestedDependencyMap["asn1.js"].Version).To(Equal("4.10.1"))
}

func TestReadDependencyTreeForEs5(t *testing.T) {
g := NewGomegaWithT(t)

collector := &Collector{
unresolvedDependencies: make(map[string]bool),
excludedDependencies: make(map[string]bool),
NodeModuleDirToDependencyMap: make(map[string]*map[string]*Dependency),
}

dir := path.Join(Dirname(), "es5-demo")

dependency, err := readPackageJson(dir)
dependency.dir = dir

g.Expect(err).NotTo(HaveOccurred())

err = collector.readDependencyTree(dependency)
g.Expect(err).NotTo(HaveOccurred())
collector.processHoistDependencyMap()

fmt.Println(collector.HoiestedDependencyMap)

g.Expect(collector.HoiestedDependencyMap["d"].dir).To(Equal(filepath.Join(Dirname(), "es5-demo/node_modules/.pnpm/[email protected]/node_modules/d")))
g.Expect(collector.HoiestedDependencyMap["d"].Version).To(Equal("1.0.2"))

g.Expect(collector.HoiestedDependencyMap["d"].conflictDependency["es5-ext"].dir).To(Equal(filepath.Join(Dirname(), "es5-demo/node_modules/.pnpm/[email protected]/node_modules/es5-ext")))
g.Expect(collector.HoiestedDependencyMap["d"].conflictDependency["es5-ext"].Version).To(Equal("0.10.64"))

}

0 comments on commit 0f42aa0

Please sign in to comment.