mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
Lint e2e tests, enforce selectors
This commit is contained in:
@@ -266,6 +266,7 @@
|
||||
"options": {
|
||||
"lintFilePatterns": [
|
||||
"src/**/*.ts",
|
||||
"cypress/**/*.ts",
|
||||
"src/**/*.html",
|
||||
"src/**/*.json5"
|
||||
]
|
||||
|
@@ -98,7 +98,20 @@ export default ESLintUtils.RuleCreator.withoutDocs({
|
||||
// ignore tests and non-routing modules
|
||||
if (context.getFilename()?.endsWith('.spec.ts')) {
|
||||
return {
|
||||
[`CallExpression[callee.object.name = "By"][callee.property.name = "css"] > Literal[value = /.*${DISALLOWED_THEME_SELECTORS}.*/]`](node: any) {
|
||||
[`CallExpression[callee.object.name = "By"][callee.property.name = "css"] > Literal:first-child[value = /.*${DISALLOWED_THEME_SELECTORS}.*/]`](node: any) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'mustUseThemedWrapper',
|
||||
fix(fixer: any){
|
||||
const newSelector = fixSelectors(node.raw);
|
||||
return fixer.replaceText(node, newSelector);
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
} else if (context.getFilename()?.endsWith('.cy.ts')) {
|
||||
return {
|
||||
[`CallExpression[callee.object.name = "cy"][callee.property.name = "get"] > Literal:first-child[value = /.*${DISALLOWED_THEME_SELECTORS}.*/]`](node: any) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'mustUseThemedWrapper',
|
||||
|
8
lint/test/fixture/src/app/test/test.component.cy.ts
Normal file
8
lint/test/fixture/src/app/test/test.component.cy.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
|
@@ -52,6 +52,13 @@ export class Something {
|
||||
name: fixture('src/app/test/test.component.spec.ts'),
|
||||
code: `
|
||||
By.css('ds-themeable');
|
||||
By.Css('#test > ds-themeable > #nest');
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: fixture('src/app/test/test.component.cy.ts'),
|
||||
code: `
|
||||
By.css('ds-themeable');
|
||||
By.Css('#test > ds-themeable > #nest');
|
||||
`,
|
||||
},
|
||||
@@ -123,6 +130,44 @@ By.css('ds-themeable');
|
||||
By.css('#test > ds-themeable > #nest');
|
||||
`,
|
||||
},
|
||||
{
|
||||
filename: fixture('src/app/test/test.component.cy.ts'),
|
||||
code: `
|
||||
cy.get('ds-themed-themeable');
|
||||
cy.get('#test > ds-themed-themeable > #nest');
|
||||
`,
|
||||
errors: [
|
||||
{
|
||||
messageId: 'mustUseThemedWrapper',
|
||||
},
|
||||
{
|
||||
messageId: 'mustUseThemedWrapper',
|
||||
},
|
||||
],
|
||||
output: `
|
||||
cy.get('ds-themeable');
|
||||
cy.get('#test > ds-themeable > #nest');
|
||||
`,
|
||||
},
|
||||
{
|
||||
filename: fixture('src/app/test/test.component.cy.ts'),
|
||||
code: `
|
||||
cy.get('ds-base-themeable');
|
||||
cy.get('#test > ds-base-themeable > #nest');
|
||||
`,
|
||||
errors: [
|
||||
{
|
||||
messageId: 'mustUseThemedWrapper',
|
||||
},
|
||||
{
|
||||
messageId: 'mustUseThemedWrapper',
|
||||
},
|
||||
],
|
||||
output: `
|
||||
cy.get('ds-themeable');
|
||||
cy.get('#test > ds-themeable > #nest');
|
||||
`,
|
||||
},
|
||||
],
|
||||
} as any);
|
||||
});
|
||||
|
Reference in New Issue
Block a user