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
22 changes: 16 additions & 6 deletions code/core/src/common/utils/validate-config.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { afterEach, describe, expect, it, vi } from 'vitest';

import { resolveModulePath } from 'exsolve';

import { validateFrameworkName } from './validate-config';

// mock exsolve to spy
vi.mock('exsolve', { spy: true });

describe('validateFrameworkName', () => {
afterEach(() => {
vi.resetAllMocks();
Expand All @@ -20,15 +25,20 @@ describe('validateFrameworkName', () => {
});

it('should not throw if framework is unknown (community) but can be resolved', () => {
// mock require.resolve to return a value
vi.spyOn(require, 'resolve').mockReturnValue('some-community-framework');
expect(() => validateFrameworkName('some-community-framework')).toThrow();
vi.mocked(resolveModulePath).mockImplementation(() => {});

expect(() => validateFrameworkName('some-community-framework')).not.toThrow();
});

it('should not throw if scoped framework is unknown (community) but can be resolved', () => {
vi.mocked(resolveModulePath).mockImplementation(() => {});

expect(() => validateFrameworkName('@some-community/framework')).not.toThrow();
});

it('should throw if framework is unknown and cannot be resolved', () => {
// mock require.resolve to fail
vi.spyOn(require, 'resolve').mockImplementation(() => {
throw new Error('Cannot resolve');
vi.mocked(resolveModulePath).mockImplementation(() => {
throw new Error('cannot resolve');
});

expect(() => validateFrameworkName('foo')).toThrow();
Expand Down
4 changes: 1 addition & 3 deletions code/core/src/common/utils/validate-config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { join } from 'node:path';

import {
CouldNotEvaluateFrameworkError,
InvalidFrameworkNameError,
Expand Down Expand Up @@ -35,7 +33,7 @@ export function validateFrameworkName(

// If it's not a known framework, we need to validate that it's a valid package at least
try {
resolveModulePath(join(frameworkName, 'preset'), {
resolveModulePath(`${frameworkName}/preset`, {
extensions: ['.mjs', '.js', '.cjs'],
conditions: ['node', 'import', 'require'],
});
Expand Down