hugo

Fork of github.com/gohugoio/hugo with reverse pagination support

git clone git://git.shimmy1996.com/hugo.git

package_builder_test.go (2407B)

    1 // Copyright 2020 The Hugo Authors. All rights reserved.
    2 //
    3 // Licensed under the Apache License, Version 2.0 (the "License");
    4 // you may not use this file except in compliance with the License.
    5 // You may obtain a copy of the License at
    6 // http://www.apache.org/licenses/LICENSE-2.0
    7 //
    8 // Unless required by applicable law or agreed to in writing, software
    9 // distributed under the License is distributed on an "AS IS" BASIS,
   10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   11 // See the License for the specific language governing permissions and
   12 // limitations under the License.
   13 
   14 package npm
   15 
   16 import (
   17 	"strings"
   18 	"testing"
   19 
   20 	qt "github.com/frankban/quicktest"
   21 )
   22 
   23 const templ = `{
   24         "name": "foo",
   25         "version": "0.1.1",
   26         "scripts": {},
   27          "dependencies": {
   28                 "react-dom": "1.1.1",
   29                 "tailwindcss": "1.2.0",
   30                 "@babel/cli": "7.8.4",
   31                 "@babel/core": "7.9.0",
   32                 "@babel/preset-env": "7.9.5"
   33         },
   34         "devDependencies": {
   35                 "postcss-cli": "7.1.0",
   36                 "tailwindcss": "1.2.0",
   37                 "@babel/cli": "7.8.4",
   38                 "@babel/core": "7.9.0",
   39                 "@babel/preset-env": "7.9.5"
   40         }
   41 }`
   42 
   43 func TestPackageBuilder(t *testing.T) {
   44 	c := qt.New(t)
   45 
   46 	b := newPackageBuilder("", strings.NewReader(templ))
   47 	c.Assert(b.Err(), qt.IsNil)
   48 
   49 	b.Add("mymod", strings.NewReader(`{
   50 "dependencies": {
   51 	 "react-dom": "9.1.1",
   52 	 "add1": "1.1.1"
   53 },
   54 "devDependencies": {
   55 	 "tailwindcss": "error",
   56 	 "add2": "2.1.1"
   57 }	
   58 }`))
   59 
   60 	b.Add("mymod", strings.NewReader(`{
   61 "dependencies": {
   62 	 "react-dom": "error",
   63 	 "add1": "error",
   64 	 "add3": "3.1.1"
   65 },
   66 "devDependencies": {
   67 	 "tailwindcss": "error",
   68 	 "add2": "error",
   69 	 "add4": "4.1.1"
   70 	 
   71 }	
   72 }`))
   73 
   74 	c.Assert(b.Err(), qt.IsNil)
   75 
   76 	c.Assert(b.dependencies, qt.DeepEquals, map[string]any{
   77 		"@babel/cli":        "7.8.4",
   78 		"add1":              "1.1.1",
   79 		"add3":              "3.1.1",
   80 		"@babel/core":       "7.9.0",
   81 		"@babel/preset-env": "7.9.5",
   82 		"react-dom":         "1.1.1",
   83 		"tailwindcss":       "1.2.0",
   84 	})
   85 
   86 	c.Assert(b.devDependencies, qt.DeepEquals, map[string]any{
   87 		"tailwindcss":       "1.2.0",
   88 		"@babel/cli":        "7.8.4",
   89 		"@babel/core":       "7.9.0",
   90 		"add2":              "2.1.1",
   91 		"add4":              "4.1.1",
   92 		"@babel/preset-env": "7.9.5",
   93 		"postcss-cli":       "7.1.0",
   94 	})
   95 }