Skip to content

Commit

Permalink
Add frontend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jordisala1991 committed May 7, 2023
1 parent b1929d2 commit 1d2aa82
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/projects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ form-extensions:
2.x:
php: ['8.0', '8.1', '8.2']
frontend: true
frontend_tests: true
variants:
symfony/symfony: ['5.4.*', '6.2.*']
1.x:
Expand Down
4 changes: 4 additions & 0 deletions src/Command/Dispatcher/DispatchBranchesProtectionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ private function buildRequiredStatusChecks(Project $project, Branch $branch): ar

if ($branch->hasFrontend()) {
$requiredStatusChecks[] = 'Webpack Encore';

if ($branch->hasFrontendTests()) {
$requiredStatusChecks[] = 'Vitest';
}
}

if ($project->hasTestKernel()) {
Expand Down
1 change: 1 addition & 0 deletions src/Config/ProjectsConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function getConfigTreeBuilder(): TreeBuilder
->arrayNode('php_extensions')->prototype('scalar')->defaultValue([])->end()->end()
->scalarNode('target_php')->defaultNull()->end()
->scalarNode('frontend')->defaultFalse()->end()
->scalarNode('frontend_tests')->defaultFalse()->end()
->arrayNode('variants')
->normalizeKeys(false)
->useAttributeAsKey('name')
Expand Down
10 changes: 10 additions & 0 deletions src/Domain/Value/Branch.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* variants: array<string, array<string>>,
* target_php: string|null,
* frontend: bool,
* frontend_tests: bool,
* docs_path: string,
* tests_path: string,
* }
Expand All @@ -46,6 +47,7 @@ final class Branch
private array $variants;

private bool $frontend;
private bool $frontendTests;
private Path $docsPath;
private Path $testsPath;
private PhpVersion $targetPhpVersion;
Expand All @@ -61,6 +63,7 @@ private function __construct(
array $phpExtensions,
array $variants,
bool $frontend,
bool $frontendTests,
Path $docsPath,
Path $testsPath,
?PhpVersion $targetPhpVersion
Expand All @@ -70,6 +73,7 @@ private function __construct(
$this->phpExtensions = $phpExtensions;
$this->variants = $variants;
$this->frontend = $frontend;
$this->frontendTests = $frontendTests;
$this->docsPath = $docsPath;
$this->testsPath = $testsPath;
$this->targetPhpVersion = $targetPhpVersion ?? end($this->phpVersions);
Expand Down Expand Up @@ -110,6 +114,7 @@ public static function fromValues(string $name, array $config): self
$phpExtensions,
$variants,
$config['frontend'],
$config['frontend_tests'],
Path::fromString($config['docs_path']),
Path::fromString($config['tests_path']),
$targetPhpVersion
Expand Down Expand Up @@ -178,6 +183,11 @@ public function hasFrontend(): bool
return $this->frontend;
}

public function hasFrontendTests(): bool
{
return $this->frontendTests;
}

public function docsPath(): Path
{
return $this->docsPath;
Expand Down
1 change: 1 addition & 0 deletions templates/project/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ module.exports = {
],
2,
],
'import/no-webpack-loader-syntax': 'off',
},
};
25 changes: 25 additions & 0 deletions templates/project/.github/workflows/frontend.yaml.twig
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,28 @@ jobs:

- name: Check if the compilation is up to date
run: git diff --no-patch --exit-code
{% if branch.hasFrontendTests %}

tests:
name: Vitest

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Node
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Install NPM dependencies
uses: bahmutov/npm-install@v1

- name: Run Vitest
run: npx vitest run --coverage

- name: Send coverage to Codecov
uses: codecov/codecov-action@v3
{% endif %}
2 changes: 2 additions & 0 deletions tests/Command/Dispatcher/DispatchFilesCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public function projectProvider(): iterable
php: ['7.3', '7.4']
target_php: ~
frontend: true
frontend_tests: true
variants:
symfony/symfony: ['4.4.*']
sonata-project/block-bundle: ['4.*']
Expand All @@ -96,6 +97,7 @@ public function projectProvider(): iterable
php: ['7.2', '7.3', '7.4']
target_php: ~
frontend: false
frontend_tests: false
variants:
symfony/symfony: ['4.4.*']
sonata-project/block-bundle: ['3.*']
Expand Down
1 change: 1 addition & 0 deletions tests/Domain/Value/BranchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ final class BranchTest extends TestCase
php: ['7.3', '7.4', '8.0']
target_php: '7.4'
frontend: true
frontend_tests: true
variants:
symfony/symfony: ['4.4']
sonata-project/block-bundle: ['4']
Expand Down
12 changes: 12 additions & 0 deletions tests/Domain/Value/ProjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ final class ProjectTest extends TestCase
php: ['7.3', '7.4']
target_php: ~
frontend: true
frontend_tests: true
variants:
symfony/symfony: ['4.4']
sonata-project/block-bundle: ['4']
Expand All @@ -44,6 +45,7 @@ final class ProjectTest extends TestCase
php: ['7.2', '7.3', '7.4']
target_php: ~
frontend: false
frontend_tests: false
variants:
symfony/symfony: ['4.4']
sonata-project/block-bundle: ['3']
Expand Down Expand Up @@ -134,6 +136,7 @@ public function isBundleProvider(): iterable
php: ['7.3', '7.4']
target_php: ~
frontend: true
frontend_tests: true
variants:
symfony/symfony: ['4.4']
sonata-project/block-bundle: ['4']
Expand All @@ -158,6 +161,7 @@ public function isBundleProvider(): iterable
php: ['7.3', '7.4']
target_php: ~
frontend: true
frontend_tests: true
variants:
symfony/symfony: ['4.4']
sonata-project/block-bundle: ['4']
Expand Down Expand Up @@ -446,6 +450,7 @@ public function documentationBadgeSlugProvider(): iterable
php: ['7.3', '7.4']
target_php: ~
frontend: true
frontend_tests: true
variants:
symfony/symfony: ['4.4']
sonata-project/block-bundle: ['4']
Expand All @@ -469,6 +474,7 @@ public function documentationBadgeSlugProvider(): iterable
php: ['7.3', '7.4']
target_php: ~
frontend: true
frontend_tests: true
variants:
symfony/symfony: ['4.4']
sonata-project/block-bundle: ['4']
Expand Down Expand Up @@ -523,6 +529,7 @@ public function defaultBranchProvider(): iterable
php: ['7.3', '7.4']
target_php: ~
frontend: true
frontend_tests: true
variants:
symfony/symfony: ['4.4']
sonata-project/block-bundle: ['4']
Expand All @@ -546,6 +553,7 @@ public function defaultBranchProvider(): iterable
php: ['7.3', '7.4']
target_php: ~
frontend: true
frontend_tests: true
variants:
symfony/symfony: ['4.4']
sonata-project/block-bundle: ['4']
Expand All @@ -556,6 +564,7 @@ public function defaultBranchProvider(): iterable
php: ['7.3', '7.4']
target_php: ~
frontend: true
frontend_tests: true
variants:
symfony/symfony: ['4.4']
sonata-project/block-bundle: ['4']
Expand All @@ -579,6 +588,7 @@ public function defaultBranchProvider(): iterable
php: ['7.3', '7.4']
target_php: ~
frontend: true
frontend_tests: true
variants:
symfony/symfony: ['4.4']
sonata-project/block-bundle: ['4']
Expand All @@ -589,6 +599,7 @@ public function defaultBranchProvider(): iterable
php: ['7.3', '7.4']
target_php: ~
frontend: true
frontend_tests: true
variants:
symfony/symfony: ['4.4']
sonata-project/block-bundle: ['4']
Expand All @@ -599,6 +610,7 @@ public function defaultBranchProvider(): iterable
php: ['7.3', '7.4']
target_php: ~
frontend: true
frontend_tests: true
variants:
symfony/symfony: ['4.4']
sonata-project/block-bundle: ['4']
Expand Down
2 changes: 2 additions & 0 deletions tests/Github/Domain/Value/Search/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function testPullRequests(): void
php: ['7.3', '7.4']
target_php: ~
frontend: true
frontend_tests: true
variants:
symfony/symfony: ['4.4']
sonata-project/block-bundle: ['4']
Expand Down Expand Up @@ -111,6 +112,7 @@ public function testPullRequestsSince(): void
php: ['7.3', '7.4']
target_php: ~
frontend: true
frontend_tests: true
variants:
symfony/symfony: ['4.4']
sonata-project/block-bundle: ['4']
Expand Down

0 comments on commit 1d2aa82

Please sign in to comment.