forked from ChromeDevTools/devtools-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathno-it-screenshot-only-or-repeat.js
44 lines (41 loc) · 1.56 KB
/
no-it-screenshot-only-or-repeat.js
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
// 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.
'use strict';
/**
* @type {import('eslint').Rule.RuleModule}
*/
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'ensure no itScreenshot.only or itScreenshot.repeat calls',
category: 'Possible Errors',
},
messages: {
// Formatted like this to make it easily to dynamically look up the
// message based on the invalid property name.
'itScreenshot-only': 'Focused screenshot tests are not allowed.',
'itScreenshot-repeat': 'Repeated screenshot tests are not allowed.',
},
fixable: 'code',
schema: [] // no options
},
create: function(context) {
const BANNED_IT_EXTENSIONS = new Set(['only', 'repeat']);
return {
'CallExpression[callee.type="MemberExpression"][callee.object.name="itScreenshot"]'(node) {
const calleePropertyName = node.callee.property.name;
if (!BANNED_IT_EXTENSIONS.has(calleePropertyName)) {
return;
}
const errorMessageId = `itScreenshot-${calleePropertyName}`;
// We report the node.callee.property as the bad node so that in an editor
// only the ".only" / ".repeat" part is highlighted as an error, else it is very
// distracting when you're working on debugging a test and the entire
// body of the test is highlighted as an error.
context.report({node: node.callee.property, messageId: errorMessageId});
}
};
}
};