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 specifying the test files and typings file manually #74

Merged
merged 23 commits into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0122488
Remove VSCode config folder and add source code generation in TS build
smartclash Jun 24, 2020
e706b63
Allow passing of path to type definiton file manually
smartclash Jun 24, 2020
43ac091
Update README.md
smartclash Jun 24, 2020
1282ce6
Refactor code to check definition file existence if specified manually
smartclash Jun 24, 2020
8185162
Fix the checking of type file existence
smartclash Jun 24, 2020
35063ce
Use expect error instead of ignoring it
smartclash Jun 24, 2020
4d23908
Allow specifing test files manually
smartclash Jun 25, 2020
c7e427b
Allow passing relative path of typing def file
smartclash Jul 2, 2020
4cf8cb4
Allow passing relative path to test files
smartclash Jul 2, 2020
ea3961a
Make changes according to suggestions
smartclash Jul 23, 2020
134b88c
Fixed README alignment
smartclash Jul 24, 2020
64409b3
Add tests for new typingsFile option
smartclash Aug 7, 2020
6d24bca
Fixed tests file resolving issue when typingsFile option is set
smartclash Aug 7, 2020
1d391ae
Add tests for testFiles option
smartclash Aug 7, 2020
d925296
Add tests to check cases where typings file is not found in specified…
smartclash Aug 7, 2020
59670d6
Use globby for testFiles option
smartclash Aug 9, 2020
41e9e0c
Remove .vscode entry in gitignore
smartclash Oct 4, 2020
02927f0
Update docs
smartclash Oct 4, 2020
285c6cb
Make testFiles property readonly
smartclash Oct 4, 2020
59c5f4b
Fix grammar
smartclash Oct 4, 2020
9ece40e
Grammar in README
smartclash Oct 5, 2020
44c066e
Update readme.md
smartclash Dec 3, 2020
c549587
Improve readme
smartclash Dec 3, 2020
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
yarn.lock
dist/
.vscode/
13 changes: 13 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,19 @@ Default: `process.cwd()`

Current working directory of the project to retrieve the diagnostics for.

##### typingsFile

Type: `string`<br>
Default: `''`

Path to the type definitions of the project.

##### testFiles

type: `string[]`<br>
default: `['']`

An array of test files with their path
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above (needs to answer what its purpose is) and you're missing a dot at the end.


## License

Expand Down
5 changes: 1 addition & 4 deletions source/lib/compiler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as path from 'path';
import {
flattenDiagnosticMessageText,
createProgram,
Expand Down Expand Up @@ -65,11 +64,9 @@ const ignoreDiagnostic = (diagnostic: TSDiagnostic, expectedErrors: Map<Location
* @returns List of diagnostics
*/
export const getDiagnostics = (context: Context): Diagnostic[] => {
const fileNames = context.testFiles.map(fileName => path.join(context.cwd, fileName));

const diagnostics: Diagnostic[] = [];

const program = createProgram(fileNames, context.config.compilerOptions);
const program = createProgram(context.testFiles, context.config.compilerOptions);

const tsDiagnostics = program
.getSemanticDiagnostics()
Expand Down
13 changes: 8 additions & 5 deletions source/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import {Context, Config} from './interfaces';

export interface Options {
cwd: string;
typingsFile?: string;
testFiles?: string[];
}

const findTypingsFile = async (pkg: any, options: Options) => {
const typings = pkg.types || pkg.typings || 'index.d.ts';

const typings = options.typingsFile || pkg.types || pkg.typings || 'index.d.ts';
const typingsExist = await pathExists(path.join(options.cwd, typings));

if (!typingsExist) {
Expand All @@ -24,12 +25,15 @@ const findTypingsFile = async (pkg: any, options: Options) => {
};

const findTestFiles = async (typingsFile: string, options: Options & {config: Config}) => {
if (options.testFiles?.length) {
return options.testFiles.map(fileName => path.join(options.cwd, fileName));
}

const testFile = typingsFile.replace(/\.d\.ts$/, '.test-d.ts');
const tsxTestFile = typingsFile.replace(/\.d\.ts$/, '.test-d.tsx');
const testDir = options.config.directory;

let testFiles = await globby([testFile, tsxTestFile], {cwd: options.cwd});

const testDirExists = await pathExists(path.join(options.cwd, testDir));

if (testFiles.length === 0 && !testDirExists) {
Expand All @@ -40,7 +44,7 @@ const findTestFiles = async (typingsFile: string, options: Options & {config: Co
testFiles = await globby([`${testDir}/**/*.ts`, `${testDir}/**/*.tsx`], {cwd: options.cwd});
}

return testFiles;
return testFiles.map(fileName => path.join(options.cwd, fileName));
};

/**
Expand All @@ -56,7 +60,6 @@ export default async (options: Options = {cwd: process.cwd()}) => {
}

const pkg = pkgResult.packageJson;

const config = loadConfig(pkg as any, options.cwd);

// Look for a typings file, otherwise use `index.d.ts` in the root directory. If the file is not found, throw an error.
Expand Down