Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow testing string sources #181

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

tommy-mitchell
Copy link
Contributor

@tommy-mitchell tommy-mitchell commented Mar 13, 2023

Closes #86.

Allows testing files passed to tsd as strings, either programmatically:

import tsd from 'tsd';

const diagnostics = await tsd({
	testFiles: [
		'file1.ts',
		{
			'name': 'file2.ts',
			'text': 'import {expectType} from \'tsd\';\nexpectType<number>(1);',
		},
	],
});

or via the CLI with a concise syntax (file.extension:source):

$ npx tsd --files "foo.ts:$(cat output.txt)"

Type definitions have been updated like so:

type TestFiles = ReadonlyArray<(
	| string
	| {name: string; text: string}
)>;

type SourceFiles = ReadonlyArray<{name: string; text: string}>;

type ParsedTestFiles = {
	globs: readonly string[];
	sourceFiles?: SourceFiles;
};

interface Context {
	cwd: string;
	pkg: PackageJsonWithTsdConfig;
	typingsFile: string;
	testFiles: ParsedTestFiles;
	config: Config;
}

interface Options {
	cwd: string;
	typingsFile?: string;
	testFiles?: TestFiles;
}

Still some items to finish, but opening this PR to get feedback:

  • Document feature in readme and CLI help
  • Add documentation comments to added functions/types
  • Improve names/concepts (e.g. globs vs. sourceFiles, etc.)
  • Consolidate repetition of some types
  • Make sure that parsing via the CLI is robust
  • See if input needs to be escaped

@sindresorhus
Copy link
Collaborator

Just a warning. I have very little time to spend on this project. So I will not be able to review non-essential things. I'm just helping out to keep it up to date with TS releases. So if you plan to make a lot of changes, I would recommend reaching out to @SamVerschueren to become a maintainer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide interfaces and test files via stdinput
2 participants