Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions calm-plugins/vscode/src/core/services/navigation-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NavigationService } from './navigation-service'
import * as fs from 'fs'
import * as path from 'path'
import * as vscode from 'vscode'
import { buildDocumentLoader } from '@finos/calm-shared/dist/document-loader/document-loader'
import { buildDocumentLoader } from '@finos/calm-shared'

// Mock vscode
vi.mock('vscode', () => ({
Expand Down Expand Up @@ -39,7 +39,7 @@ vi.mock('fs', () => ({
}))

// Mock document loader
vi.mock('@finos/calm-shared/dist/document-loader/document-loader', () => ({
vi.mock('@finos/calm-shared', () => ({
buildDocumentLoader: vi.fn(),
}))

Expand All @@ -65,7 +65,7 @@ describe('NavigationService', () => {
}

vi.mocked(buildDocumentLoader).mockReturnValue(mockDocLoader)

// Reset vscode mocks
// @ts-ignore
vscode.workspace.workspaceFolders = undefined
Expand Down Expand Up @@ -96,8 +96,8 @@ describe('NavigationService', () => {
// @ts-ignore
vscode.workspace.workspaceFolders = undefined

const result = await navigationService.navigate('node1', {
'detailed-architecture': 'detail.json'
const result = await navigationService.navigate('node1', {
'detailed-architecture': 'detail.json'
})

expect(result).toBe(false)
Expand All @@ -114,7 +114,7 @@ describe('NavigationService', () => {
const targetPath = '/workspace/detail.json'
mockDocLoader.resolvePath.mockReturnValue(targetPath)
vi.mocked(fs.existsSync).mockReturnValue(true)

// Setup open document
const mockDoc = { uri: { fsPath: targetPath } }
vi.mocked(vscode.workspace.openTextDocument).mockResolvedValue(mockDoc as any)
Expand Down Expand Up @@ -147,8 +147,8 @@ describe('NavigationService', () => {
mockDocLoader.resolvePath.mockReturnValue(targetPath)
vi.mocked(fs.existsSync).mockReturnValue(false)

const result = await navigationService.navigate('node1', {
'detailed-architecture': 'detail.json'
const result = await navigationService.navigate('node1', {
'detailed-architecture': 'detail.json'
})

expect(vscode.window.showWarningMessage).toHaveBeenCalledWith(expect.stringContaining('File not found'))
Expand All @@ -163,9 +163,9 @@ describe('NavigationService', () => {

const httpUrl = 'http://example.com/arch.json'
mockDocLoader.resolvePath.mockReturnValue(undefined) // or whatever resolvePath returns for unresolvable
const result = await navigationService.navigate('node1', {
'detailed-architecture': httpUrl

const result = await navigationService.navigate('node1', {
'detailed-architecture': httpUrl
})

expect(vscode.window.showWarningMessage).toHaveBeenCalledWith(
Expand Down Expand Up @@ -200,7 +200,7 @@ describe('NavigationService', () => {
expect(buildDocumentLoader).toHaveBeenCalledWith(expect.objectContaining({
urlToLocalMap: expect.any(Map)
}))

// Verify map content passed to loader
const callArgs = vi.mocked(buildDocumentLoader).mock.calls[0][0]
expect(callArgs.urlToLocalMap?.get('http://example.com')).toContain('local/path')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
buildDocumentLoader,
DocumentLoader,
DocumentLoaderOptions
} from '@finos/calm-shared/dist/document-loader/document-loader'
} from '@finos/calm-shared'
import { Config } from '../ports/config'
import type { Logger } from '../ports/logger'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,14 @@ vi.mock('@finos/calm-shared', async () => {
loadTimeline: vi.fn(),
SchemaDirectory: vi.fn().mockImplementation(() => ({
loadSchemas: vi.fn()
})),
buildDocumentLoader: vi.fn(() => ({
loadMissingDocument: vi.fn(),
initialise: vi.fn()
}))
}
})

// Mock document loader
vi.mock('@finos/calm-shared/dist/document-loader/document-loader', () => ({
buildDocumentLoader: vi.fn(() => ({
loadMissingDocument: vi.fn(),
initialise: vi.fn()
}))
}))

// Mock CalmSchemaRegistry
vi.mock('../../core/services/calm-schema-registry', () => ({
CalmSchemaRegistry: vi.fn().mockImplementation(() => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import {
loadArchitectureAndPattern,
loadTimeline,
enrichWithDocumentPositions,
parseDocumentWithPositions
parseDocumentWithPositions,
buildDocumentLoader,
DocumentLoader
} from '@finos/calm-shared'
import { buildDocumentLoader, DocumentLoader } from '@finos/calm-shared/dist/document-loader/document-loader'
import type { Logger } from '../../core/ports/logger'
import type { Config } from '../../core/ports/config'
import { CalmSchemaRegistry } from '../../core/services/calm-schema-registry'
Expand Down
23 changes: 15 additions & 8 deletions cli/src/cli.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
CALM_META_SCHEMA_DIRECTORY,
Docifier,
DocifyMode,
TemplateProcessingMode,
TemplateProcessor
TemplateProcessor,
DocumentLoader
} from '@finos/calm-shared';
import { Command } from 'commander';
import { MockInstance } from 'vitest';
Expand All @@ -14,12 +14,12 @@ let validateModule: typeof import('./command-helpers/validate');
let serverModule: typeof import('./server/cli-server');
let templateModule: typeof import('./command-helpers/template');
let optionsModule: typeof import('./command-helpers/generate-options');
let fileSystemDocLoaderModule: typeof import('@finos/calm-shared/dist/document-loader/file-system-document-loader');
let setupCLI: typeof import('./cli').setupCLI;
let cliConfigModule: typeof import('./cli-config');

describe('CLI Commands', () => {
let program: Command;
let mockDocLoader: DocumentLoader;

beforeEach(async () => {
vi.resetModules();
Expand All @@ -30,7 +30,6 @@ describe('CLI Commands', () => {
serverModule = await import('./server/cli-server');
templateModule = await import('./command-helpers/template');
optionsModule = await import('./command-helpers/generate-options');
fileSystemDocLoaderModule = await import('@finos/calm-shared/dist/document-loader/file-system-document-loader');

vi.spyOn(calmShared, 'runGenerate').mockResolvedValue(undefined);
vi.spyOn(calmShared.TemplateProcessor.prototype, 'processTemplate').mockResolvedValue(undefined);
Expand All @@ -44,8 +43,12 @@ describe('CLI Commands', () => {

vi.spyOn(optionsModule, 'promptUserForOptions').mockResolvedValue([]);

vi.spyOn(fileSystemDocLoaderModule, 'FileSystemDocumentLoader').mockImplementation(vi.fn());
vi.spyOn(fileSystemDocLoaderModule.FileSystemDocumentLoader.prototype, 'loadMissingDocument').mockResolvedValue({});
mockDocLoader = {
initialise: vi.fn().mockResolvedValue(undefined),
loadMissingDocument: vi.fn().mockResolvedValue({}),
resolvePath: vi.fn().mockReturnValue(undefined)
};
vi.spyOn(calmShared, 'buildDocumentLoader').mockReturnValue(mockDocLoader);

const cliModule = await import('./cli');
setupCLI = cliModule.setupCLI;
Expand All @@ -64,10 +67,14 @@ describe('CLI Commands', () => {
'--schema-directory', 'schemas',
]);

expect(fileSystemDocLoaderModule.FileSystemDocumentLoader.prototype.loadMissingDocument).toHaveBeenCalledWith('pattern.json', 'pattern');
expect(mockDocLoader.loadMissingDocument).toHaveBeenCalledWith('pattern.json', 'pattern');
expect(optionsModule.promptUserForOptions).toHaveBeenCalled();

expect(fileSystemDocLoaderModule.FileSystemDocumentLoader).toHaveBeenCalledWith([CALM_META_SCHEMA_DIRECTORY, 'schemas'], true, process.cwd());
expect(calmShared.buildDocumentLoader).toHaveBeenCalledWith(expect.objectContaining({
schemaDirectoryPath: 'schemas',
debug: true,
basePath: process.cwd()
}));

expect(calmShared.runGenerate).toHaveBeenCalledWith(
{}, 'output.json', true, expect.any(calmShared.SchemaDirectory), []
Expand Down
4 changes: 1 addition & 3 deletions cli/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { CALM_META_SCHEMA_DIRECTORY, DocifyMode, initLogger, runGenerate, SchemaDirectory, TemplateProcessingMode } from '@finos/calm-shared';
import { CALM_META_SCHEMA_DIRECTORY, DocifyMode, initLogger, runGenerate, SchemaDirectory, TemplateProcessingMode, CalmChoice, buildDocumentLoader, DocumentLoader, DocumentLoaderOptions } from '@finos/calm-shared';
import { Option, Command } from 'commander';
import { version } from '../package.json';
import { promptUserForOptions } from './command-helpers/generate-options';
import { CalmChoice } from '@finos/calm-shared/dist/commands/generate/components/options';
import { buildDocumentLoader, DocumentLoader, DocumentLoaderOptions } from '@finos/calm-shared/dist/document-loader/document-loader';
import { loadCliConfig } from './cli-config';
import path from 'path';
import { select } from '@inquirer/prompts';
Expand Down
12 changes: 8 additions & 4 deletions cli/src/command-helpers/generate-options.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CalmChoice } from '@finos/calm-shared/dist/commands/generate/components/options';
import { CalmChoice } from '@finos/calm-shared';
import { promptUserForOptions } from './generate-options';

const mocks = vi.hoisted(() => {
Expand All @@ -9,9 +9,13 @@ const mocks = vi.hoisted(() => {
};
});

vi.mock('@finos/calm-shared/dist/commands/generate/components/options', () => ({
extractOptions: mocks.extractOptions
}));
vi.mock('@finos/calm-shared', async () => {
const actual = await vi.importActual<typeof import('@finos/calm-shared')>('@finos/calm-shared');
return {
...actual,
extractOptions: mocks.extractOptions
};
});

vi.mock('@inquirer/prompts', () => ({
select: mocks.select,
Expand Down
3 changes: 1 addition & 2 deletions cli/src/command-helpers/generate-options.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { CalmChoice, CalmOption, extractOptions } from '@finos/calm-shared/dist/commands/generate/components/options';
import { initLogger } from '@finos/calm-shared';
import { CalmChoice, CalmOption, extractOptions, initLogger } from '@finos/calm-shared';
import { select, checkbox } from '@inquirer/prompts';

type InquirerQuestion = {
Expand Down
8 changes: 2 additions & 6 deletions cli/src/command-helpers/validate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ vi.mock('@finos/calm-shared', async () => ({
getFormattedOutput: mocks.getFormattedOutput,
exitBasedOffOfValidationOutcome: mocks.exitBasedOffOfValidationOutcome,
initLogger: mocks.initLogger,
loadSchemas: mocks.loadSchemas
loadSchemas: mocks.loadSchemas,
buildDocumentLoader: mocks.buildDocumentLoader
}));

vi.mock('mkdirp', () => ({
Expand All @@ -59,11 +60,6 @@ vi.mock('../cli', async () => ({
})),
}));

vi.mock('@finos/calm-shared/dist/document-loader/document-loader', async () => ({
...(await vi.importActual('@finos/calm-shared/dist/document-loader/document-loader')),
buildDocumentLoader: mocks.buildDocumentLoader
}));

describe('runValidate', () => {
const fakeOutcome = { valid: true };

Expand Down
6 changes: 1 addition & 5 deletions cli/src/command-helpers/validate.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { getFormattedOutput, validate, exitBasedOffOfValidationOutcome, ValidationFormattingOptions, loadArchitectureAndPattern, loadTimeline, enrichWithDocumentPositions, ParsedDocumentContext } from '@finos/calm-shared';
import { initLogger } from '@finos/calm-shared';
import { getFormattedOutput, validate, exitBasedOffOfValidationOutcome, ValidationFormattingOptions, loadArchitectureAndPattern, loadTimeline, enrichWithDocumentPositions, ParsedDocumentContext, initLogger, ValidateOutputFormat, buildDocumentLoader, DocumentLoader, Logger } from '@finos/calm-shared';
import path from 'path';
import { mkdirp } from 'mkdirp';
import { readFileSync, writeFileSync } from 'fs';
import { Command } from 'commander';
import { ValidateOutputFormat } from '@finos/calm-shared/dist/commands/validate/validate';
import { buildSchemaDirectory, parseDocumentLoaderConfig } from '../cli';
import { buildDocumentLoader, DocumentLoader } from '@finos/calm-shared/dist/document-loader/document-loader';
import { Logger } from '@finos/calm-shared/dist/logger';
import { parseWithPointers } from '@stoplight/json';

export interface ValidateOptions {
Expand Down
4 changes: 3 additions & 1 deletion shared/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ export {
ValidationFormattingOptions,
ValidationDocumentContext,
} from './commands/validate/validate.js';
export { OutputFormat } from './commands/validate/validate.js';
export { OutputFormat, ValidateOutputFormat } from './commands/validate/validate.js';
export { runGenerate } from './commands/generate/generate.js';
export {
extractOptions,
selectChoices,
CalmChoice,
CalmOption,
} from './commands/generate/components/options.js';
export { ValidationOutput } from './commands/validate/validation.output.js';
export { CALM_META_SCHEMA_DIRECTORY } from './consts.js';
Expand Down
Loading