BettererFileResolver
API > @betterer/betterer > BettererFileResolver
A helper for resolving file paths in a BettererFileTest
.
Signature
export interface BettererFileResolver
Remarks
For ergonomic reasons, a test consumer should be able to use relative paths when they use a test, whether that be passing the path to a config file, or using BettererFileTest.include()
to select relevant files.
To enable that, Betterer creates a BettererFileResolver
whenever a BettererFileTest
is run. The baseDirectory
is set to the directory containing the test definition file.
Internally Betterer uses the BettererFileResolver
to manage file paths specified by BettererFileTest.include()
and BettererFileTest.exclude
. A test function can use the BettererFileResolver
to resolve and validate file paths.
Example
import { BettererFileTest } from '@betterer/betterer';
export function myFileTest (relativeConfigFilePath: string) {
return new BettererFileTest((_, __, resolver) => {
// Resolve a file path relative to the `baseDirectory`
const absoluteConfigFilePath = resolver.resolve(relativeConfigFilePath);
// Validate if some file paths are relevant for a test:
const validatedPaths = resolver.validate(
['./file-1.js', './file-2.js', './file-3.ts']
);
// ['./file-1.js']
})
.include('**\/*.js')
.exclude(/file-2.js/);
};
Properties
Property | Type | Description |
---|---|---|
baseDirectory | string | The direction from which all file paths are resolved. |
Methods
Method | Description |
---|---|
resolve(pathSegments) | Resolve a file path relative to the baseDirectory . |
validate(filePaths) | Validate if some file paths are relevant for a test. Files can be included and excluded via BettererFileTest.include() and BettererFileTest.exclude() . |