Skip to content

Commit 4f4dd00

Browse files
add config test
1 parent a092a8e commit 4f4dd00

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

packages/vite-plugin-tempest/src/config.test.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import { expect, test } from 'vitest'
1+
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
22
import { loadTempestConfiguration } from './config'
33
import { mockTempestConfiguration } from './test-utils'
4+
import fs from 'node:fs'
5+
import path from 'node:path'
6+
import * as utils from './utils'
47

58
test('the configuration can be loaded', async () => {
69
mockTempestConfiguration()
@@ -28,3 +31,41 @@ test('the configuration can be overriden', async () => {
2831
expect(config).toHaveProperty('manifest')
2932
expect(config).toHaveProperty('entrypoints')
3033
})
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

Comments
 (0)