| 1 |
// Copyright 2026 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 hexec_test |
| 15 |
|
| 16 |
import ( |
| 17 |
"testing" |
| 18 |
|
| 19 |
"github.com/gohugoio/hugo/htesting" |
| 20 |
"github.com/gohugoio/hugo/hugolib" |
| 21 |
) |
| 22 |
|
| 23 |
func TestNPMGlobalInstalls(t *testing.T) { |
| 24 |
if !htesting.IsRealCI() { |
| 25 |
t.Skip("We only ever want to run this in CI.") |
| 26 |
} |
| 27 |
files := ` |
| 28 |
-- hugo.toml -- |
| 29 |
disableKinds = ["taxonomy", "term"] |
| 30 |
[security.exec] |
| 31 |
allow = ['^(babel|node|postcss|tailwindcss)$'] |
| 32 |
|
| 33 |
-- package.json -- |
| 34 |
{} |
| 35 |
-- hugo_stats.json -- |
| 36 |
-- assets/js/main.js -- |
| 37 |
console.log("Hello, world!"); |
| 38 |
-- assets/css/main1.css -- |
| 39 |
body { color: red } |
| 40 |
-- assets/css/main2.css -- |
| 41 |
@import "tailwindcss"; |
| 42 |
@plugin "@tailwindcss/typography"; |
| 43 |
@source "hugo_stats.json"; |
| 44 |
body { color: blue } |
| 45 |
-- layouts/home.html -- |
| 46 |
{{ with resources.Get "css/main1.css" }} |
| 47 |
{{ with . | css.PostCSS }} |
| 48 |
CSS1: {{ .RelPermalink }}|{{ gt (.Content | len) 10 }}| |
| 49 |
{{ end }} |
| 50 |
{{ end }} |
| 51 |
{{ with resources.Get "css/main2.css" }} |
| 52 |
{{ with . | css.TailwindCSS }} |
| 53 |
CSS2: {{ .RelPermalink }}|{{ gt (.Content | len) 10 }}| |
| 54 |
{{ end }} |
| 55 |
{{ end }} |
| 56 |
{{ with resources.Get "js/main.js" }} |
| 57 |
{{ with . | js.Babel }} |
| 58 |
JS: {{ .RelPermalink }}|{{ gt (.Content | len) 10 }}| |
| 59 |
{{ end }} |
| 60 |
{{ end }} |
| 61 |
` |
| 62 |
|
| 63 |
b := hugolib.Test(t, files, hugolib.TestOptOsFs(), hugolib.TestOptWithNpmInstallGlobal( |
| 64 |
"postcss", "postcss-cli", |
| 65 |
"@babel/core", "@babel/cli", |
| 66 |
"tailwindcss", "@tailwindcss/cli", "@tailwindcss/typography", |
| 67 |
)) |
| 68 |
|
| 69 |
b.AssertFileContent("public/index.html", |
| 70 |
"CSS1: /css/main1.css|true|", |
| 71 |
"CSS2: /css/main2.css|true|", |
| 72 |
"JS: /js/main.js|true|", |
| 73 |
) |
| 74 |
} |