fix(tests): add validation of comment translations (#41537)

This commit is contained in:
Oliver Eyton-Williams
2021-03-20 07:29:13 +01:00
committed by GitHub
parent 654d66186e
commit 0d3158d4f4
12 changed files with 345 additions and 527 deletions

View File

@ -0,0 +1,77 @@
/* global expect */
const extractScriptJSComments = require('./extract-script-js-comments');
const inlineComments = `<body>
Some text
<script>
// comment 1
var x = 'y';
// comment 2
// comment 1
</script>
</body>
`;
const multilineComments = `<body>
Some text
<script>
/*
comment 1
*/
var x = 'y';
/* comment 2 */
/* comment 1 */
</script>
</body>
`;
const outsideScript = `<body>
Some text
<script>
// comment 1
var x = 'y';
// comment 2
// comment 1
</script>
// comment 2
</body>
`;
describe('extractScriptJSComments', () => {
it('should catch inline comments', () => {
const commentCounts = {
'comment 1': 2,
'comment 2': 1
};
expect(extractScriptJSComments(inlineComments)).toEqual(commentCounts);
});
it('should catch multiline comments', () => {
const commentCounts = {
'comment 1': 2,
'comment 2': 1
};
expect(extractScriptJSComments(multilineComments)).toEqual(commentCounts);
});
it('should ignore comments outside script tags', () => {
const commentCounts = {
'comment 1': 2,
'comment 2': 1
};
expect(extractScriptJSComments(outsideScript)).toEqual(commentCounts);
});
});