summaryrefslogtreecommitdiff
path: root/source/helpers/feature-utils.test.ts
blob: b3762b2ea618abf9fc3e47022971fb5c559dd34e (plain) (blame)
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
import {test, assert} from 'vitest';

import {shouldFeatureRun} from './feature-utils.js';

test('shouldFeatureRun', async () => {
	const yes = (): boolean => true;
	const no = (): boolean => false;
	const yesYes = [yes, yes];
	const yesNo = [yes, no];
	const noNo = [no, no];

	assert.isTrue(await shouldFeatureRun({}), 'A lack of conditions should mean "run everywhere"');

	assert.isFalse(await shouldFeatureRun({
		asLongAs: yesNo,
	}), 'Every `asLongAs` should be true to run');

	assert.isFalse(await shouldFeatureRun({
		asLongAs: yesNo,
		include: [yes],
	}), 'Every `asLongAs` should be true to run, regardless of `include`');

	assert.isFalse(await shouldFeatureRun({
		include: noNo,
	}), 'At least one `include` should be true to run');

	assert.isTrue(await shouldFeatureRun({
		include: yesNo,
	}), 'If one `include` is true, then it should run');

	assert.isFalse(await shouldFeatureRun({
		exclude: yesNo,
	}), 'If any `exclude` is true, then it should not run');

	assert.isFalse(await shouldFeatureRun({
		include: [yes],
		exclude: yesNo,
	}), 'If any `exclude` is true, then it should not run, regardless of `include`');

	assert.isFalse(await shouldFeatureRun({
		asLongAs: [yes],
		exclude: yesNo,
	}), 'If any `exclude` is true, then it should not run, regardless of `asLongAs`');

	assert.isFalse(await shouldFeatureRun({
		asLongAs: [yes],
		include: yesYes,
		exclude: yesNo,
	}), 'If any `exclude` is true, then it should not run, regardless of `asLongAs` and `include`');
});