120 lines
5.3 KiB
TypeScript
120 lines
5.3 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import * as path from 'path';
|
|
import { resolveFixturesPath } from '@/apps/companion/main/di-container';
|
|
|
|
describe('DIContainer path resolution', () => {
|
|
describe('resolveFixturesPath', () => {
|
|
describe('built mode (with /dist/ in path)', () => {
|
|
it('should resolve fixtures path to monorepo root when dirname is apps/companion/dist/main', () => {
|
|
// Given: The dirname as it would be in built Electron runtime (apps/companion/dist/main)
|
|
const mockDirname = '/Users/test/Projects/gridpilot/apps/companion/dist/main';
|
|
const relativePath = './resources/iracing-hosted-sessions';
|
|
|
|
// When: Resolving the fixtures path
|
|
const resolved = resolveFixturesPath(relativePath, mockDirname);
|
|
|
|
// Then: Should resolve to monorepo root (4 levels up from apps/companion/dist/main)
|
|
// Level 0: apps/companion/dist/main (__dirname)
|
|
// Level 1: apps/companion/dist (../)
|
|
// Level 2: apps/companion (../../)
|
|
// Level 3: apps (../../../)
|
|
// Level 4: gridpilot (monorepo root) (../../../../) ← CORRECT
|
|
const expectedPath = '/Users/test/Projects/gridpilot/resources/iracing-hosted-sessions';
|
|
expect(resolved).toBe(expectedPath);
|
|
});
|
|
|
|
it('should navigate exactly 4 levels up in built mode', () => {
|
|
// Given: A path with /dist/ that demonstrates the 4-level navigation
|
|
const mockDirname = '/level4/level3/dist/level1';
|
|
const relativePath = './target';
|
|
|
|
// When: Resolving the fixtures path
|
|
const resolved = resolveFixturesPath(relativePath, mockDirname);
|
|
|
|
// Then: Should resolve to the path 4 levels up (root /)
|
|
expect(resolved).toBe('/target');
|
|
});
|
|
|
|
it('should work with different relative path formats in built mode', () => {
|
|
// Given: Various relative path formats
|
|
const mockDirname = '/Users/test/Projects/gridpilot/apps/companion/dist/main';
|
|
|
|
// When/Then: Different relative formats should all work
|
|
expect(resolveFixturesPath('resources/fixtures', mockDirname))
|
|
.toBe('/Users/test/Projects/gridpilot/resources/fixtures');
|
|
|
|
expect(resolveFixturesPath('./resources/fixtures', mockDirname))
|
|
.toBe('/Users/test/Projects/gridpilot/resources/fixtures');
|
|
});
|
|
});
|
|
|
|
describe('dev mode (without /dist/ in path)', () => {
|
|
it('should resolve fixtures path to monorepo root when dirname is apps/companion/main', () => {
|
|
// Given: The dirname as it would be in dev mode (apps/companion/main)
|
|
const mockDirname = '/Users/test/Projects/gridpilot/apps/companion/main';
|
|
const relativePath = './resources/iracing-hosted-sessions';
|
|
|
|
// When: Resolving the fixtures path
|
|
const resolved = resolveFixturesPath(relativePath, mockDirname);
|
|
|
|
// Then: Should resolve to monorepo root (3 levels up from apps/companion/main)
|
|
// Level 0: apps/companion/main (__dirname)
|
|
// Level 1: apps/companion (../)
|
|
// Level 2: apps (../../)
|
|
// Level 3: gridpilot (monorepo root) (../../../) ← CORRECT
|
|
const expectedPath = '/Users/test/Projects/gridpilot/resources/iracing-hosted-sessions';
|
|
expect(resolved).toBe(expectedPath);
|
|
});
|
|
|
|
it('should navigate exactly 3 levels up in dev mode', () => {
|
|
// Given: A path without /dist/ that demonstrates the 3-level navigation
|
|
const mockDirname = '/level3/level2/level1';
|
|
const relativePath = './target';
|
|
|
|
// When: Resolving the fixtures path
|
|
const resolved = resolveFixturesPath(relativePath, mockDirname);
|
|
|
|
// Then: Should resolve to the path 3 levels up (root /)
|
|
expect(resolved).toBe('/target');
|
|
});
|
|
|
|
it('should work with different relative path formats in dev mode', () => {
|
|
// Given: Various relative path formats
|
|
const mockDirname = '/Users/test/Projects/gridpilot/apps/companion/main';
|
|
|
|
// When/Then: Different relative formats should all work
|
|
expect(resolveFixturesPath('resources/fixtures', mockDirname))
|
|
.toBe('/Users/test/Projects/gridpilot/resources/fixtures');
|
|
|
|
expect(resolveFixturesPath('./resources/fixtures', mockDirname))
|
|
.toBe('/Users/test/Projects/gridpilot/resources/fixtures');
|
|
});
|
|
});
|
|
|
|
describe('absolute paths', () => {
|
|
it('should return absolute paths unchanged in built mode', () => {
|
|
// Given: An absolute path
|
|
const absolutePath = '/some/absolute/path/to/fixtures';
|
|
const mockDirname = '/Users/test/Projects/gridpilot/apps/companion/dist/main';
|
|
|
|
// When: Resolving an absolute path
|
|
const resolved = resolveFixturesPath(absolutePath, mockDirname);
|
|
|
|
// Then: Should return the absolute path unchanged
|
|
expect(resolved).toBe(absolutePath);
|
|
});
|
|
|
|
it('should return absolute paths unchanged in dev mode', () => {
|
|
// Given: An absolute path
|
|
const absolutePath = '/some/absolute/path/to/fixtures';
|
|
const mockDirname = '/Users/test/Projects/gridpilot/apps/companion/main';
|
|
|
|
// When: Resolving an absolute path
|
|
const resolved = resolveFixturesPath(absolutePath, mockDirname);
|
|
|
|
// Then: Should return the absolute path unchanged
|
|
expect(resolved).toBe(absolutePath);
|
|
});
|
|
});
|
|
});
|
|
}); |