-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement linting tests (#2333)
- created linting tests for the following rules: - import-playwright-a11y.cjs - no-shadow-native-events.cjs - require-root-class - removed unnessesary testing from require-root-class because it's already tested on default.
- Loading branch information
1 parent
63993e9
commit 4c31ef1
Showing
7 changed files
with
265 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
packages/eslint-plugin/src/tests/import-playwright-a11y.cjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
"use strict"; | ||
|
||
const { RuleTester } = require("eslint"); | ||
const rule = require("../rules/import-playwright-a11y.cjs"); | ||
|
||
const tester = new RuleTester({ | ||
languageOptions: { | ||
parser: require("vue-eslint-parser"), | ||
ecmaVersion: 2020, | ||
sourceType: "module", | ||
}, | ||
}); | ||
|
||
tester.run("no-playwright-imports-when-fixture-available", rule, { | ||
valid: [ | ||
{ | ||
code: ` | ||
import { someOtherFunction } from "@playwright/experimental-ct-vue"; | ||
`, | ||
filename: "/some/other/path/to/file.js", | ||
}, | ||
{ | ||
code: ` | ||
import { expect } from "../../playwright/a11y"; | ||
`, | ||
filename: "/path/to/playwright/a11y.ts", | ||
}, | ||
], | ||
|
||
invalid: [ | ||
{ | ||
code: ` | ||
import { test, expect } from "@playwright/test"; | ||
`, | ||
errors: [ | ||
{ | ||
message: | ||
'Import "test" from "../../playwright/a11y" instead because onyx uses custom Playwright fixtures for providing a global configuration for accessibility testing.', | ||
}, | ||
{ | ||
message: | ||
'Import "expect" from "../../playwright/a11y" instead because onyx uses custom Playwright fixtures for providing a global configuration for accessibility testing.', | ||
}, | ||
], | ||
filename: "/path/to/file.js", | ||
}, | ||
{ | ||
code: ` | ||
import { test, expect } from "@playwright/experimental-ct-vue"; | ||
`, | ||
errors: [ | ||
{ | ||
message: | ||
'Import "test" from "../../playwright/a11y" instead because onyx uses custom Playwright fixtures for providing a global configuration for accessibility testing.', | ||
}, | ||
{ | ||
message: | ||
'Import "expect" from "../../playwright/a11y" instead because onyx uses custom Playwright fixtures for providing a global configuration for accessibility testing.', | ||
}, | ||
], | ||
filename: "/path/to/file.js", | ||
}, | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require("./import-playwright-a11y.cjs"); | ||
require("./no-shadow-native-events.cjs"); | ||
require("./require-root-class.cjs"); |
89 changes: 89 additions & 0 deletions
89
packages/eslint-plugin/src/tests/no-shadow-native-events.cjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
"use strict"; | ||
|
||
const { RuleTester } = require("eslint"); | ||
const rule = require("../rules/no-shadow-native-events.cjs"); | ||
|
||
const tester = new RuleTester({ | ||
languageOptions: { | ||
parser: require("vue-eslint-parser"), | ||
ecmaVersion: 2020, | ||
sourceType: "module", | ||
}, | ||
}); | ||
tester.run("no-native-event-emits", rule, { | ||
valid: [ | ||
{ | ||
code: ` | ||
<script setup> | ||
defineEmits(['customClick']); | ||
</script> | ||
`, | ||
}, | ||
{ | ||
code: ` | ||
<script> | ||
export default { | ||
emits: ['customSubmit'], | ||
methods: { | ||
emitSomething() { | ||
this.$emit('customChange'); | ||
}, | ||
}, | ||
}; | ||
</script> | ||
`, | ||
}, | ||
{ | ||
code: ` | ||
<script> | ||
export default { | ||
emits: ['customHover'], | ||
}; | ||
</script> | ||
`, | ||
}, | ||
], | ||
invalid: [ | ||
{ | ||
code: ` | ||
<script setup> | ||
defineEmits(['click']); | ||
</script> | ||
`, | ||
errors: [ | ||
{ | ||
message: | ||
'Use a different emit name to avoid shadowing the native event with name "click". Consider an emit name which communicates the users intent, if applicable.', | ||
}, | ||
], | ||
}, | ||
{ | ||
code: ` | ||
<script setup> | ||
const emit = defineEmits(['focus']); | ||
emit('focus'); | ||
</script> | ||
`, | ||
errors: [ | ||
{ | ||
message: | ||
'Use a different emit name to avoid shadowing the native event with name "focus". Consider an emit name which communicates the users intent, if applicable.', | ||
}, | ||
], | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div @click="$emit('submit')"> | ||
</div> | ||
</template> | ||
`, | ||
errors: [ | ||
{ | ||
message: | ||
'Use a different emit name to avoid shadowing the native event with name "submit". Consider an emit name which communicates the users intent, if applicable.', | ||
}, | ||
], | ||
}, | ||
], | ||
}); |
105 changes: 105 additions & 0 deletions
105
packages/eslint-plugin/src/tests/require-root-class.cjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
"use strict"; | ||
|
||
const { RuleTester } = require("eslint"); | ||
const rule = require("../rules/require-root-class.cjs"); | ||
|
||
const tester = new RuleTester({ | ||
languageOptions: { | ||
parser: require("vue-eslint-parser"), | ||
ecmaVersion: 2020, | ||
sourceType: "module", | ||
}, | ||
}); | ||
tester.run("require-onyx-component-class", rule, { | ||
valid: [ | ||
{ | ||
code: ` | ||
<template> | ||
<div class="onyx-component"> | ||
<p>Valid component</p> | ||
</div> | ||
</template> | ||
`, | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div :class="'onyx-component'"> | ||
<p>Dynamic class</p> | ||
</div> | ||
</template> | ||
`, | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div :class="['class1', 'onyx-component']"> | ||
<p>Array class binding</p> | ||
</div> | ||
</template> | ||
`, | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div :class="{ 'onyx-component': true, 'other-class': false }"> | ||
<p>Object class binding</p> | ||
</div> | ||
</template> | ||
`, | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<onyx-custom-element> | ||
<p>Custom Onyx element</p> | ||
</onyx-custom-element> | ||
</template> | ||
`, | ||
}, | ||
], | ||
invalid: [ | ||
{ | ||
code: ` | ||
<template> | ||
<div> | ||
<p>Missing class</p> | ||
</div> | ||
</template> | ||
`, | ||
errors: [ | ||
{ | ||
messageId: "missingClass", | ||
}, | ||
], | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div :class="['class1', 'class2']"> | ||
<p>Array binding without onyx-component</p> | ||
</div> | ||
</template> | ||
`, | ||
errors: [ | ||
{ | ||
messageId: "missingClass", | ||
}, | ||
], | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div :class="{ 'other-class': true }"> | ||
<p>Object binding without onyx-component</p> | ||
</div> | ||
</template> | ||
`, | ||
errors: [ | ||
{ | ||
messageId: "missingClass", | ||
}, | ||
], | ||
}, | ||
], | ||
}); |