assetSource.spec.ts — vite Source File
Architecture documentation for assetSource.spec.ts, a typescript file in the vite codebase. 4 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR ec8b45d7_5d26_7be1_b946_be1735a3b6f0["assetSource.spec.ts"] a2a61cd6_2d46_2c12_335a_793c63cb8a19["assetSource.ts"] ec8b45d7_5d26_7be1_b946_be1735a3b6f0 --> a2a61cd6_2d46_2c12_335a_793c63cb8a19 583413b4_122f_c77c_6469_fed71988cf60["getNodeAssetAttributes"] ec8b45d7_5d26_7be1_b946_be1735a3b6f0 --> 583413b4_122f_c77c_6469_fed71988cf60 a340ba46_b2b7_3048_3bb3_6907a74c8464["vitest"] ec8b45d7_5d26_7be1_b946_be1735a3b6f0 --> a340ba46_b2b7_3048_3bb3_6907a74c8464 f254ed68_2782_1441_34e4_258ed6a8f434["parse5"] ec8b45d7_5d26_7be1_b946_be1735a3b6f0 --> f254ed68_2782_1441_34e4_258ed6a8f434 style ec8b45d7_5d26_7be1_b946_be1735a3b6f0 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import { describe, expect, test } from 'vitest'
import { type DefaultTreeAdapterMap, parseFragment } from 'parse5'
import { getNodeAssetAttributes } from '../assetSource'
describe('getNodeAssetAttributes', () => {
const getNode = (html: string) => {
const ast = parseFragment(html, { sourceCodeLocationInfo: true })
return ast.childNodes[0] as DefaultTreeAdapterMap['element']
}
test('handles img src', () => {
const node = getNode('<img src="foo.jpg">')
const attrs = getNodeAssetAttributes(node)
expect(attrs).toHaveLength(1)
expect(attrs[0]).toHaveProperty('type', 'src')
expect(attrs[0]).toHaveProperty('key', 'src')
expect(attrs[0]).toHaveProperty('value', 'foo.jpg')
expect(attrs[0].attributes).toEqual({ src: 'foo.jpg' })
expect(attrs[0].location).toHaveProperty('startOffset', 5)
expect(attrs[0].location).toHaveProperty('endOffset', 18)
})
test('handles source srcset', () => {
const node = getNode('<source srcset="foo.jpg 1x, bar.jpg 2x">')
const attrs = getNodeAssetAttributes(node)
expect(attrs).toHaveLength(1)
expect(attrs[0]).toHaveProperty('type', 'srcset')
expect(attrs[0]).toHaveProperty('key', 'srcset')
expect(attrs[0]).toHaveProperty('value', 'foo.jpg 1x, bar.jpg 2x')
expect(attrs[0].attributes).toEqual({ srcset: 'foo.jpg 1x, bar.jpg 2x' })
})
test('handles video src and poster', () => {
const node = getNode('<video src="video.mp4" poster="poster.jpg">')
const attrs = getNodeAssetAttributes(node)
expect(attrs).toHaveLength(2)
expect(attrs[0]).toHaveProperty('type', 'src')
expect(attrs[0]).toHaveProperty('key', 'src')
expect(attrs[0]).toHaveProperty('value', 'video.mp4')
expect(attrs[0].attributes).toEqual({
src: 'video.mp4',
poster: 'poster.jpg',
})
expect(attrs[1]).toHaveProperty('type', 'src')
expect(attrs[1]).toHaveProperty('key', 'poster')
expect(attrs[1]).toHaveProperty('value', 'poster.jpg')
})
test('handles link with allowed rel', () => {
const node = getNode('<link rel="stylesheet" href="style.css">')
const attrs = getNodeAssetAttributes(node)
expect(attrs).toHaveLength(1)
expect(attrs[0]).toHaveProperty('type', 'src')
expect(attrs[0]).toHaveProperty('key', 'href')
expect(attrs[0]).toHaveProperty('value', 'style.css')
expect(attrs[0].attributes).toEqual({
rel: 'stylesheet',
href: 'style.css',
})
})
test('handles meta with allowed name', () => {
const node = getNode('<meta name="twitter:image" content="image.jpg">')
const attrs = getNodeAssetAttributes(node)
expect(attrs).toHaveLength(1)
expect(attrs[0]).toHaveProperty('type', 'src')
expect(attrs[0]).toHaveProperty('key', 'content')
expect(attrs[0]).toHaveProperty('value', 'image.jpg')
})
test('handles meta with allowed property', () => {
const node = getNode('<meta property="og:image" content="image.jpg">')
const attrs = getNodeAssetAttributes(node)
expect(attrs).toHaveLength(1)
expect(attrs[0]).toHaveProperty('type', 'src')
expect(attrs[0]).toHaveProperty('key', 'content')
expect(attrs[0]).toHaveProperty('value', 'image.jpg')
})
test('does not handle meta with unknown name', () => {
const node = getNode('<meta name="unknown" content="image.jpg">')
const attrs = getNodeAssetAttributes(node)
expect(attrs).toHaveLength(0)
})
test('does not handle meta with unknown property', () => {
const node = getNode('<meta property="unknown" content="image.jpg">')
const attrs = getNodeAssetAttributes(node)
expect(attrs).toHaveLength(0)
})
test('does not handle meta with no known properties', () => {
const node = getNode('<meta foo="bar" content="image.jpg">')
const attrs = getNodeAssetAttributes(node)
expect(attrs).toHaveLength(0)
})
})
Domain
Dependencies
- assetSource.ts
- getNodeAssetAttributes
- parse5
- vitest
Source
Frequently Asked Questions
What does assetSource.spec.ts do?
assetSource.spec.ts is a source file in the vite codebase, written in typescript. It belongs to the ViteCore domain.
What does assetSource.spec.ts depend on?
assetSource.spec.ts imports 4 module(s): assetSource.ts, getNodeAssetAttributes, parse5, vitest.
Where is assetSource.spec.ts in the architecture?
assetSource.spec.ts is located at packages/vite/src/node/__tests__/assetSource.spec.ts (domain: ViteCore, directory: packages/vite/src/node/__tests__).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free