-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathbinding.unit.test.ts
More file actions
143 lines (128 loc) · 4.5 KB
/
binding.unit.test.ts
File metadata and controls
143 lines (128 loc) · 4.5 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import type { PluginAnswer } from '@code-pushup/models';
import { createMockTree } from '@code-pushup/test-utils';
import { axeSetupBinding as binding } from './binding.js';
const defaultAnswers: Record<string, PluginAnswer> = {
'axe.urls': 'http://localhost:4200',
'axe.preset': 'wcag21aa',
'axe.setupScript': false,
'axe.categories': true,
};
const noCategoryAnswers: Record<string, PluginAnswer> = {
...defaultAnswers,
'axe.categories': false,
};
describe('axeSetupBinding', () => {
describe('prompts', () => {
it('should offer preset choices with wcag21aa as default', async () => {
await expect(binding.prompts!()).resolves.toIncludeAllPartialMembers([
{ key: 'axe.preset', type: 'select', default: 'wcag21aa' },
]);
});
it('should default setupScript to false', async () => {
await expect(binding.prompts!()).resolves.toIncludeAllPartialMembers([
{ key: 'axe.setupScript', type: 'confirm', default: false },
]);
});
});
describe('generateConfig with categories selected', () => {
it('should declare plugin as a variable for use in category refs', async () => {
const { pluginDeclaration } = await binding.generateConfig(
defaultAnswers,
createMockTree(),
);
expect(pluginDeclaration).toStrictEqual({
identifier: 'axe',
expression: "axePlugin('http://localhost:4200')",
});
});
it('should import axeGroupRefs helper', async () => {
const { imports } = await binding.generateConfig(
defaultAnswers,
createMockTree(),
);
expect(imports).toStrictEqual([
expect.objectContaining({ namedImports: ['axeGroupRefs'] }),
]);
});
it('should produce accessibility category with refs expression', async () => {
const { categories } = await binding.generateConfig(
defaultAnswers,
createMockTree(),
);
expect(categories).toStrictEqual([
expect.objectContaining({
slug: 'a11y',
refsExpression: 'axeGroupRefs(axe)',
}),
]);
});
});
describe('generateConfig without categories selected', () => {
it('should not declare plugin as a variable', async () => {
const { pluginDeclaration } = await binding.generateConfig(
noCategoryAnswers,
createMockTree(),
);
expect(pluginDeclaration).toBeUndefined();
});
it('should not import axeGroupRefs helper', async () => {
const { imports } = await binding.generateConfig(
noCategoryAnswers,
createMockTree(),
);
expect(imports[0]).not.toHaveProperty('namedImports');
});
it('should not produce categories', async () => {
const { categories } = await binding.generateConfig(
noCategoryAnswers,
createMockTree(),
);
expect(categories).toBeUndefined();
});
});
describe('setup script', () => {
it('should write setup script file when confirmed', async () => {
const tree = createMockTree();
await binding.generateConfig(
{ ...defaultAnswers, 'axe.setupScript': true },
tree,
);
expect(tree.written.get('./axe-setup.ts')).toContain(
"import type { Page } from 'playwright-core'",
);
});
it('should include setupScript in plugin call when confirmed', async () => {
const { pluginDeclaration } = await binding.generateConfig(
{ ...defaultAnswers, 'axe.setupScript': true },
createMockTree(),
);
expect(pluginDeclaration!.expression).toContain(
"setupScript: './axe-setup.ts'",
);
});
it('should not write setup script file when declined', async () => {
const tree = createMockTree();
await binding.generateConfig(defaultAnswers, tree);
expect(tree.written.size).toBe(0);
});
});
it('should include non-default preset in plugin call', async () => {
const { pluginDeclaration } = await binding.generateConfig(
{ ...defaultAnswers, 'axe.preset': 'wcag22aa' },
createMockTree(),
);
expect(pluginDeclaration!.expression).toContain("preset: 'wcag22aa'");
});
it('should format multiple URLs as array', async () => {
const { pluginDeclaration } = await binding.generateConfig(
{
...defaultAnswers,
'axe.urls': 'http://localhost:4200/login, http://localhost:4200/home',
},
createMockTree(),
);
expect(pluginDeclaration!.expression).toContain(
"axePlugin(['http://localhost:4200/login', 'http://localhost:4200/home']",
);
});
});