@@ -27,24 +27,34 @@ describe('isCanary', () => {
2727 vi . unstubAllEnvs ( )
2828 } )
2929
30- it ( 'returns true when VERCEL_ENV is "canary"' , async ( ) => {
31- vi . stubEnv ( 'VERCEL_ENV' , 'canary' )
30+ it ( 'returns true when VERCEL_ENV is "production" and branch is "main"' , async ( ) => {
31+ vi . stubEnv ( 'VERCEL_ENV' , 'production' )
32+ vi . stubEnv ( 'VERCEL_GIT_COMMIT_REF' , 'main' )
3233 const { isCanary } = await import ( '../../../config/env' )
3334
3435 expect ( isCanary ) . toBe ( true )
3536 } )
3637
37- it ( 'returns true when VERCEL_ENV is "production " and branch is "main"' , async ( ) => {
38- vi . stubEnv ( 'VERCEL_ENV' , 'production ' )
38+ it ( 'returns true when VERCEL_ENV is "preview " and branch is "main" (non-PR) ' , async ( ) => {
39+ vi . stubEnv ( 'VERCEL_ENV' , 'preview ' )
3940 vi . stubEnv ( 'VERCEL_GIT_COMMIT_REF' , 'main' )
4041 const { isCanary } = await import ( '../../../config/env' )
4142
4243 expect ( isCanary ) . toBe ( true )
4344 } )
4445
46+ it ( 'returns false when VERCEL_ENV is "preview", branch is "main", but is a PR' , async ( ) => {
47+ vi . stubEnv ( 'VERCEL_ENV' , 'preview' )
48+ vi . stubEnv ( 'VERCEL_GIT_COMMIT_REF' , 'main' )
49+ vi . stubEnv ( 'VERCEL_GIT_PULL_REQUEST_ID' , '123' )
50+ const { isCanary } = await import ( '../../../config/env' )
51+
52+ expect ( isCanary ) . toBe ( false )
53+ } )
54+
4555 it . each ( [
4656 [ 'production (non-main branch)' , 'production' , 'v1.0.0' ] ,
47- [ 'preview' , 'preview' , undefined ] ,
57+ [ 'preview (non-main branch) ' , 'preview' , 'feat/foo' ] ,
4858 [ 'development' , 'development' , undefined ] ,
4959 [ 'unset' , undefined , undefined ] ,
5060 ] ) ( 'returns false when VERCEL_ENV is %s' , async ( _label , value , branch ) => {
@@ -78,19 +88,19 @@ describe('getEnv', () => {
7888 expect ( result . env ) . toBe ( 'dev' )
7989 } )
8090
81- it ( 'returns "canary" when VERCEL_ENV is "canary" ' , async ( ) => {
82- vi . stubEnv ( 'VERCEL_ENV' , 'canary ' )
91+ it ( 'returns "canary" for Vercel preview deploys from main branch (non-PR) ' , async ( ) => {
92+ vi . stubEnv ( 'VERCEL_ENV' , 'preview ' )
8393 vi . stubEnv ( 'VERCEL_GIT_COMMIT_REF' , 'main' )
8494 const { getEnv } = await import ( '../../../config/env' )
8595 const result = await getEnv ( false )
8696
8797 expect ( result . env ) . toBe ( 'canary' )
8898 } )
8999
90- it ( 'returns "preview" for Vercel preview deploys' , async ( ) => {
100+ it ( 'returns "preview" for Vercel preview PR deploys' , async ( ) => {
91101 vi . stubEnv ( 'VERCEL_ENV' , 'preview' )
92102 vi . stubEnv ( 'VERCEL_GIT_PULL_REQUEST_ID' , '123' )
93- vi . stubEnv ( 'VERCEL_GIT_COMMIT_REF' , 'main ' )
103+ vi . stubEnv ( 'VERCEL_GIT_COMMIT_REF' , 'feat/foo ' )
94104 const { getEnv } = await import ( '../../../config/env' )
95105 const result = await getEnv ( false )
96106
@@ -125,18 +135,9 @@ describe('getEnv', () => {
125135 expect ( result . env ) . toBe ( 'release' )
126136 } )
127137
128- it ( 'prioritises "canary" over "preview" when VERCEL_ENV is "canary" and PR is open' , async ( ) => {
129- vi . stubEnv ( 'VERCEL_ENV' , 'canary' )
130- vi . stubEnv ( 'VERCEL_GIT_PULL_REQUEST_ID' , '789' )
131- vi . stubEnv ( 'VERCEL_GIT_COMMIT_REF' , 'main' )
132- const { getEnv } = await import ( '../../../config/env' )
133- const result = await getEnv ( false )
134-
135- expect ( result . env ) . toBe ( 'canary' )
136- } )
137-
138138 it ( 'prioritises "dev" over "canary" in development mode' , async ( ) => {
139- vi . stubEnv ( 'VERCEL_ENV' , 'canary' )
139+ vi . stubEnv ( 'VERCEL_ENV' , 'preview' )
140+ vi . stubEnv ( 'VERCEL_GIT_COMMIT_REF' , 'main' )
140141 const { getEnv } = await import ( '../../../config/env' )
141142 const result = await getEnv ( true )
142143
@@ -169,7 +170,6 @@ describe('getPreviewUrl', () => {
169170 it . each ( [
170171 [ 'Netlify production' , { CONTEXT : 'production' , URL : 'https://prod.example.com' } ] ,
171172 [ 'Vercel production' , { VERCEL_ENV : 'production' , NUXT_ENV_VERCEL_URL : 'prod.example.com' } ] ,
172- [ 'Vercel canary' , { VERCEL_ENV : 'canary' , NUXT_ENV_VERCEL_URL : 'main.example.com' } ] ,
173173 ] ) ( '%s environment returns `undefined`' , async ( _name , envVars ) => {
174174 for ( const [ key , value ] of Object . entries ( envVars ) ) {
175175 vi . stubEnv ( key , value )
@@ -308,3 +308,20 @@ describe('getProductionUrl', () => {
308308 expect ( getProductionUrl ( ) ) . toBe ( expectedUrl )
309309 } )
310310} )
311+
312+ describe ( 'getVersion' , ( ) => {
313+ it ( 'returns package.json version when no git tags are reachable' , async ( ) => {
314+ const { getVersion, version } = await import ( '../../../config/env' )
315+ const result = await getVersion ( )
316+
317+ // In test environments without reachable tags, falls back to package.json
318+ expect ( result ) . toBe ( version )
319+ } )
320+
321+ it ( 'strips the leading "v" prefix from the tag' , async ( ) => {
322+ const { getVersion } = await import ( '../../../config/env' )
323+ const result = await getVersion ( )
324+
325+ expect ( result ) . not . toMatch ( / ^ v / )
326+ } )
327+ } )
0 commit comments