Skip to content

Commit 6915725

Browse files
formatting
1 parent 4f4dd00 commit 6915725

File tree

3 files changed

+51
-46
lines changed

3 files changed

+51
-46
lines changed
Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,76 @@
1+
import fs from 'node:fs'
2+
import path from 'node:path'
3+
import { fileURLToPath } from 'node:url'
14
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
25
import { loadTempestConfiguration } from './config'
36
import { mockTempestConfiguration } from './test-utils'
4-
import fs from 'node:fs'
5-
import path from 'node:path'
67
import * as utils from './utils'
78

8-
test('the configuration can be loaded', async () => {
9-
mockTempestConfiguration()
9+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
1010

11-
const config = await loadTempestConfiguration()
11+
describe('loading configuration via command or environment variable', () => {
12+
afterEach(() => {
13+
vi.restoreAllMocks()
14+
delete process.env.TEMPEST_PLUGIN_CONFIGURATION_OVERRIDE
15+
})
1216

13-
expect(config).toHaveProperty('build_directory')
14-
expect(config).toHaveProperty('bridge_file_name')
15-
expect(config).toHaveProperty('manifest')
16-
expect(config).toHaveProperty('entrypoints')
17-
})
17+
test('the configuration can be loaded', async () => {
18+
mockTempestConfiguration()
1819

19-
test('the configuration can be overriden', async () => {
20-
process.env.TEMPEST_PLUGIN_CONFIGURATION_OVERRIDE = JSON.stringify({
21-
build_directory: 'build',
22-
bridge_file_name: 'vite-tempest',
23-
manifest: 'manifest.json',
24-
entrypoints: [],
20+
const config = await loadTempestConfiguration()
21+
expect(config.build_directory).toBe('build')
2522
})
2623

27-
const config = await loadTempestConfiguration()
24+
test('the configuration can be overriden with an environment variable', async () => {
25+
const execSpy = vi.spyOn(utils, 'exec')
26+
process.env.TEMPEST_PLUGIN_CONFIGURATION_OVERRIDE = JSON.stringify({
27+
build_directory: 'build/from-env',
28+
bridge_file_name: 'vite-tempest',
29+
manifest: 'manifest.json',
30+
entrypoints: [],
31+
})
2832

29-
expect(config).toHaveProperty('build_directory')
30-
expect(config).toHaveProperty('bridge_file_name')
31-
expect(config).toHaveProperty('manifest')
32-
expect(config).toHaveProperty('entrypoints')
33+
const config = await loadTempestConfiguration()
34+
35+
expect(config.build_directory).toBe('build/from-env')
36+
expect(execSpy).not.toHaveBeenCalled()
37+
})
3338
})
3439

3540
describe('loading configuration from a file', () => {
36-
const tempConfigPath = path.join(__dirname, 'tempest-vite.test.json');
41+
const tempConfigPath = path.join(__dirname, 'tempest-vite.test.json')
3742
const mockConfig = {
3843
build_directory: 'build/from-file',
3944
bridge_file_name: 'test-bridge',
4045
manifest: 'test-manifest.json',
4146
entrypoints: ['resources/js/test.js'],
42-
};
47+
}
4348

4449
beforeEach(() => {
45-
fs.writeFileSync(tempConfigPath, JSON.stringify(mockConfig));
46-
});
50+
fs.writeFileSync(tempConfigPath, JSON.stringify(mockConfig))
51+
})
4752

4853
afterEach(() => {
49-
fs.rmSync(tempConfigPath);
50-
vi.restoreAllMocks();
51-
});
54+
fs.rmSync(tempConfigPath)
55+
vi.restoreAllMocks()
56+
})
5257

5358
test('it loads configuration from the specified file path', async () => {
5459
const config = await loadTempestConfiguration({
5560
config_file_path: tempConfigPath,
56-
});
61+
})
5762

58-
expect(config.build_directory).toBe('build/from-file');
59-
expect(config.entrypoints).toEqual(['resources/js/test.js']);
60-
});
63+
expect(config.build_directory).toBe('build/from-file')
64+
expect(config.entrypoints).toEqual(['resources/js/test.js'])
65+
})
6166

6267
test('it does not execute the php command when a file path is provided', async () => {
63-
const execSpy = vi.spyOn(utils, 'exec');
68+
const execSpy = vi.spyOn(utils, 'exec')
6469

6570
await loadTempestConfiguration({
6671
config_file_path: tempConfigPath,
67-
});
72+
})
6873

69-
expect(execSpy).not.toHaveBeenCalled();
70-
});
71-
});
74+
expect(execSpy).not.toHaveBeenCalled()
75+
})
76+
})

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1+
import { readFileSync } from 'node:fs'
2+
import { resolve } from 'node:path'
13
import type { TempestViteConfiguration } from './types'
24
import { exec, php } from './utils'
3-
import { readFileSync } from 'node:fs';
4-
import { resolve } from 'node:path';
55

66
const TEMPEST_BIN = 'tempest'
77
const VITE_CONFIG_COMMAND = 'vite:config'
88

99
export async function loadTempestConfiguration(
10-
options: { config_file_path?: string } = {}
10+
options: { config_file_path?: string } = {},
1111
): Promise<TempestViteConfiguration> {
1212
if (options.config_file_path) {
1313
try {
14-
const filePath = resolve(process.cwd(), options.config_file_path);
15-
const fileContent = readFileSync(filePath, 'utf-8');
16-
return JSON.parse(fileContent);
14+
const filePath = resolve(process.cwd(), options.config_file_path)
15+
const fileContent = readFileSync(filePath, 'utf-8')
16+
return JSON.parse(fileContent)
1717
} catch (e) {
18-
console.error(`[vite-plugin-tempest] Error: Failed to read or parse the file at [${options.config_file_path}].`);
19-
throw e;
18+
console.error(`[vite-plugin-tempest] Error: Failed to read or parse the file at [${options.config_file_path}].`)
19+
throw e
2020
}
2121
}
2222

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const TEMPEST_ORIGIN_PLACEHOLDER = 'http://__tempest_placeholder__.test'
1616
let exitHandlersBound = false
1717

1818
export interface TempestPluginOptions {
19-
config_file_path?: string;
19+
config_file_path?: string
2020
}
2121

2222
export default function tempest(options: TempestPluginOptions = {}): Plugin {

0 commit comments

Comments
 (0)