-
Notifications
You must be signed in to change notification settings - Fork 0
/
dangerfile.ts
30 lines (25 loc) · 846 Bytes
/
dangerfile.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
import { danger, fail } from "danger";
import { structuredFileAddedLineMatches } from "danger-plugin-toolbox";
const TestDataIDs = async (git, failer) => {
const wrongAttributeRegExp =
/data-testId|data-testID|datatestid|data-test-id|data-test-Id|data-test-ID|data-qa|data-QA/;
const filesWithWrongDataTestId: string[] = [];
await Promise.all(
git.created_files.map(async (file) => {
const dataTestIDs = await structuredFileAddedLineMatches(
file,
wrongAttributeRegExp
);
if (dataTestIDs.length > 0) {
filesWithWrongDataTestId.push(file);
}
})
);
filesWithWrongDataTestId.forEach((file) => {
failer(
`Wrong "data-testid" attribute found in file ${file} -
<i>Make sure you use "data-testid" attribute</i>`
);
});
};
TestDataIDs(danger.git, fail);