Skip to content
This repository was archived by the owner on Jun 29, 2025. It is now read-only.

Commit a04d974

Browse files
authored
data-test-id plugin integration (#188)
* data-test-id plugin integration * cleanup: no need of this now * refactor: added plugin as extension * updated test cases * updated packge to latest * update: test cases * refactor: integrated as plugin
1 parent bc02cd1 commit a04d974

File tree

5 files changed

+97
-6
lines changed

5 files changed

+97
-6
lines changed

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
const a11y = require.resolve('./rules/a11y');
22
const vue = require.resolve('./rules/vue');
33
const vuex = require.resolve('./rules/vuex');
4+
const testId = require.resolve('./rules/test-id');
45

56
module.exports = {
6-
extends: ['plugin:vue/recommended', a11y, vue, vuex],
7+
extends: ['plugin:vue/recommended', a11y, vue, vuex, testId],
78
parserOptions: {
89
parser: 'babel-eslint',
910
},
10-
plugins: ['vue', 'vuejs-accessibility'],
11+
plugins: ['vue', 'vuejs-accessibility', 'test-id'],
1112
env: {
1213
es6: true,
1314
},

package-lock.json

Lines changed: 14 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"eslint-plugin-import": "^2.22.1",
4444
"eslint-plugin-jest": "^24.1.3",
4545
"eslint-plugin-prettier": "^3.3.0",
46+
"eslint-plugin-test-id": "^1.1.0",
4647
"eslint-plugin-unicorn": "^23.0.0",
4748
"eslint-plugin-vue": "^7.2.0",
4849
"eslint-plugin-vuejs-accessibility": "^0.6.0",
@@ -54,6 +55,7 @@
5455
},
5556
"peerDependencies": {
5657
"eslint": "^7.0.0",
58+
"eslint-plugin-test-id": "^1.1.0",
5759
"eslint-plugin-vue": "^7.0.0",
5860
"eslint-plugin-vuejs-accessibility": "^0.6.0"
5961
},

rules/test-id.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
rules: {
3+
'test-id/data-test-id': 'error',
4+
},
5+
};

test/plugin-test-id.test.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
const eslint = require('eslint');
2+
3+
describe('test eslint-plugin-test-id', () => {
4+
test('`v-model` without `data-test-id`', () => {
5+
const code = `
6+
<template>
7+
<div>
8+
<test v-model="somedata"> some slot data </test>
9+
</div>
10+
</template>
11+
12+
<script>
13+
export default {
14+
components: {
15+
data() {
16+
return{
17+
somedata: 'test'
18+
}
19+
}
20+
}
21+
}
22+
</script>
23+
`;
24+
const expectedErrorLineNum = 4;
25+
const expectedErrorColumnNum = 11;
26+
const linter = new eslint.CLIEngine({
27+
useEslintrc: false,
28+
configFile: '.eslintrc.json',
29+
});
30+
const errors = linter.executeOnText(code).results[0].messages;
31+
const error = errors[0];
32+
33+
expect(error.ruleId).toStrictEqual('test-id/data-test-id');
34+
expect(error.line).toStrictEqual(expectedErrorLineNum);
35+
expect(error.column).toStrictEqual(expectedErrorColumnNum);
36+
expect(error.message).toStrictEqual(`Expected 'data-test-id' with v-model.`);
37+
});
38+
39+
test('`v-model` with `data-test-id`', () => {
40+
const code = `
41+
<template>
42+
<div>
43+
<test v-model="somedata" data-test-id="somedata"> some slot data </test>
44+
</div>
45+
</template>
46+
47+
<script>
48+
export default {
49+
components: {
50+
data() {
51+
return{
52+
somedata: 'test'
53+
}
54+
}
55+
}
56+
}
57+
</script>
58+
`;
59+
const expectedErrorLineNum = 6;
60+
const expectedErrorColumnNum = 18;
61+
const linter = new eslint.CLIEngine({
62+
useEslintrc: false,
63+
configFile: '.eslintrc.json',
64+
});
65+
const errors = linter.executeOnText(code).results[0].messages;
66+
const error = errors[0];
67+
68+
expect(error.ruleId).toStrictEqual('vue/comment-directive');
69+
expect(error.line).toStrictEqual(expectedErrorLineNum);
70+
expect(error.column).toStrictEqual(expectedErrorColumnNum);
71+
expect(error.message).toStrictEqual('clear');
72+
});
73+
});

0 commit comments

Comments
 (0)