Skip to content

Commit d552f6a

Browse files
authored
Merge pull request #68 from magento-commerce/imported-loginesta-magento-coding-standard-262
[Imported] AC-1156: Move custom eslint tests to magento-coding-standard repo
2 parents ec62c5c + 71970da commit d552f6a

33 files changed

+3118
-0
lines changed

.github/workflows/php.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ jobs:
2525
name: Tests with PHP ${{ matrix.php-version }} and ${{ matrix.dependencies }} dependencies
2626

2727
steps:
28+
- name: Setup node
29+
uses: actions/setup-node@v2
30+
2831
- uses: actions/checkout@v2
2932

3033
- name: Setup PHP
@@ -34,6 +37,11 @@ jobs:
3437
env:
3538
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3639

40+
- name: Install dependencies
41+
run: npm install
42+
- name: Run ESLint
43+
run: npm run eslint -- eslint/rules
44+
3745
- name: Validate composer
3846
run: composer validate
3947

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/vendor/*
22
/bin/*
3+
/node_modules
34

45
# IDE files
56
.idea/
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento2\Tests\Eslint;
9+
10+
use PHPUnit\Framework\TestCase;
11+
12+
/**
13+
* Abstract class AbstractEslintTestCase
14+
*
15+
* Test Eslint Rules (magento-coding-standard/eslint/rules)
16+
*/
17+
abstract class AbstractEslintTestCase extends TestCase
18+
{
19+
/**
20+
* @param string $testFile
21+
* @param array $expectedMessages
22+
*/
23+
protected function assertFileContainsError(string $testFile, array $expectedMessages): void
24+
{
25+
exec(
26+
'npm run eslint -- Magento2/Tests/Eslint/' . $testFile,
27+
$output
28+
);
29+
30+
foreach ($expectedMessages as $message) {
31+
$this->assertStringContainsString($message, implode(' ',$output));
32+
}
33+
}
34+
}

Magento2/Tests/Eslint/AndSelfTest.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
$(document).ready(function() {
2+
'use strict';
3+
$("div").find("p").andSelf().addClass("border");
4+
});

Magento2/Tests/Eslint/AndSelfTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento2\Tests\Eslint;
9+
10+
/**
11+
* Class AndSelfTest
12+
*
13+
* Test Eslint Rule: jquery-no-andSelf.js
14+
*/
15+
class AndSelfTest extends AbstractEslintTestCase
16+
{
17+
public function testExecute(): void
18+
{
19+
$this->assertFileContainsError(
20+
'AndSelfTest.js',
21+
['jQuery.andSelf() removed, use jQuery.addBack()']
22+
);
23+
}
24+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
$(document).ready(function(){
2+
'use strict';
3+
$(".btn1").bind("click");
4+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento2\Tests\Eslint;
9+
10+
/**
11+
* Class BindUnbindTest
12+
*
13+
* Test Eslint Rule: jquery-no-bind-unbind.js
14+
*/
15+
class BindUnbindTest extends AbstractEslintTestCase
16+
{
17+
public function testExecute(): void
18+
{
19+
$this->assertFileContainsError(
20+
'BindUnbindTest.js',
21+
['jQuery $.bind and $.unbind are deprecated, use $.on and $.off instead']
22+
);
23+
}
24+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
$(document).ready(function(){
2+
'use strict';
3+
$("input").blur();
4+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento2\Tests\Eslint;
9+
10+
/**
11+
* Class ClickEventShorthandTest
12+
*
13+
* Test Eslint Rule: jquery-no-click-event-shorthand.js
14+
*/
15+
class ClickEventShorthandTest extends AbstractEslintTestCase
16+
{
17+
public function testExecute(): void
18+
{
19+
$this->assertFileContainsError(
20+
'ClickEventShorthand.js',
21+
['Instead of .blur(fn) use .on("blur", fn). Instead of .blur() use .trigger("blur")']
22+
);
23+
}
24+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
$(document).ready(function(){
2+
'use strict';
3+
$( "table" ).delegate( "td", "click", function() {
4+
$( this ).toggleClass( "chosen" );
5+
});
6+
});

0 commit comments

Comments
 (0)