-
Notifications
You must be signed in to change notification settings - Fork 101
/
provider.spec.ts
118 lines (90 loc) · 3.24 KB
/
provider.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import * as assert from 'node:assert';
import * as path from 'node:path';
import Settings from '../settings';
import * as tests from '../tests';
import { Provider } from './provider';
import type { Task } from '../managers/tasks';
import type { Options } from '../settings';
import type { Dictionary, MicromatchOptions, ReaderOptions } from '../types';
class TestProvider extends Provider<Dictionary[]> {
public read(): Dictionary[] {
return [];
}
public getRootDirectory(task: Task): string {
return this._getRootDirectory(task);
}
public getReaderOptions(task: Task): ReaderOptions {
return this._getReaderOptions(task);
}
public getMicromatchOptions(): MicromatchOptions {
return this._getMicromatchOptions();
}
}
function getProvider(options?: Options): TestProvider {
const settings = new Settings(options);
return new TestProvider(settings);
}
describe('Providers → Provider', () => {
describe('Constructor', () => {
it('should create instance of class', () => {
const provider = getProvider();
assert.ok(provider instanceof Provider);
});
});
describe('.getRootDirectory', () => {
it('should return root directory for reader with global base (.)', () => {
const provider = getProvider();
const task = tests.task.builder().base('.').build();
const expected = process.cwd();
const actual = provider.getRootDirectory(task);
assert.strictEqual(actual, expected);
});
it('should return root directory for reader with non-global base (fixtures)', () => {
const provider = getProvider();
const task = tests.task.builder().base('root').build();
const expected = path.join(process.cwd(), 'root');
const actual = provider.getRootDirectory(task);
assert.strictEqual(actual, expected);
});
});
describe('.getReaderOptions', () => {
it('should return options for reader with global base (.)', () => {
const settings = new Settings();
const provider = getProvider(settings);
const task = tests.task.builder().base('.').positive('*').build();
const actual = provider.getReaderOptions(task);
assert.strictEqual(actual.basePath, '');
assert.strictEqual(typeof actual.deepFilter, 'function');
assert.strictEqual(typeof actual.entryFilter, 'function');
assert.strictEqual(typeof actual.errorFilter, 'function');
assert.ok(actual.followSymbolicLinks);
assert.strictEqual(typeof actual.fs, 'object');
assert.ok(!actual.stats);
assert.ok(actual.throwErrorOnBrokenSymbolicLink === false);
assert.strictEqual(typeof actual.transform, 'function');
});
it('should return options for reader with non-global base', () => {
const provider = getProvider();
const task = tests.task.builder().base('root').positive('*').build();
const actual = provider.getReaderOptions(task);
assert.strictEqual(actual.basePath, 'root');
});
});
describe('.getMicromatchOptions', () => {
it('should return options for micromatch', () => {
const provider = getProvider();
const expected: MicromatchOptions = {
dot: false,
matchBase: false,
nobrace: false,
nocase: false,
noext: false,
noglobstar: false,
posix: true,
strictSlashes: false,
};
const actual = provider.getMicromatchOptions();
assert.deepStrictEqual(actual, expected);
});
});
});