[READ-ONLY] a fast, modern browser for the npm registry
at main 58 lines 1.9 kB view raw
1import type { BuildInfo } from '#shared/types' 2import { describe, expect, it } from 'vitest' 3import { mountSuspended } from '@nuxt/test-utils/runtime' 4import BuildEnvironment from '~/components/BuildEnvironment.vue' 5 6describe('BuildEnvironment', () => { 7 it('renders dev environment correctly', async () => { 8 const buildInfo: BuildInfo = { 9 env: 'dev', 10 version: '1.2.3', 11 time: 1234567890, 12 commit: 'abcdef', 13 shortCommit: 'abc', 14 branch: 'main', 15 privacyPolicyDate: new Date().toISOString(), 16 } 17 const component = await mountSuspended(BuildEnvironment, { 18 props: { 19 buildInfo, 20 }, 21 }) 22 23 // In dev mode, it shows env name, not version link 24 const envSpan = component.find('span.tracking-wider') 25 expect(envSpan.exists()).toBe(true) 26 expect(envSpan.text()).toBe(buildInfo.env) 27 const commitLink = component.find(`a[href$="/commit/${buildInfo.commit}"]`) 28 expect(commitLink.exists()).toBe(true) 29 const tagLink = component.find(`a[href$="/tag/v${buildInfo.version}"]`) 30 expect(tagLink.exists()).toBe(false) 31 }) 32 33 it('renders release environment correctly', async () => { 34 const buildInfo: BuildInfo = { 35 env: 'release', 36 version: '1.2.3', 37 time: 1234567890, 38 commit: 'abcdef', 39 shortCommit: 'abc', 40 branch: 'release', 41 privacyPolicyDate: new Date().toISOString(), 42 } 43 44 const component = await mountSuspended(BuildEnvironment, { 45 props: { 46 buildInfo, 47 }, 48 }) 49 50 // In release mode, it shows tag version link, not env name 51 const envSpan = component.find('span.tracking-wider') 52 expect(envSpan.exists()).toBe(false) 53 const commitLink = component.find(`a[href$="/commit/${buildInfo.commit}"]`) 54 expect(commitLink.exists()).toBe(false) 55 const tagLink = component.find(`a[href$="/tag/v${buildInfo.version}"]`) 56 expect(tagLink.exists()).toBe(true) 57 }) 58})