|
1 | | -import { expect, test } from 'vitest' |
| 1 | +import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest' |
2 | 2 | import { loadTempestConfiguration } from './config' |
3 | 3 | import { mockTempestConfiguration } from './test-utils' |
| 4 | +import fs from 'node:fs' |
| 5 | +import path from 'node:path' |
| 6 | +import * as utils from './utils' |
4 | 7 |
|
5 | 8 | test('the configuration can be loaded', async () => { |
6 | 9 | mockTempestConfiguration() |
@@ -28,3 +31,41 @@ test('the configuration can be overriden', async () => { |
28 | 31 | expect(config).toHaveProperty('manifest') |
29 | 32 | expect(config).toHaveProperty('entrypoints') |
30 | 33 | }) |
| 34 | + |
| 35 | +describe('loading configuration from a file', () => { |
| 36 | + const tempConfigPath = path.join(__dirname, 'tempest-vite.test.json'); |
| 37 | + const mockConfig = { |
| 38 | + build_directory: 'build/from-file', |
| 39 | + bridge_file_name: 'test-bridge', |
| 40 | + manifest: 'test-manifest.json', |
| 41 | + entrypoints: ['resources/js/test.js'], |
| 42 | + }; |
| 43 | + |
| 44 | + beforeEach(() => { |
| 45 | + fs.writeFileSync(tempConfigPath, JSON.stringify(mockConfig)); |
| 46 | + }); |
| 47 | + |
| 48 | + afterEach(() => { |
| 49 | + fs.rmSync(tempConfigPath); |
| 50 | + vi.restoreAllMocks(); |
| 51 | + }); |
| 52 | + |
| 53 | + test('it loads configuration from the specified file path', async () => { |
| 54 | + const config = await loadTempestConfiguration({ |
| 55 | + config_file_path: tempConfigPath, |
| 56 | + }); |
| 57 | + |
| 58 | + expect(config.build_directory).toBe('build/from-file'); |
| 59 | + expect(config.entrypoints).toEqual(['resources/js/test.js']); |
| 60 | + }); |
| 61 | + |
| 62 | + test('it does not execute the php command when a file path is provided', async () => { |
| 63 | + const execSpy = vi.spyOn(utils, 'exec'); |
| 64 | + |
| 65 | + await loadTempestConfiguration({ |
| 66 | + config_file_path: tempConfigPath, |
| 67 | + }); |
| 68 | + |
| 69 | + expect(execSpy).not.toHaveBeenCalled(); |
| 70 | + }); |
| 71 | +}); |
0 commit comments