diff options
author | Bjørn Erik Pedersen <[email protected]> | 2022-02-09 14:15:20 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2022-02-09 15:41:32 +0100 |
commit | 215a715ddd698731fd81aed9cfaf7e37826e2467 (patch) | |
tree | e81d2bc0732a35cf89b1771a0b2ca2272ea0b690 /resources | |
parent | d128d260b5a4f395eefec6da841c14c665021c22 (diff) | |
download | hugo-215a715ddd698731fd81aed9cfaf7e37826e2467.tar.gz hugo-215a715ddd698731fd81aed9cfaf7e37826e2467.zip |
babel: Port integration tests to their own package
Diffstat (limited to 'resources')
-rw-r--r-- | resources/resource_transformers/babel/integration_test.go | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/resources/resource_transformers/babel/integration_test.go b/resources/resource_transformers/babel/integration_test.go new file mode 100644 index 000000000..3fe3c17b1 --- /dev/null +++ b/resources/resource_transformers/babel/integration_test.go @@ -0,0 +1,97 @@ +// Copyright 2021 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 babel_test + +import ( + "testing" + + qt "github.com/frankban/quicktest" + jww "github.com/spf13/jwalterweatherman" + + "github.com/gohugoio/hugo/htesting" + "github.com/gohugoio/hugo/hugolib" +) + +func TestTransformBabel(t *testing.T) { + if !htesting.IsCI() { + t.Skip("Skip long running test when running locally") + } + + c := qt.New(t) + + files := ` +-- assets/js/main.js -- +/* A Car */ +class Car { + constructor(brand) { + this.carname = brand; + } +} +-- assets/js/main2.js -- +/* A Car2 */ +class Car2 { + constructor(brand) { + this.carname = brand; + } +} +-- babel.config.js -- +console.error("Hugo Environment:", process.env.HUGO_ENVIRONMENT ); + +module.exports = { + presets: ["@babel/preset-env"], +}; +-- config.toml -- +disablekinds = ['taxonomy', 'term', 'page'] +[security] + [security.exec] + allow = ['^npx$', '^babel$'] +-- layouts/index.html -- +{{ $options := dict "noComments" true }} +{{ $transpiled := resources.Get "js/main.js" | babel -}} +Transpiled: {{ $transpiled.Content | safeJS }} + +{{ $transpiled := resources.Get "js/main2.js" | babel (dict "sourceMap" "inline") -}} +Transpiled2: {{ $transpiled.Content | safeJS }} + +{{ $transpiled := resources.Get "js/main2.js" | babel (dict "sourceMap" "external") -}} +Transpiled3: {{ $transpiled.Permalink }} +-- package.json -- +{ + "scripts": {}, + + "devDependencies": { + "@babel/cli": "7.8.4", + "@babel/core": "7.9.0", + "@babel/preset-env": "7.9.5" + } +} + + ` + + b := hugolib.NewIntegrationTestBuilder( + hugolib.IntegrationTestConfig{ + T: c, + TxtarString: files, + NeedsOsFS: true, + NeedsNpmInstall: true, + LogLevel: jww.LevelInfo, + }).Build() + + b.AssertLogContains("babel: Hugo Environment: production") + b.AssertFileContent("public/index.html", `var Car2 =`) + b.AssertFileContent("public/js/main2.js", `var Car2 =`) + b.AssertFileContent("public/js/main2.js.map", `{"version":3,`) + b.AssertFileContent("public/index.html", ` +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozL`) +} |