2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
4
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' ,
10
11
meta : {
11
12
type : 'problem' ,
12
-
13
13
docs : {
14
14
description : 'ensure screenshots are asserted in an itScreenshot block' ,
15
15
category : 'Possible Errors' ,
@@ -20,6 +20,7 @@ module.exports = {
20
20
fixable : 'code' ,
21
21
schema : [ ] // no options
22
22
} ,
23
+ defaultOptions : [ ] ,
23
24
create : function ( context ) {
24
25
const SCREENSHOT_ASSERTION_FUNCTIONS =
25
26
new Set ( [ 'assertElementScreenshotUnchanged' , 'assertPageScreenshotUnchanged' ] ) ;
@@ -53,7 +54,7 @@ module.exports = {
53
54
}
54
55
55
56
function findItParentForNode ( node ) {
56
- if ( ! node || ! node . parent ) {
57
+ if ( ! node ? .parent ) {
57
58
return null ;
58
59
}
59
60
@@ -96,15 +97,14 @@ module.exports = {
96
97
}
97
98
98
99
return {
99
- 'CallExpression[callee.type="Identifier"][callee.name="it"]' ( node ) {
100
+ 'CallExpression[callee.type="Identifier"][callee.name="it"]' ( node : TSESTree . CallExpression ) {
100
101
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
+ }
105
106
}
106
- checkForScreenshotCalls ( testCallback . body . body ) ;
107
107
}
108
108
} ;
109
109
}
110
- } ;
110
+ } ) ;
0 commit comments