// Copyright 2019 The Hugo Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package hugolib
import (
"io"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"testing"
"github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/htesting"
"github.com/spf13/viper"
qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/hugofs"
"github.com/gohugoio/hugo/common/loggers"
"github.com/gohugoio/hugo/resources/resource_transformers/tocss/scss"
)
func TestSCSSWithIncludePaths(t *testing.T) {
if !scss.Supports() {
t.Skip("Skip SCSS")
}
c := qt.New(t)
workDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-scss-include")
c.Assert(err, qt.IsNil)
defer clean()
v := viper.New()
v.Set("workingDir", workDir)
b := newTestSitesBuilder(t).WithLogger(loggers.NewErrorLogger())
// Need to use OS fs for this.
b.Fs = hugofs.NewDefault(v)
b.WithWorkingDir(workDir)
b.WithViper(v)
fooDir := filepath.Join(workDir, "node_modules", "foo")
scssDir := filepath.Join(workDir, "assets", "scss")
c.Assert(os.MkdirAll(fooDir, 0777), qt.IsNil)
c.Assert(os.MkdirAll(filepath.Join(workDir, "content", "sect"), 0777), qt.IsNil)
c.Assert(os.MkdirAll(filepath.Join(workDir, "data"), 0777), qt.IsNil)
c.Assert(os.MkdirAll(filepath.Join(workDir, "i18n"), 0777), qt.IsNil)
c.Assert(os.MkdirAll(filepath.Join(workDir, "layouts", "shortcodes"), 0777), qt.IsNil)
c.Assert(os.MkdirAll(filepath.Join(workDir, "layouts", "_default"), 0777), qt.IsNil)
c.Assert(os.MkdirAll(filepath.Join(scssDir), 0777), qt.IsNil)
b.WithSourceFile(filepath.Join(fooDir, "_moo.scss"), `
$moolor: #fff;
moo {
color: $moolor;
}
`)
b.WithSourceFile(filepath.Join(scssDir, "main.scss"), `
@import "moo";
`)
b.WithTemplatesAdded("index.html", `