Skip to content

Commit 2e77b91

Browse files
committed
Convert screenshot-assertion-in-it-screenshot to TypeScript
Bug: chromium:397586315 Change-Id: Ib1aef5994785e77f08990b952ace867f60bfc70d Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6441157 Reviewed-by: Andres Olivares <andoli@chromium.org> Reviewed-by: Nikolay Vitkov <nvitkov@chromium.org>
1 parent a5686a8 commit 2e77b91

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

scripts/eslint_rules/lib/screenshot-assertion-in-it-screenshot.js renamed to scripts/eslint_rules/lib/screenshot-assertion-in-it-screenshot.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
'use strict';
6-
/**
7-
* @type {import('eslint').Rule.RuleModule}
8-
*/
9-
module.exports = {
5+
import type {TSESTree} from '@typescript-eslint/utils';
6+
7+
import {createRule} from './tsUtils.ts';
8+
9+
export default createRule({
10+
name: 'screenshot-assertion-in-it-screenshot',
1011
meta: {
1112
type: 'problem',
12-
1313
docs: {
1414
description: 'ensure screenshots are asserted in an itScreenshot block',
1515
category: 'Possible Errors',
@@ -20,6 +20,7 @@ module.exports = {
2020
fixable: 'code',
2121
schema: [] // no options
2222
},
23+
defaultOptions: [],
2324
create: function(context) {
2425
const SCREENSHOT_ASSERTION_FUNCTIONS =
2526
new Set(['assertElementScreenshotUnchanged', 'assertPageScreenshotUnchanged']);
@@ -53,7 +54,7 @@ module.exports = {
5354
}
5455

5556
function findItParentForNode(node) {
56-
if (!node || !node.parent) {
57+
if (!node?.parent) {
5758
return null;
5859
}
5960

@@ -96,15 +97,14 @@ module.exports = {
9697
}
9798

9899
return {
99-
'CallExpression[callee.type="Identifier"][callee.name="it"]'(node) {
100+
'CallExpression[callee.type="Identifier"][callee.name="it"]'(node: TSESTree.CallExpression) {
100101
const testCallback = node.arguments[1];
101-
const validCallbackTypes = ['ArrowFunctionExpression', 'FunctionExpression'];
102-
if (!testCallback || !validCallbackTypes.includes(testCallback.type)) {
103-
// Oddly structured it: bail.
104-
return;
102+
if (testCallback.type === 'ArrowFunctionExpression' || testCallback.type === 'FunctionExpression') {
103+
if (testCallback.body.type === 'BlockStatement') {
104+
checkForScreenshotCalls(testCallback.body.body);
105+
}
105106
}
106-
checkForScreenshotCalls(testCallback.body.body);
107107
}
108108
};
109109
}
110-
};
110+
});

scripts/eslint_rules/tests/screenshot-assertion-in-it-screenshot.test.js renamed to scripts/eslint_rules/tests/screenshot-assertion-in-it-screenshot.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
'use strict';
6-
const rule = require('../lib/screenshot-assertion-in-it-screenshot.js');
5+
import rule from '../lib/screenshot-assertion-in-it-screenshot.ts';
76

8-
const {RuleTester} = require('./utils/utils.js');
7+
import {RuleTester} from './utils/tsUtils.ts';
98

109
new RuleTester().run('screenshot-assertion-in-it-screenshot', rule, {
1110
valid: [

0 commit comments

Comments
 (0)