projecttestutil

package
v0.0.0-...-a4721f4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TestTypingsLocation = "/home/src/Library/Caches/typescript"
	TestLibLocation     = "/home/src/tslibs/TS/Lib"
)

Variables

This section is empty.

Functions

func TypesRegistryConfig

func TypesRegistryConfig() map[string]string

func TypesRegistryConfigText

func TypesRegistryConfigText() string

func WithRequestID

func WithRequestID(ctx context.Context) context.Context

Types

type ClientMock

type ClientMock struct {
	// RefreshDiagnosticsFunc mocks the RefreshDiagnostics method.
	RefreshDiagnosticsFunc func(ctx context.Context) error

	// UnwatchFilesFunc mocks the UnwatchFiles method.
	UnwatchFilesFunc func(ctx context.Context, handle project.WatcherHandle) error

	// WatchFilesFunc mocks the WatchFiles method.
	WatchFilesFunc func(ctx context.Context, watchers []*lsproto.FileSystemWatcher) (project.WatcherHandle, error)
	// contains filtered or unexported fields
}

ClientMock is a mock implementation of project.Client.

func TestSomethingThatUsesClient(t *testing.T) {

	// make and configure a mocked project.Client
	mockedClient := &ClientMock{
		RefreshDiagnosticsFunc: func(ctx context.Context) error {
			panic("mock out the RefreshDiagnostics method")
		},
		UnwatchFilesFunc: func(ctx context.Context, handle project.WatcherHandle) error {
			panic("mock out the UnwatchFiles method")
		},
		WatchFilesFunc: func(ctx context.Context, watchers []*lsproto.FileSystemWatcher) (project.WatcherHandle, error) {
			panic("mock out the WatchFiles method")
		},
	}

	// use mockedClient in code that requires project.Client
	// and then make assertions.

}

func (*ClientMock) RefreshDiagnostics

func (mock *ClientMock) RefreshDiagnostics(ctx context.Context) error

RefreshDiagnostics calls RefreshDiagnosticsFunc.

func (*ClientMock) RefreshDiagnosticsCalls

func (mock *ClientMock) RefreshDiagnosticsCalls() []struct {
	Ctx context.Context
}

RefreshDiagnosticsCalls gets all the calls that were made to RefreshDiagnostics. Check the length with:

len(mockedClient.RefreshDiagnosticsCalls())

func (*ClientMock) UnwatchFiles

func (mock *ClientMock) UnwatchFiles(ctx context.Context, handle project.WatcherHandle) error

UnwatchFiles calls UnwatchFilesFunc.

func (*ClientMock) UnwatchFilesCalls

func (mock *ClientMock) UnwatchFilesCalls() []struct {
	Ctx    context.Context
	Handle project.WatcherHandle
}

UnwatchFilesCalls gets all the calls that were made to UnwatchFiles. Check the length with:

len(mockedClient.UnwatchFilesCalls())

func (*ClientMock) WatchFiles

func (mock *ClientMock) WatchFiles(ctx context.Context, watchers []*lsproto.FileSystemWatcher) (project.WatcherHandle, error)

WatchFiles calls WatchFilesFunc.

func (*ClientMock) WatchFilesCalls

func (mock *ClientMock) WatchFilesCalls() []struct {
	Ctx      context.Context
	Watchers []*lsproto.FileSystemWatcher
}

WatchFilesCalls gets all the calls that were made to WatchFiles. Check the length with:

len(mockedClient.WatchFilesCalls())

type ProjectServiceHost

type ProjectServiceHost struct {
	ClientMock *ClientMock

	ServiceOptions *project.ServiceOptions
	// contains filtered or unexported fields
}

func Setup

func Setup(files map[string]any, testOptions *TestTypingsInstaller) (*project.Service, *ProjectServiceHost)

func (*ProjectServiceHost) Client

func (p *ProjectServiceHost) Client() project.Client

Client implements project.ProjectServiceHost.

func (*ProjectServiceHost) DefaultLibraryPath

func (p *ProjectServiceHost) DefaultLibraryPath() string

DefaultLibraryPath implements project.ProjectServiceHost.

func (*ProjectServiceHost) FS

func (p *ProjectServiceHost) FS() vfs.FS

FS implements project.ProjectServiceHost.

func (*ProjectServiceHost) GetCurrentDirectory

func (p *ProjectServiceHost) GetCurrentDirectory() string

GetCurrentDirectory implements project.ProjectServiceHost.

func (*ProjectServiceHost) Log

func (p *ProjectServiceHost) Log(msg ...any)

Log implements project.ProjectServiceHost.

func (*ProjectServiceHost) NewLine

func (p *ProjectServiceHost) NewLine() string

NewLine implements project.ProjectServiceHost.

func (*ProjectServiceHost) NpmInstall

func (p *ProjectServiceHost) NpmInstall(cwd string, npmInstallArgs []string) ([]byte, error)

func (*ProjectServiceHost) ReplaceFS

func (p *ProjectServiceHost) ReplaceFS(files map[string]any)

func (*ProjectServiceHost) TypingsLocation

func (p *ProjectServiceHost) TypingsLocation() string

type TestTypingsInstallerOptions

type TestTypingsInstallerOptions struct {
	TypesRegistry []string
	PackageToFile map[string]string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL