antler
Version:
Directory structure linter
53 lines (44 loc) • 1.3 kB
text/typescript
import { RegexRule } from '../../src/regex-rule';
import { DirectoryName } from '../../src/rules/directory-name';
import { Node } from '../../src/types';
describe('DirectoryName', () => {
const directoryNode: Node = {
fullPath: 'root/parent/child',
path: 'parent/child',
name: 'child',
parentName: 'parent',
siblingNamesIncludingSelf: ['child'],
childNames: [],
isDirectory: true,
};
const fileNode = {
...directoryNode,
isDirectory: false,
};
it('should extend RegexRule', () => {
const instance = new DirectoryName({
level: 'error',
options: { allow: '' },
});
expect(instance instanceof RegexRule).toBe(true);
});
describe('shouldRun', () => {
it('should run only for directories', () => {
const instance = new DirectoryName({
level: 'error',
options: { allow: '' },
});
expect(instance['shouldRun'](directoryNode)).toBe(true);
expect(instance['shouldRun'](fileNode)).toBe(false);
});
});
describe('getPart', () => {
it('should return the file / directory name', () => {
const instance = new DirectoryName({
level: 'error',
options: { allow: '' },
});
expect(instance['getPart'](directoryNode)).toBe('child');
});
});
});