Files
zeekayandHanzo Dev aa87442fdd Record upstream authorship centrally in NOTICE instead of in every file header
Source files keep their SPDX-License-Identifier and Hanzo copyright line; the
Gitea, Gogs and LFS Test Server copyrights they used to repeat now live once in
NOTICE, alongside LICENSE. The header lint accepts any copyright line above the
SPDX line, so it no longer demands an upstream one.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-10 17:50:35 -07:00

77 lines
2.7 KiB
Go

// Copyright 2026 Hanzo AI, Inc. All rights reserved.
// SPDX-License-Identifier: MIT
package public
import (
"html/template"
"testing"
"time"
"github.com/hanzoai/git/modules/setting"
"github.com/hanzoai/git/modules/test"
"github.com/stretchr/testify/assert"
)
func TestViteManifest(t *testing.T) {
defer test.MockVariableValue(&setting.IsProd, true)()
const testManifest = `{
"web_src/js/index.ts": {
"file": "js/index.C6Z2MRVQ.js",
"name": "index",
"src": "web_src/js/index.ts",
"isEntry": true,
"imports": ["_shared.AaAaAaAa.js"],
"css": ["css/index.B3zrQPqD.css", "css/index-extra.CcCcCcCc.css"]
},
"_shared.AaAaAaAa.js": {
"file": "js/shared.AaAaAaAa.js",
"name": "shared",
"css": ["css/shared.BbBbBbBb.css"]
},
"web_src/css/themes/theme-hanzo-dark.css": {
"file": "css/theme-hanzo-dark.CyAaQnn5.css",
"name": "theme-hanzo-dark",
"src": "web_src/css/themes/theme-hanzo-dark.css",
"isEntry": true
}
}`
t.Run("EmptyManifest", func(t *testing.T) {
storeManifestFromBytes([]byte(``), 0, time.Now())
// not in manifest -> custom theme fallback
assert.Equal(t, "/assets/css/theme-hanzo-dark.css", AssetURI("web_src/css/themes/theme-hanzo-dark.css"))
assert.Empty(t, entryStyleURLs("web_src/js/index.ts", "web_src/css/index.css"))
assert.Empty(t, AssetNameFromHashedPath("css/no-such-file.css"))
})
t.Run("ParseManifest", func(t *testing.T) {
storeManifestFromBytes([]byte(testManifest), 0, time.Now())
// assets are addressed by their source path (the manifest key)
assert.Equal(t, "/assets/js/index.C6Z2MRVQ.js", AssetURI("web_src/js/index.ts"))
assert.Equal(t, "/assets/css/theme-hanzo-dark.CyAaQnn5.css", AssetURI("web_src/css/themes/theme-hanzo-dark.css"))
// custom theme not in the manifest falls back to the static asset location
assert.Equal(t, "/assets/css/theme-custom.css", AssetURI("web_src/css/themes/theme-custom.css"))
// a JS entry's stylesheets: all of the entry's own CSS plus the CSS of statically-imported chunks
assert.Equal(t, []string{
"/assets/css/index.B3zrQPqD.css",
"/assets/css/index-extra.CcCcCcCc.css",
"/assets/css/shared.BbBbBbBb.css",
}, entryStyleURLs("web_src/js/index.ts", "web_src/css/index.css"))
assert.Equal(t, template.HTML(
`<link rel="stylesheet" href="/assets/css/index.B3zrQPqD.css">`+
`<link rel="stylesheet" href="/assets/css/index-extra.CcCcCcCc.css">`+
`<link rel="stylesheet" href="/assets/css/shared.BbBbBbBb.css">`,
), AssetCSSLinks("web_src/js/index.ts", "web_src/css/index.css"))
// hashed output file -> entry name
assert.Equal(t, "theme-hanzo-dark", AssetNameFromHashedPath("css/theme-hanzo-dark.CyAaQnn5.css"))
assert.Empty(t, AssetNameFromHashedPath("css/no-such-file.css"))
})
}