Skip to content
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

Lint test files #3782

Merged
merged 1 commit into from
Jun 1, 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
43 changes: 27 additions & 16 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,45 @@
{
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
},
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
"env": {
"browser": true,
"commonjs": true,
"es6": true
},
"plugins": ["prettier", "@typescript-eslint"],
"parser": "@typescript-eslint/parser",
"settings": {
"import/resolver": {
"webpack": {
"config": "_develop/webpack.config.js"
}
}
},
"ignorePatterns": ["**/*.d.ts", "**/*.js", "website/**/*"],
"ignorePatterns": [
"website/**/*",
"*.js",
"!test/helpers/**/*.js",
"!test/unit/**/*.js"
],
"rules": {
"arrow-parens": ["error", "as-needed"],
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"no-use-before-define": ["error", { "functions": false, "classes": false }],
"prettier/prettier": "error"
}
},
"overrides": [
{
"files": ["test/helpers/**/*.js", "test/unit/**/*.js"],
"plugins": ["prettier"]
},
{
"files": ["**/*.ts"],
"extends": ["plugin:@typescript-eslint/recommended"],
"excludedFiles": "*.d.ts",
"plugins": ["prettier", "@typescript-eslint"],
"rules": {
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-explicit-any": "off"
}
}
]
}
263 changes: 159 additions & 104 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"@playwright/test": "^1.27.1",
"@types/jasmine": "^4.3.0",
"@types/lodash.clonedeep": "^4.5.7",
"@typescript-eslint/eslint-plugin": "^5.38.0",
"@typescript-eslint/parser": "^5.38.0",
"@typescript-eslint/eslint-plugin": "^5.59.8",
"@typescript-eslint/parser": "^5.59.8",
"babel-loader": "^8.2.5",
"babel-plugin-istanbul": "^6.1.1",
"css-loader": "^6.7.1",
Expand Down
16 changes: 7 additions & 9 deletions test/helpers/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const div = document.createElement('div');
div.id = 'test-container';
document.body.appendChild(div);

window.onerror = function(msg) {
window.onerror = function (msg) {
return msg === 'Script error.';
};

beforeEach(function() {
beforeEach(function () {
jasmine.addMatchers({
toEqualHTML() {
return { compare: compareHTML };
Expand All @@ -37,7 +37,7 @@ function compareApproximately(actual, expected, tolerance) {
}

function compareHTML(actual, expected, ignoreClassId, ignoreUI = true) {
const [div1, div2] = [actual, expected].map(function(html) {
const [div1, div2] = [actual, expected].map(function (html) {
if (html instanceof HTMLElement) {
html = html.innerHTML;
}
Expand Down Expand Up @@ -79,8 +79,8 @@ function compareNodes(node1, node2, ignoredAttributes = []) {
if (node1.tagName !== node2.tagName) {
return `Expected tagName '${node1.tagName}' to equal '${node2.tagName}'`;
}
const [attr1, attr2] = [node1, node2].map(function(node) {
return Array.from(node.attributes || []).reduce(function(attr, elem) {
const [attr1, attr2] = [node1, node2].map(function (node) {
return Array.from(node.attributes || []).reduce(function (attr, elem) {
if (ignoredAttributes.indexOf(elem.name) < 0) {
attr[elem.name] =
elem.name === 'style' ? elem.value.trim() : elem.value;
Expand All @@ -94,14 +94,12 @@ function compareNodes(node1, node2, ignoredAttributes = []) {
)}`;
}
if (node1.childNodes.length !== node2.childNodes.length) {
return `Expected node childNodes length '${
node1.childNodes.length
}' to equal '${node2.childNodes.length}'`;
return `Expected node childNodes length '${node1.childNodes.length}' to equal '${node2.childNodes.length}'`;
}
if (node1.childNodes.length === 0) return null;
let message = '';
if (
Array.from(node1.childNodes).some(function(child1, i) {
Array.from(node1.childNodes).some(function (child1, i) {
message = compareNodes(child1, node2.childNodes[i], ignoredAttributes);
return message;
})
Expand Down
26 changes: 13 additions & 13 deletions test/unit/blots/block-embed.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Scroll from '../../../blots/scroll';

describe('Block Embed', function() {
it('insert', function() {
describe('Block Embed', function () {
it('insert', function () {
const scroll = this.initialize(Scroll, '<p>0123</p>');
scroll.insertAt(2, 'video', '#');
expect(scroll.domNode).toEqualHTML(`
Expand All @@ -11,7 +11,7 @@ describe('Block Embed', function() {
`);
});

it('split newline', function() {
it('split newline', function () {
const scroll = this.initialize(Scroll, '<p>0123</p>');
scroll.insertAt(4, 'video', '#');
expect(scroll.domNode).toEqualHTML(`
Expand All @@ -21,7 +21,7 @@ describe('Block Embed', function() {
`);
});

it('insert end of document', function() {
it('insert end of document', function () {
const scroll = this.initialize(Scroll, '<p>0123</p>');
scroll.insertAt(5, 'video', '#');
expect(scroll.domNode).toEqualHTML(`
Expand All @@ -30,7 +30,7 @@ describe('Block Embed', function() {
`);
});

it('insert text before', function() {
it('insert text before', function () {
const scroll = this.initialize(
Scroll,
'<iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>',
Expand All @@ -42,7 +42,7 @@ describe('Block Embed', function() {
`);
});

it('insert text after', function() {
it('insert text after', function () {
const scroll = this.initialize(
Scroll,
'<iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>',
Expand All @@ -54,7 +54,7 @@ describe('Block Embed', function() {
`);
});

it('insert inline embed before', function() {
it('insert inline embed before', function () {
const scroll = this.initialize(
Scroll,
'<iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>',
Expand All @@ -66,7 +66,7 @@ describe('Block Embed', function() {
`);
});

it('insert inline embed after', function() {
it('insert inline embed after', function () {
const scroll = this.initialize(
Scroll,
'<iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>',
Expand All @@ -78,7 +78,7 @@ describe('Block Embed', function() {
`);
});

it('insert block embed before', function() {
it('insert block embed before', function () {
const scroll = this.initialize(
Scroll,
'<iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>',
Expand All @@ -90,7 +90,7 @@ describe('Block Embed', function() {
`);
});

it('insert block embed after', function() {
it('insert block embed after', function () {
const scroll = this.initialize(
Scroll,
'<iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>',
Expand All @@ -102,7 +102,7 @@ describe('Block Embed', function() {
`);
});

it('insert newline before', function() {
it('insert newline before', function () {
const scroll = this.initialize(
Scroll,
'<iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>',
Expand All @@ -115,7 +115,7 @@ describe('Block Embed', function() {
`);
});

it('insert newline after', function() {
it('insert newline after', function () {
const scroll = this.initialize(
Scroll,
'<iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>',
Expand All @@ -128,7 +128,7 @@ describe('Block Embed', function() {
`);
});

it('delete preceding newline', function() {
it('delete preceding newline', function () {
const scroll = this.initialize(
Scroll,
'<p>0123</p><iframe src="#" class="ql-video" frameborder="0" allowfullscreen="true"></iframe>',
Expand Down
26 changes: 13 additions & 13 deletions test/unit/blots/block.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import Scroll from '../../../blots/scroll';

describe('Block', function() {
it('childless', function() {
describe('Block', function () {
it('childless', function () {
const scroll = this.initialize(Scroll, '');
const block = scroll.create('block');
block.optimize();
expect(block.domNode).toEqualHTML('<br>');
});

it('insert into empty', function() {
it('insert into empty', function () {
const scroll = this.initialize(Scroll, '');
const block = scroll.create('block');
block.insertAt(0, 'Test');
expect(block.domNode).toEqualHTML('Test');
});

it('insert newlines', function() {
it('insert newlines', function () {
const scroll = this.initialize(Scroll, '<p><br></p>');
scroll.insertAt(0, '\n\n\n');
expect(scroll.domNode).toEqualHTML(
'<p><br></p><p><br></p><p><br></p><p><br></p>',
);
});

it('insert multiline', function() {
it('insert multiline', function () {
const scroll = this.initialize(Scroll, '<p>Hello World!</p>');
scroll.insertAt(6, 'pardon\nthis\n\ninterruption\n');
expect(scroll.domNode).toEqualHTML(`
Expand All @@ -35,26 +35,26 @@ describe('Block', function() {
`);
});

it('insert into formatted', function() {
it('insert into formatted', function () {
const scroll = this.initialize(Scroll, '<h1>Welcome</h1>');
scroll.insertAt(3, 'l\n');
expect(scroll.domNode.firstChild.outerHTML).toEqualHTML('<h1>Well</h1>');
expect(scroll.domNode.childNodes[1].outerHTML).toEqualHTML('<h1>come</h1>');
});

it('delete line contents', function() {
it('delete line contents', function () {
const scroll = this.initialize(Scroll, '<p>Hello</p><p>World!</p>');
scroll.deleteAt(0, 5);
expect(scroll.domNode).toEqualHTML('<p><br></p><p>World!</p>');
});

it('join lines', function() {
it('join lines', function () {
const scroll = this.initialize(Scroll, '<h1>Hello</h1><h2>World!</h2>');
scroll.deleteAt(5, 1);
expect(scroll.domNode).toEqualHTML('<h2>HelloWorld!</h2>');
});

it('join line with empty', function() {
it('join line with empty', function () {
const scroll = this.initialize(
Scroll,
'<p>Hello<strong>World</strong></p><p><br></p>',
Expand All @@ -63,25 +63,25 @@ describe('Block', function() {
expect(scroll.domNode).toEqualHTML('<p>Hello<strong>World</strong></p>');
});

it('join empty lines', function() {
it('join empty lines', function () {
const scroll = this.initialize(Scroll, '<h1><br></h1><p><br></p>');
scroll.deleteAt(1, 1);
expect(scroll.domNode).toEqualHTML('<h1><br></h1>');
});

it('format empty', function() {
it('format empty', function () {
const scroll = this.initialize(Scroll, '<p><br></p>');
scroll.formatAt(0, 1, 'header', 1);
expect(scroll.domNode).toEqualHTML('<h1><br></h1>');
});

it('format newline', function() {
it('format newline', function () {
const scroll = this.initialize(Scroll, '<h1>Hello</h1>');
scroll.formatAt(5, 1, 'header', 2);
expect(scroll.domNode).toEqualHTML('<h2>Hello</h2>');
});

it('remove unnecessary break', function() {
it('remove unnecessary break', function () {
const scroll = this.initialize(Scroll, '<p>Test</p>');
scroll.children.head.domNode.appendChild(document.createElement('br'));
scroll.update();
Expand Down
8 changes: 4 additions & 4 deletions test/unit/blots/inline.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Scroll from '../../../blots/scroll';

describe('Inline', function() {
it('format order', function() {
describe('Inline', function () {
it('format order', function () {
const scroll = this.initialize(Scroll, '<p>Hello World!</p>');
scroll.formatAt(0, 1, 'bold', true);
scroll.formatAt(0, 1, 'italic', true);
Expand All @@ -12,11 +12,11 @@ describe('Inline', function() {
);
});

it('reorder', function() {
it('reorder', function () {
const scroll = this.initialize(Scroll, '<p>0<strong>12</strong>3</p>');
const p = scroll.domNode.firstChild;
const em = document.createElement('em');
Array.from(p.childNodes).forEach(function(node) {
Array.from(p.childNodes).forEach(function (node) {
em.appendChild(node);
});
p.appendChild(em);
Expand Down
Loading