mirror of
				https://github.com/ionic-team/ionic-framework.git
				synced 2025-11-04 21:30:00 +08:00 
			
		
		
		
	Issue number: N/A --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> Ionic Framework has a set of custom lint assertions to avoid creating flaky Playwright tests by forgetting to await a promise. However the `click` method was not included in the original list of methods to check. ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - Developers will receive a lint error when forgetting to await click methods from Playwright - Resolves existing tests where this lint issue was present ## Does this introduce a breaking change? - [ ] Yes - [x] No <!-- If this introduces a breaking change: 1. Describe the impact and migration path for existing applications below. 2. Update the BREAKING.md file with the breaking change. 3. Add "BREAKING CHANGE: [...]" to the commit description when merging. See https://github.com/ionic-team/ionic-framework/blob/main/docs/CONTRIBUTING.md#footer for more information. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. -->
		
			
				
	
	
		
			72 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			72 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
module.exports = {
 | 
						|
  meta: {
 | 
						|
    messages: {
 | 
						|
      awaitPlaywrightPromiseAssertion: 'This Playwright assertion returns a Promise. Add an "await" to avoid creating a flaky test.',
 | 
						|
    },
 | 
						|
  },
 | 
						|
  create(context) {
 | 
						|
    return {
 | 
						|
      ExpressionStatement(node) {
 | 
						|
        const expression = node.expression;
 | 
						|
 | 
						|
        /**
 | 
						|
         * The first expression of a properly awaited
 | 
						|
         * Playwright assertion should be an AwaitExpression,
 | 
						|
         * so if it goes directly to the CallExpression
 | 
						|
         * then we potentially need to report this.
 | 
						|
         */
 | 
						|
        if (expression.type === 'CallExpression') {
 | 
						|
          const { object, property } = expression.callee;
 | 
						|
 | 
						|
          /**
 | 
						|
           * Check to see if the property name is
 | 
						|
           * of a known Playwright async assertion.
 | 
						|
           */
 | 
						|
          if (
 | 
						|
            property !== undefined &&
 | 
						|
            property.type === 'Identifier' &&
 | 
						|
            hasPlaywrightAsyncAssertion(property.name)
 | 
						|
          ) {
 | 
						|
            context.report({ node: node, messageId: 'awaitPlaywrightPromiseAssertion' });
 | 
						|
          }
 | 
						|
        }
 | 
						|
      }
 | 
						|
    }
 | 
						|
  }
 | 
						|
};
 | 
						|
 | 
						|
/**
 | 
						|
 * Returns `true` if `property` is the name
 | 
						|
 * of a known async Playwright assertion.
 | 
						|
 */
 | 
						|
const hasPlaywrightAsyncAssertion = (property) => {
 | 
						|
  return ASYNC_PLAYWRIGHT_ASSERTS.includes(property);
 | 
						|
}
 | 
						|
 | 
						|
// https://playwright.dev/docs/test-assertions
 | 
						|
const ASYNC_PLAYWRIGHT_ASSERTS = [
 | 
						|
  'toBeChecked',
 | 
						|
  'toBeDisabled',
 | 
						|
  'toBeEditable',
 | 
						|
  'toBeEmpty',
 | 
						|
  'toBeEnabled',
 | 
						|
  'toBeFocused',
 | 
						|
  'toBeHidden',
 | 
						|
  'toBeVisible',
 | 
						|
  'toContainText',
 | 
						|
  'toHaveAttribute',
 | 
						|
  'toHaveClass',
 | 
						|
  'toHaveCount',
 | 
						|
  'toHaveCSS',
 | 
						|
  'toHaveId',
 | 
						|
  'toHaveJSProperty',
 | 
						|
  'toHaveScreenshot',
 | 
						|
  'toHaveText',
 | 
						|
  'toHaveValue',
 | 
						|
  'toHaveValues',
 | 
						|
  'toHaveTitle',
 | 
						|
  'toHaveURL',
 | 
						|
  'toBeOK',
 | 
						|
  'click'
 | 
						|
];
 |