1+ import fs from 'node:fs'
2+ import path from 'node:path'
3+ import { fileURLToPath } from 'node:url'
14import { expect , test } from 'vitest'
25import { loadTempestConfiguration } from './config'
36import { mockTempestConfiguration } from './test-utils'
47
58test ( 'the configuration can be loaded' , async ( ) => {
6- mockTempestConfiguration ( )
9+ const spy = mockTempestConfiguration ( )
710
8- const config = await loadTempestConfiguration ( )
11+ try {
12+ const config = await loadTempestConfiguration ( )
913
10- expect ( config ) . toHaveProperty ( 'build_directory' )
11- expect ( config ) . toHaveProperty ( 'bridge_file_name' )
12- expect ( config ) . toHaveProperty ( 'manifest' )
13- expect ( config ) . toHaveProperty ( 'entrypoints' )
14+ expect ( config ) . toHaveProperty ( 'build_directory' )
15+ expect ( config ) . toHaveProperty ( 'bridge_file_name' )
16+ expect ( config ) . toHaveProperty ( 'manifest' )
17+ expect ( config ) . toHaveProperty ( 'entrypoints' )
18+ } finally {
19+ spy . mockRestore ( )
20+ }
1421} )
1522
1623test ( 'the configuration can be overriden' , async ( ) => {
@@ -28,3 +35,29 @@ test('the configuration can be overriden', async () => {
2835 expect ( config ) . toHaveProperty ( 'manifest' )
2936 expect ( config ) . toHaveProperty ( 'entrypoints' )
3037} )
38+
39+ test ( 'the configuration can be loaded from a file path environment variable' , async ( ) => {
40+ const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) )
41+ const tempConfigPath = path . join ( __dirname , 'tempest-vite.test.json' )
42+ const mockConfig = {
43+ build_directory : 'build/from-file' ,
44+ bridge_file_name : 'test-bridge' ,
45+ manifest : 'test-manifest.json' ,
46+ entrypoints : [ 'resources/js/test.js' ] ,
47+ }
48+
49+ try {
50+ fs . writeFileSync ( tempConfigPath , JSON . stringify ( mockConfig ) )
51+ process . env . TEMPEST_PLUGIN_CONFIGURATION_PATH = tempConfigPath
52+
53+ const config = await loadTempestConfiguration ( )
54+
55+ expect ( config . build_directory ) . toBe ( 'build/from-file' )
56+ expect ( config . bridge_file_name ) . toBe ( 'test-bridge' )
57+ expect ( config . manifest ) . toBe ( 'test-manifest.json' )
58+ expect ( config . entrypoints ) . toEqual ( [ 'resources/js/test.js' ] )
59+ } finally {
60+ fs . rmSync ( tempConfigPath , { force : true } )
61+ delete process . env . TEMPEST_PLUGIN_CONFIGURATION_PATH
62+ }
63+ } )
0 commit comments