Debian Codegraph @

resources/resource_transformers/cssjs/tailwindcss_integration_test.go

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 // Copyright 2024 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 cssjs_test
15
16 import (
17 "testing"
18
19 qt "github.com/frankban/quicktest"
20 "github.com/gohugoio/hugo/htesting"
21 "github.com/gohugoio/hugo/hugolib"
22 )
23
24 func TestTailwindV4Basic(t *testing.T) {
25 if !htesting.IsCI() {
26 t.Skip("Skip long running test when running locally")
27 }
28
29 files := `
30 -- hugo.toml --
31 security.exec.allow = ['^go$', '^git$', '^node$', '^tailwindcss$']
32 -- package.json --
33 {
34 "license": "MIT",
35 "repository": {
36 "type": "git",
37 "url": "https://github.com/bep/hugo-starter-tailwind-basic.git"
38 },
39 "devDependencies": {
40 "@tailwindcss/cli": "^4.0.1",
41 "tailwindcss": "^4.0.1"
42 },
43 "name": "hugo-starter-tailwind-basic",
44 "version": "0.1.0"
45 }
46 -- assets/css/styles.css --
47 @import "tailwindcss";
48
49 @theme {
50 --font-family-display: "Satoshi", "sans-serif";
51
52 --breakpoint-3xl: 1920px;
53
54 --color-neon-pink: oklch(71.7% 0.25 360);
55 --color-neon-lime: oklch(91.5% 0.258 129);
56 --color-neon-cyan: oklch(91.3% 0.139 195.8);
57 }
58 -- layouts/home.html --
59 {{ $css := resources.Get "css/styles.css" | css.TailwindCSS }}
60 CSS: {{ $css.Content | safeCSS }}|
61 `
62
63 b := hugolib.Test(t, files, hugolib.TestOptOsFs(), hugolib.TestOptWithNpmInstall(), hugolib.TestOptInfo())
64
65 b.AssertFileContent("public/index.html", "/*! tailwindcss v4.")
66 }
67
68 // See issue 15103.
69 func TestTailwindCSSImportContext(t *testing.T) {
70 t.Parallel()
71 htesting.SkipSlowTestUnlessCI(t)
72
73 files := `
74 -- hugo.toml --
75 disableKinds = ['page','rss','section','sitemap','taxonomy','term']
76 security.exec.allow = ['^go$', '^git$', '^node$', '^tailwindcss$']
77 -- assets/css/main.css --
78 @import "tailwindcss";
79
80 @import "foo.css";
81 @import "bar.css";
82 -- assets/css/foo.css --
83 .foo {color: orange;}
84 -- layouts/home.html --
85 {{ $foo := resources.FromString "foo.css" ".foo {color: blue;}" }}
86 {{ $bar := resources.FromString "bar.css" ".bar {color: green;}" }}
87 {{ $opts := dict "importContext" (slice $foo $bar) }}
88 {{ $css := resources.Get "css/main.css" | css.TailwindCSS $opts }}
89 CSS: {{ $css.Content | safeCSS }}|
90 -- package.json --
91 {
92 "devDependencies": {
93 "@tailwindcss/cli": "^4.1.7",
94 "tailwindcss": "^4.1.7"
95 }
96 }
97 `
98
99 b := hugolib.Test(t, files, hugolib.TestOptOsFs(), hugolib.TestOptWithNpmInstall(), hugolib.TestOptInfo())
100
101 // foo.css resolves in the import context before the assets filesystem.
102 b.AssertFileContent("public/index.html",
103 ".foo {\n color: blue;\n }",
104 ".bar {\n color: green;\n }",
105 )
106 }
107
108 func TestTailwindCSSNoInlineImportsIssue13719(t *testing.T) {
109 t.Parallel()
110 htesting.SkipSlowTestUnlessCI(t)
111
112 files := `
113 -- hugo.toml --
114 disableKinds = ['page','rss','section','sitemap','taxonomy','term']
115 theme = 'my-theme'
116
117 security.exec.allow = ['^go$', '^git$', '^node$', '^tailwindcss$']
118
119 [[module.mounts]]
120 source = 'assets'
121 target = 'assets'
122
123 [[module.mounts]]
124 source = 'other'
125 target = 'assets/css'
126 -- assets/css/main.css --
127 @import "tailwindcss";
128
129 @import "colors/red.css";
130 @import "colors/blue.css";
131 @import "colors/purple.css";
132 -- assets/css/colors/red.css --
133 @import "green.css";
134
135 .red {color: red;}
136 -- assets/css/colors/green.css --
137 .green {color: green;}
138 -- themes/my-theme/assets/css/colors/blue.css --
139 .blue {color: blue;}
140 -- other/colors/purple.css --
141 .purple {color: purple;}
142 -- layouts/home.html --
143 {{ with (templates.Defer (dict "key" "global")) }}
144 {{ with resources.Get "css/main.css" }}
145 {{ $opts := dict "disableInlineImports" true }}
146 {{ with . | css.TailwindCSS $opts }}
147 <link rel="stylesheet" href="{{ .RelPermalink }}">
148 {{ end }}
149 {{ end }}
150 {{ end }}
151 -- package.json --
152 {
153 "devDependencies": {
154 "@tailwindcss/cli": "^4.1.7",
155 "tailwindcss": "^4.1.7"
156 }
157 }
158 `
159
160 b, err := hugolib.TestE(t, files, hugolib.TestOptOsFs(), hugolib.TestOptWithNpmInstall(), hugolib.TestOptInfo())
161
162 b.Assert(err, qt.IsNotNil)
163 b.Assert(err.Error(), qt.Contains, "Can't resolve 'colors/red.css'")
164 b.Assert(err.Error(), qt.Contains, "You may want to set the 'disableInlineImports' option to false")
165 }