|
| 1 | +import type { BuildInfo } from '#shared/types' |
| 2 | +import { describe, expect, it } from 'vitest' |
| 3 | +import { mountSuspended } from '@nuxt/test-utils/runtime' |
| 4 | +import BuildEnvironment from '~/components/BuildEnvironment.vue' |
| 5 | + |
| 6 | +describe('BuildEnvironment', () => { |
| 7 | + it('renders dev environment correctly', async () => { |
| 8 | + const buildInfo = useAppConfig().buildInfo as BuildInfo |
| 9 | + const component = await mountSuspended(BuildEnvironment, { |
| 10 | + props: { |
| 11 | + buildInfo, |
| 12 | + }, |
| 13 | + }) |
| 14 | + const html = component.html() |
| 15 | + |
| 16 | + // In dev mode, it shows env name, not version link |
| 17 | + expect(html).toContain('<span class="tracking-wider">dev</span>') |
| 18 | + expect(html).toContain( |
| 19 | + '<a href="https://github.com/npmx-dev/npmx.dev/commit/704987bba88909f3782d792c224bde989569acb9"', |
| 20 | + ) |
| 21 | + expect(html).not.toContain('href="https://github.com/npmx-dev/npmx.dev/tag/v0.0.0"') |
| 22 | + }) |
| 23 | + |
| 24 | + it('renders release environment correctly', async () => { |
| 25 | + const buildInfo: BuildInfo = { |
| 26 | + env: 'release', |
| 27 | + version: '1.2.3', |
| 28 | + time: 1234567890, |
| 29 | + commit: 'abcdef', |
| 30 | + shortCommit: 'abc', |
| 31 | + branch: 'release', |
| 32 | + } |
| 33 | + |
| 34 | + const component = await mountSuspended(BuildEnvironment, { |
| 35 | + props: { |
| 36 | + buildInfo, |
| 37 | + }, |
| 38 | + }) |
| 39 | + const html = component.html() |
| 40 | + |
| 41 | + // In release mode, it shows tag version link, not env name |
| 42 | + expect(html).not.toContain('<span class="tracking-wider">dev</span>') |
| 43 | + expect(html).not.toContain( |
| 44 | + '<a href="https://github.com/npmx-dev/npmx.dev/commit/704987bba88909f3782d792c224bde989569acb9"', |
| 45 | + ) |
| 46 | + expect(html).toContain('href="https://github.com/npmx-dev/npmx.dev/tag/v1.2.3"') |
| 47 | + }) |
| 48 | +}) |
0 commit comments