-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert validation tests to jest (#1748)
* Convert validation tests to jest * Rename acceptance files * Fix duplicate lockfile dependencies * Fix linters and update script * Fix test errors except for thinking helper files are tests * Stricter Jest test matching pattern * Update CSS tests to return promise * Fix HTML test promises * Use babel-plugin-transform-globals for html-inspector * Fix test filename * Implement mock createRange in test * Clean up unused code * Remove commented code * Fix karma tests by adding back webpack import loader * Fix tests
- Loading branch information
1 parent
2ab7e36
commit 23782fb
Showing
38 changed files
with
862 additions
and
915 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
jest.requireActual('html-inspector/html-inspector'); | ||
export default window.HTMLInspector; |
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 @@ | ||
export default {}; |
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,6 @@ | ||
export function t(key) { | ||
if (key === 'utility.or') { | ||
return ' or '; | ||
} | ||
return ''; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
function createRange() { | ||
// createRange is always called with a Document context | ||
/* eslint-disable no-invalid-this, consistent-this */ | ||
const context = this; | ||
let end; | ||
return { | ||
setEndBefore(el) { | ||
end = el; | ||
}, | ||
|
||
// Finds all text nodes up to the target node, and returns them | ||
// This is used to count newlines for the error reporting | ||
toString() { | ||
let hasFoundNode = false; | ||
const newLines = []; | ||
const iterator = context.createNodeIterator( | ||
context.documentElement, | ||
NodeFilter.SHOW_ALL, | ||
{ | ||
acceptNode(node) { | ||
if (hasFoundNode) { | ||
return NodeFilter.FILTER_REJECT; | ||
} | ||
if (node.isEqualNode(end)) { | ||
hasFoundNode = true; | ||
} | ||
if (node.nodeType === Node.TEXT_NODE) { | ||
newLines.push(node.textContent); | ||
} | ||
return NodeFilter.FILTER_ACCEPT; | ||
}, | ||
}, | ||
); | ||
const nodes = []; | ||
let node; | ||
while ((node = iterator.nextNode())) { | ||
nodes.push(node); | ||
} | ||
return newLines.join(''); | ||
}, | ||
}; | ||
} | ||
global.Document.prototype.createRange = createRange; |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,160 @@ | ||
import css from '../css'; | ||
|
||
import testValidatorAcceptance from './testValidatorAcceptance'; | ||
import validationTest from './validationHelper'; | ||
|
||
describe('css validation', () => { | ||
test('valid flexbox', () => | ||
validationTest( | ||
`.flex-container { | ||
display: flex; | ||
flex-flow: nowrap column; | ||
align-content: flex-end; | ||
justify-content: flex-start; | ||
align-items: center; | ||
} | ||
.flex-item { | ||
flex: 1 0 auto; | ||
align-self: flex-end; | ||
order: 2; | ||
}`, | ||
css, | ||
)); | ||
|
||
test('valid filter', () => | ||
validationTest( | ||
`img { | ||
filter: grayscale(100%); | ||
}`, | ||
css, | ||
)); | ||
|
||
test('valid text-shadow declaration', () => | ||
validationTest( | ||
`p { | ||
text-shadow: rgba(0,0,0,0.1) 0 -5px, rgba(0,0,0,0.1) 0 -1px, \ | ||
rgba(255,255,255,0.1) 1px 0, rgba(255,255,255,0.1) 0 1px, \ | ||
rgba(0,0,0,0.1) -1px -1px, rgba(255,255,255,0.1) 1px 1px; | ||
}`, | ||
css, | ||
)); | ||
|
||
test('valid background-position declarations', () => | ||
validationTest( | ||
`img { | ||
background-position-x: 10px; | ||
background-position-y: 15%; | ||
}`, | ||
css, | ||
)); | ||
|
||
test('bogus flex value', () => | ||
validationTest('.flex-item { flex: bogus; }', css, { | ||
reason: 'invalid-value', | ||
row: 0, | ||
payload: {error: 'bogus'}, | ||
})); | ||
|
||
test('fails with bogus filter value', () => | ||
validationTest('img { filter: whitescale(100%); }', css, { | ||
reason: 'invalid-value', | ||
row: 0, | ||
payload: {error: 'whitescale('}, | ||
})); | ||
|
||
test('no opening curly brace', () => | ||
validationTest( | ||
`p | ||
display: block;`, | ||
css, | ||
{reason: 'block-expected', row: 0, payload: {error: 'p'}}, | ||
)); | ||
|
||
test('no closing curly brace', () => | ||
validationTest( | ||
`p { | ||
display: block;`, | ||
css, | ||
{reason: 'missing-closing-curly', row: 0}, | ||
)); | ||
|
||
test('bogus character in selector', () => | ||
validationTest('p; div { display: block; }', css, { | ||
reason: 'invalid-token-in-selector', | ||
row: 0, | ||
payload: {token: ';'}, | ||
})); | ||
|
||
test('invalid negative value', () => | ||
validationTest('p { padding-left: -2px; }', css, { | ||
reason: 'invalid-negative-value', | ||
row: 0, | ||
payload: {error: '-2px'}, | ||
})); | ||
|
||
test('invalid fractional value', () => | ||
validationTest('p { z-index: 2.4; }', css, { | ||
reason: 'invalid-fractional-value', | ||
row: 0, | ||
payload: {error: '2.4'}, | ||
})); | ||
|
||
test('missing semicolon at end of block', () => | ||
validationTest( | ||
`p { | ||
display: block | ||
}`, | ||
css, | ||
{reason: 'missing-semicolon', row: 1}, | ||
)); | ||
|
||
test('missing semicolon within block', () => | ||
validationTest( | ||
` | ||
p { | ||
margin: 10px | ||
padding: 5px; | ||
} | ||
`, | ||
css, | ||
{reason: 'missing-semicolon', row: 2}, | ||
)); | ||
|
||
test('extra tokens after value', () => | ||
validationTest( | ||
` | ||
p { | ||
padding: 5px 5px 5px 5px 5px; | ||
} | ||
`, | ||
css, | ||
{reason: 'extra-tokens-after-value', row: 2, payload: {token: '5px'}}, | ||
)); | ||
|
||
test('potentially missing semicolon before first line', () => | ||
validationTest( | ||
`button{border:20px solid b; | ||
}`, | ||
css, | ||
{reason: 'extra-tokens-after-value', row: 0, payload: {token: 'b'}}, | ||
)); | ||
|
||
test('extra token that is prefix of the beginning of the line', () => | ||
validationTest( | ||
` | ||
p { | ||
border: 20px solid b; | ||
} | ||
`, | ||
css, | ||
{reason: 'extra-tokens-after-value', row: 2, payload: {token: 'b'}}, | ||
)); | ||
|
||
test('thoroughly unparseable CSS', () => | ||
validationTest('<a href="http;.facebook.com>', css, { | ||
reason: 'invalid-token', | ||
row: 0, | ||
})); | ||
|
||
testValidatorAcceptance(css, 'css'); | ||
}); |
Oops, something went wrong.