-
Notifications
You must be signed in to change notification settings - Fork 498
/
Copy pathno-screenshot-test-outside-perf-panel.ts
77 lines (70 loc) · 2.06 KB
/
no-screenshot-test-outside-perf-panel.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
// Copyright 2023 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import * as path from 'path';
import {createRule} from './utils/ruleCreator.ts';
const PERFORMANCE_PANEL_INTERACTION_TESTS_PATH = path.join(
// @ts-expect-error
import.meta.dirname,
'..',
'..',
'..',
'test',
'interactions',
'panels',
'performance',
);
const UI_COMPONENTS_PATH = path.join(
// @ts-expect-error
import.meta.dirname,
'..',
'..',
'..',
'test',
'interactions',
'ui',
'components',
);
export default createRule({
name: 'no-screenshot-test-outside-perf-panel',
meta: {
type: 'problem',
docs: {
description: 'Bans writing screenshot tests outside the directory for the Performance Panel interaction tests.',
category: 'Possible Errors',
},
messages: {
invalidScreenshotTest:
'It is banned to write screenshot tests outside the directory of the Performance Panel interaction tests or UI components tests.',
},
schema: [], // no options
},
defaultOptions: [],
create: function(context) {
const filename: string = context.filename;
const absoluteFileName: string = path.resolve(filename);
if (absoluteFileName.includes(PERFORMANCE_PANEL_INTERACTION_TESTS_PATH) ||
absoluteFileName.includes(UI_COMPONENTS_PATH)) {
return {};
}
return {
CallExpression(node) {
if (node.callee.type === 'Identifier' && node.callee.name === 'itScreenshot') {
context.report({
node,
messageId: 'invalidScreenshotTest',
});
}
},
MemberExpression(node) {
if (node.object.type === 'Identifier' && node.object.name === 'itScreenshot' &&
node.property.type === 'Identifier' && (node.property.name === 'skip' || node.property.name === 'only')) {
context.report({
node,
messageId: 'invalidScreenshotTest',
});
}
},
};
},
});