Skip to content

chore: Reduce number of lines of expected files #8325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 64 additions & 13 deletions test/validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ describe('validate', () => {
...options
});

assert.deepEqual(warnings.map(w => ({
code: w.code,
message: w.message,
pos: w.pos,
start: w.start,
end: w.end
})), expected_warnings);
assert.deepEqual(
warnings.map((w) => ({
code: w.code,
message: w.message,
start: { line: w.start.line, column: w.start.column },
end: { line: w.end.line, column: w.end.column }
})),
expected_warnings
);
} catch (e) {
error = e;
}
Expand All @@ -56,13 +58,17 @@ describe('validate', () => {
}

try {
assert.equal(error.code, expected.code);
assert.equal(error.message, expected.message);
assert.deepEqual(error.start, expected.start);
assert.deepEqual(error.end, expected.end);
assert.equal(error.pos, expected.pos);
assert.deepEqual(
{
code: error.code,
message: error.message,
start: { line: error.start.line, column: error.start.column },
end: { line: error.end.line, column: error.end.column }
},
expected
);
} catch (e) {
console.error(error); // eslint-disable-line no-console
console.error(error);
throw e;
}
}
Expand All @@ -78,6 +84,51 @@ describe('validate', () => {
}, /options\.name must be a valid identifier/);
});

it('check warning position', () => {
const { warnings } = svelte.compile('\n <img \n src="foo.jpg">\n', {
generate: false
});

assert.deepEqual(
warnings.map((w) => {
return {
code: w.code,
frame: w.frame,
message: w.message,
start: {
character: w.start.character,
column: w.start.column,
line: w.start.line
},
end: {
character: w.end.character,
column: w.end.column,
line: w.end.line
},
pos: w.pos
};
}),
[
{
code: 'a11y-missing-attribute',
frame: '1: \n2: <img \n ^\n3: src="foo.jpg">\n4: ',
message: 'A11y: <img> element should have an alt attribute',
start: {
character: 3,
column: 2,
line: 2
},
end: {
character: 24,
column: 15,
line: 3
},
pos: 3
}
]
);
});

it('warns if options.name is not capitalised', () => {
const { warnings } = svelte.compile('<div></div>', {
name: 'lowercase',
Expand Down
39 changes: 12 additions & 27 deletions test/validator/samples/a11y-alt-text/warnings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,47 @@
"message": "A11y: <img> element should have an alt attribute",
"start": {
"line": 1,
"column": 0,
"character": 0
"column": 0
},
"end": {
"line": 1,
"column": 19,
"character": 19
},
"pos": 0
"column": 19
}
},

{
"code": "a11y-missing-attribute",
"message": "A11y: <area> element should have an alt, aria-label or aria-labelledby attribute",
"start": {
"line": 4,
"column": 1,
"character": 28
"column": 1
},
"end": {
"line": 4,
"column": 7,
"character": 34
},
"pos": 28
"column": 7
}
},

{
"code": "a11y-missing-attribute",
"message": "A11y: <object> element should have a title, aria-label or aria-labelledby attribute",
"start": {
"line": 7,
"column": 0,
"character": 43
"column": 0
},
"end": {
"line": 7,
"column": 17,
"character": 60
},
"pos": 43
"column": 17
}
},

{
"code": "a11y-missing-attribute",
"message": "A11y: <input type=\"image\"> element should have an alt, aria-label or aria-labelledby attribute",
"start": {
"line": 9,
"column": 0,
"character": 62
"column": 0
},
"end": {
"line": 9,
"column": 20,
"character": 82
},
"pos": 62
"column": 20
}
}
]
11 changes: 4 additions & 7 deletions test/validator/samples/a11y-anchor-has-content/warnings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
"message": "A11y: <a> element should have child content",
"start": {
"line": 1,
"column": 0,
"character": 0
"column": 0
},
"end": {
"line": 1,
"column": 19,
"character": 19
},
"pos": 0
}]
"column": 19
}
}]
27 changes: 9 additions & 18 deletions test/validator/samples/a11y-anchor-in-svg-is-valid/warnings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,35 @@
"message": "A11y: <a> element should have an href attribute",
"start": {
"line": 1,
"column": 11,
"character": 11
"column": 11
},
"end": {
"line": 1,
"column": 37,
"character": 37
},
"pos": 11
"column": 37
}
},
{
"code": "a11y-invalid-attribute",
"message": "A11y: '' is not a valid xlink:href attribute",
"start": {
"line": 2,
"column": 14,
"character": 65
"column": 14
},
"end": {
"line": 2,
"column": 27,
"character": 78
},
"pos": 65
"column": 27
}
},
{
"code": "a11y-invalid-attribute",
"message": "A11y: '#' is not a valid xlink:href attribute",
"start": {
"line": 3,
"column": 14,
"character": 130
"column": 14
},
"end": {
"line": 3,
"column": 28,
"character": 144
},
"pos": 130
"column": 28
}
}
]
54 changes: 18 additions & 36 deletions test/validator/samples/a11y-anchor-is-valid/warnings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,89 +4,71 @@
"message": "A11y: <a> element should have an href attribute",
"start": {
"line": 1,
"column": 0,
"character": 0
"column": 0
},
"end": {
"line": 1,
"column": 26,
"character": 26
},
"pos": 0
"column": 26
}
},
{
"code": "a11y-invalid-attribute",
"message": "A11y: '' is not a valid href attribute",
"start": {
"line": 2,
"column": 3,
"character": 30
"column": 3
},
"end": {
"line": 2,
"column": 10,
"character": 37
},
"pos": 30
"column": 10
}
},
{
"code": "a11y-invalid-attribute",
"message": "A11y: '#' is not a valid href attribute",
"start": {
"line": 3,
"column": 3,
"character": 53
"column": 3
},
"end": {
"line": 3,
"column": 11,
"character": 61
},
"pos": 53
"column": 11
}
},
{
"code": "a11y-invalid-attribute",
"message": "A11y: 'javascript:void(0)' is not a valid href attribute",
"start": {
"line": 4,
"column": 3,
"character": 77
"column": 3
},
"end": {
"line": 4,
"column": 28,
"character": 102
},
"pos": 77
"column": 28
}
},
{
"code": "a11y-missing-attribute",
"message": "A11y: <a> element should have an href attribute",
"start": {
"line": 5,
"column": 0,
"character": 115
"column": 0
},
"end": {
"line": 5,
"column": 22,
"character": 137
},
"pos": 115
"column": 22
}
},
{
"code": "a11y-missing-attribute",
"message": "A11y: <a> element should have an href attribute",
"start": {
"line": 6,
"column": 0,
"character": 138
"column": 0
},
"end": {
"line": 6,
"column": 20,
"character": 158
},
"pos": 138
"column": 20
}
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
{
"code": "a11y-aria-activedescendant-has-tabindex",
"end": {
"character": 568,
"column": 36,
"line": 16
},
"message": "A11y: Elements with attribute aria-activedescendant should have tabindex value",
"pos": 537,
"start": {
"character": 537,
"column": 5,
"line": 16
}
Expand Down
Loading