2023-10-30 14:23:40 +00:00
|
|
|
module.exports = {
|
|
|
|
meta: {
|
|
|
|
type: 'problem',
|
|
|
|
docs: {
|
|
|
|
description:
|
2024-05-27 14:54:06 +00:00
|
|
|
'advise using @woocommerce/e2e-utils for importing test or expect functions',
|
2023-10-30 14:23:40 +00:00
|
|
|
category: 'Possible Errors',
|
|
|
|
recommended: true,
|
|
|
|
},
|
|
|
|
fixable: 'code',
|
|
|
|
schema: [],
|
|
|
|
messages: {
|
|
|
|
unexpected:
|
2024-05-27 14:54:06 +00:00
|
|
|
"Prefer importing { test, expect } from '@woocommerce/e2e-utils'.",
|
2023-10-30 14:23:40 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
create( context ) {
|
|
|
|
return {
|
|
|
|
ImportDeclaration( node ) {
|
|
|
|
if ( node.source.value === '@playwright/test' ) {
|
|
|
|
const functionsNotAllowedToImportFromPlaywright = [
|
|
|
|
'test',
|
|
|
|
'expect',
|
|
|
|
];
|
|
|
|
const testSpecifier = node.specifiers.find(
|
|
|
|
( specifier ) =>
|
|
|
|
specifier.imported &&
|
|
|
|
functionsNotAllowedToImportFromPlaywright.includes(
|
|
|
|
specifier.imported.name
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( testSpecifier ) {
|
|
|
|
context.report( {
|
|
|
|
node,
|
|
|
|
message:
|
2024-05-27 14:54:06 +00:00
|
|
|
'Import test or expect from @woocommerce/e2e-utils instead of @playwright/test for additional utilities.',
|
2023-10-30 14:23:40 +00:00
|
|
|
fix( fixer ) {
|
|
|
|
return [
|
|
|
|
fixer.replaceText(
|
|
|
|
node.source,
|
2024-05-27 14:54:06 +00:00
|
|
|
"'@woocommerce/e2e-utils'"
|
2023-10-30 14:23:40 +00:00
|
|
|
),
|
|
|
|
];
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
};
|