Skip to content

Commit

Permalink
Replace JS toolchain by asset-mapper when testing ux-turbo
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Oct 2, 2024
1 parent 623fe50 commit 1907c84
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 78 deletions.
20 changes: 1 addition & 19 deletions .github/workflows/test-turbo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- run: corepack enable

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand All @@ -81,25 +79,9 @@ jobs:
working-directory: src/Turbo
dependency-versions: ${{ matrix.dependency-version }}

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT

- uses: actions/cache@v4
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install JavaScript dependencies
working-directory: src/Turbo/tests/app
run: touch yarn.lock && yarn install --mode update-lockfile && yarn install

- name: Build JavaScript
working-directory: src/Turbo/tests/app
run: yarn build
run: php public/index.php importmap:install

- name: Create DB
working-directory: src/Turbo/tests/app
Expand Down
5 changes: 2 additions & 3 deletions src/Turbo/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
/composer.lock
/phpunit.xml
/vendor/
/tests/app/var
/tests/app/assets/vendor/
/tests/app/var/
/tests/app/public/build/
node_modules/
package-lock.json
yarn.lock
5 changes: 3 additions & 2 deletions src/Turbo/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@
"doctrine/doctrine-bundle": "^2.4.3",
"doctrine/orm": "^2.8 | 3.0",
"phpstan/phpstan": "^1.10",
"symfony/asset-mapper": "^6.4|^7.0",
"symfony/debug-bundle": "^5.4|^6.0|^7.0",
"symfony/form": "^5.4|^6.0|^7.0",
"symfony/framework-bundle": "^5.4|^6.0|^7.0",
"symfony/framework-bundle": "^6.4|^7.0",
"symfony/mercure-bundle": "^0.3.7",
"symfony/messenger": "^5.4|^6.0|^7.0",
"symfony/panther": "^1.0|^2.0",
"symfony/panther": "^2.1",
"symfony/phpunit-bridge": "^5.4|^6.0|^7.0",
"symfony/process": "^5.4|6.3.*|^7.0",
"symfony/property-access": "^5.4|^6.0|^7.0",
Expand Down
4 changes: 2 additions & 2 deletions src/Turbo/tests/BroadcastTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class BroadcastTest extends PantherTestCase

protected function setUp(): void
{
if (!file_exists(__DIR__.'/app/public/build')) {
throw new \Exception(\sprintf('Move into "%s" and execute Encore before running this test.', realpath(__DIR__.'/app')));
if (!file_exists(__DIR__.'/app/assets/vendor/installed.php')) {
throw new \Exception(\sprintf('Move into "%s" and execute `php public/index.php importmap:install` before running this test.', realpath(__DIR__.'/app')));
}

parent::setUp();
Expand Down
5 changes: 4 additions & 1 deletion src/Turbo/tests/app/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,13 @@ protected function configureContainer(ContainerConfigurator $container): void
{
$container->extension('framework', [
'secret' => 'ChangeMe',
'test' => 'test' === ($_SERVER['APP_ENV'] ?? 'dev'),
'test' => 'test' === $this->environment,
'router' => [
'utf8' => true,
],
'asset_mapper' => [
'paths' => ['assets/']
],
'profiler' => [
'only_exceptions' => false,
],
Expand Down
5 changes: 5 additions & 0 deletions src/Turbo/tests/app/assets/controllers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"controllers": {
},
"entrypoints": []
}
Empty file.
31 changes: 31 additions & 0 deletions src/Turbo/tests/app/importmap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/**
* Returns the importmap for this application.
*
* - "path" is a path inside the asset mapper system. Use the
* "debug:asset-map" command to see the full list of paths.
*
* - "entrypoint" (JavaScript only) set to true for any module that will
* be used as an "entrypoint" (and passed to the importmap() Twig function).
*
* The "importmap:require" command can be used to add new entries to this file.
*/
return [
'app' => [
'path' => './assets/app.js',
'entrypoint' => true,
],
'@hotwired/stimulus' => [
'version' => '3.2.2',
],
'@symfony/stimulus-bundle' => [
'path' => '../../vendor/symfony/stimulus-bundle/assets/dist/loader.js',
],
'@symfony/ux-turbo/dist/turbo_stream_controller' => [
'path' => '../../assets/dist/turbo_stream_controller.js'
],
'@hotwired/turbo' => [
'version' => '7.3.0',
],
];
27 changes: 0 additions & 27 deletions src/Turbo/tests/app/package.json

This file was deleted.

4 changes: 3 additions & 1 deletion src/Turbo/tests/app/templates/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
<meta charset="UTF-8">
<title>Symfony UX Turbo</title>
{% block stylesheets %}{% endblock %}
{{ encore_entry_script_tags('app') }}
{% block javascripts %}
{% block importmap %}{{ importmap('app') }}{% endblock %}
{% endblock %}
</head>
<body>
<nav id="navigation">
Expand Down
23 changes: 0 additions & 23 deletions src/Turbo/tests/app/webpack.config.js

This file was deleted.

0 comments on commit 1907c84

Please sign in to comment.