14 Commits
ci-pr ... main

Author SHA1 Message Date
Hugo Alliaume
2dd8302c75 2.1.0 2025-07-05 13:38:16 +02:00
Hugo Alliaume
17420a4b7c feature #10 Deprecate the package (Kocal)
This PR was merged into the main branch.

Discussion
----------

Deprecate the package

I don't think there is any interest in _maintaining_ it anymore. Because of Jest and Babel, installing ``@symfony`/stimulus-testing` installs [**~500 subdependencies**](https://npmgraph.js.org/?q=%40symfony%2Fstimulus-testing), which is totally unacceptable, since the added-value of this package is only these two functions:
```js
export function mountDOM(html = '') {
    const div = document.createElement('div');
    div.innerHTML = html;
    document.body.appendChild(div);

    return div;
}

export function clearDOM() {
    document.body.innerHTML = '';
}
```

It's like a Composer package, but all its dependencies being shadowed and not removable by the final user.

Removing it from `@symfony`/ux, where we don't use Jest and Babel but Vitest, allowed us to remove ~400 useless Node.js dev dependencies: https://github.com/symfony/ux/pull/2879

The package is still experimental, and I suggest to deprecate this package. I've added migration steps for people being stuck with it, even if I think we, Symfony, are maybe the only ones to use it:

https://github.com/user-attachments/assets/86a21c37-8560-43dc-bec9-0043875831ea

We can observe:
1. it always had ~1k downloads per week this last year,
2. more recently we had ~21k downloads per week, and I believe that's correlated to my last two-months work on UX
3. and since a few days, it started to drop again (currently at 8k downloads for the last full week), when I removed it from UX

Commits
-------

07d2209 Deprecate the package
2025-07-05 13:36:56 +02:00
Hugo Alliaume
07d2209dd5 Deprecate the package 2025-07-02 18:08:01 +02:00
Ryan Weaver
7194dc04c9 minor #8 fix readme import name (a.baron)
This PR was merged into the main branch.

Discussion
----------

fix readme import name

This merge request is created after this conversation : https://github.com/symfony/stimulus-testing/issues/6

Commits
-------

9588a2b fix readme import name
2023-10-03 12:02:58 -04:00
Ryan Weaver
25bca2c62e minor #9 fix readme babel preset env (a.baron)
This PR was merged into the main branch.

Discussion
----------

fix readme babel preset env

This merge request is created after this conversation : https://github.com/symfony/stimulus-testing/issues/7

Commits
-------

0438da3 fix readme babel preset env
2023-10-03 12:02:37 -04:00
a.baron
0438da3771 fix readme babel preset env 2023-10-03 11:40:54 +02:00
a.baron
9588a2bde0 fix readme import name 2023-10-03 11:36:29 +02:00
Titouan Galopin
edd246b564 Tagging 2.0.1 2021-12-09 15:50:35 +01:00
Titouan Galopin
cc5151bde1 bug #5 Fix usage of 2.0 with Jest (tgalopin)
This PR was merged into the main branch.

Discussion
----------

Fix usage of 2.0 with Jest

Commits
-------

b79342d Fix usage of 2.0 with Jest
2021-12-09 15:50:10 +01:00
Titouan Galopin
b79342d6c4 Fix usage of 2.0 with Jest 2021-12-09 15:49:32 +01:00
Titouan Galopin
78f5aef61c Tagging 2.0.0 2021-12-09 15:26:57 +01:00
Titouan Galopin
40c5c8bcbf minor #4 Removing dist/ & testing against Stimulus 3 (weaverryan)
This PR was squashed before being merged into the main branch.

Discussion
----------

Removing dist/ & testing against Stimulus 3

Hi!

This was mainly motivated to add support for Stimulus 3... but I think the library already supports it just fine, as this library never actually *imports* Stimulus itself (other than in a test file).

So, this PR includes a number of other "chores" that we should handle:

* The `dist/` directory is not needed, because this is used purely as a node package. Babel IS still there, because it's used by jest to transform the test controller file.
* The `src/setup.js` file was missing (there was a `dist/setup.js` file but the original source file was missing - but easily reproduceable).
* We're now testing against Stimulus 3.

Commits
-------

3c7697a Removing dist/ & testing against Stimulus 3
2021-11-24 22:09:39 +01:00
Ryan Weaver
3c7697ace8 Removing dist/ & testing against Stimulus 3 2021-11-24 22:08:55 +01:00
Titouan Galopin
12edab3d80 Merge pull request #3 from symfony/ci-pr
Enable CI on pull requests
2020-12-05 11:30:50 +01:00
9 changed files with 63 additions and 63 deletions

View File

@@ -1,4 +1,3 @@
{
"presets": ["@babel/env"],
"plugins": ["@babel/plugin-proposal-class-properties"]
"presets": ["@babel/env"]
}

View File

@@ -9,8 +9,8 @@ jobs:
- uses: actions/checkout@master
- name: Prettier
run: |
yarn global add prettier@^2.2.0
~/.yarn/bin/prettier --check src/**/*.js --config .prettierrc.json
yarn add prettier@^2.2.0
yarn run prettier --check {src,test}/**/*.js --config .prettierrc.json
tests:
runs-on: ubuntu-latest

View File

@@ -1,11 +1,51 @@
# Symfony UX Stimulus testing
> [!WARNING]
> **Deprecated**: This package is deprecated and will not receive any further updates.
Because this package only provides very small helpers to help write tests for Stimulus controllers, and is tightly coupled with [Jest](https://jestjs.io/), [jsdom](https://github.com/jsdom/jsdom) and [Testing Library](https://testing-library.com/) dependencies, we can no longer recommend it.
In 2025, we cannot force developers to install Jest (and [~270 sub-dependencies](https://npmgraph.js.org/?q=jest) including [Babel](https://babeljs.io/)) and the like, since [many test runners exist](https://npmtrends.com/ava-vs-japa-vs-jasmine-vs-jest-vs-karma-vs-mocha-vs-tap-vs-vitest), and many of them are more modern and much faster, like [Vitest](https://vitest.dev/).
We want to give you the choice to use the best tools for your needs, and not force you to use what we suggested in the past.
To migrate from `@symfony/stimulus-testing`, you can follow these steps:
1. Install the dev dependencies `@testing-library/jest-dom @testing-library/dom`;
you may also want to install `mutationobserver-shim regenerator-runtime` if you still have
legacy code or _architecture_.
2. In the file `assets/test/setup.js`, replace imports:
```diff
-import '@symfony/stimulus-testing/setup';
+import '@testing-library/jest-dom';
```
3. Create the file `assets/test/stimulus-helpers.js` with the following content:
```js
export function mountDOM(html = '') {
const div = document.createElement('div');
div.innerHTML = html;
document.body.appendChild(div);
return div;
}
export function clearDOM() {
document.body.innerHTML = '';
}
```
4. In your tests files, replace imports for `mountDOM` and `clearDOM`:
```diff
// assets/test/controllers/hello_controller.test.js
-import { clearDOM, mountDOM } from '@symfony/stimulus-testing';
+import { clearDOM, mountDOM } from '../stimulus-helpers';
```
5. And finally, remove the `@symfony/stimulus-testing` dependency from your project.
---
Symfony UX Stimulus testing is a low-level package to help write tests for Stimulus controllers
in applications and reusable packages.
**If you are developing a project with Symfony Flex, you should probably use the ux-test-pack
instead**. The pack includes this package and configures it automatically in your application.
Symfony UX Stimulus testing is currently considered **experimental**.
## Installation
@@ -31,7 +71,7 @@ To start using Symfony UX Testing, you first need to configure a testing environ
2. Create a `assets/test/setup.js` file to initialize Symfony UX Testing:
```js
import '@symfony/ux-testing/setup';
import '@symfony/stimulus-testing/setup';
```
3. Create a `assets/jest.config.js` file for Jest configuration:
@@ -48,14 +88,15 @@ module.exports = {
```json
{
"presets": ["@babel/env"],
"presets": ["@babel/preset-env"],
"plugins": ["@babel/plugin-proposal-class-properties"]
}
```
5. Finally, create your first test, for instance `hello_controller.test.js`:
```js
import { Application } from 'stimulus';
import { Application } from '@hotwired/stimulus';
import { clearDOM, mountDOM } from '@symfony/stimulus-testing';
import HelloController from '../controllers/hello_controller.js';

30
dist/index.js vendored
View File

@@ -1,30 +0,0 @@
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.mountDOM = exports.clearDOM = void 0;
var mountDOM = function mountDOM() {
var htmlString = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
var div = document.createElement('div');
div.innerHTML = htmlString;
document.body.appendChild(div);
return div;
};
exports.mountDOM = mountDOM;
var clearDOM = function clearDOM() {
document.body.innerHTML = '';
};
exports.clearDOM = clearDOM;

View File

@@ -1,19 +1,15 @@
{
"name": "@symfony/stimulus-testing",
"description": "@testing-library integration for Symfony UX",
"version": "1.1.0",
"main": "dist/index.js",
"version": "2.1.0",
"main": "src/index.js",
"license": "MIT",
"author": "Titouan Galopin <galopintitouan@gmail.com>",
"engines": {
"node": "^10.13.0 || >=12.0.0"
},
"scripts": {
"build": "babel src -d dist",
"test": "babel src -d dist && jest"
},
"peerDependencies": {
"stimulus": "^2.0"
"test": "jest"
},
"dependencies": {
"@testing-library/dom": "^7.28.1",
@@ -25,11 +21,9 @@
"regenerator-runtime": "^0.13.7"
},
"devDependencies": {
"@babel/cli": "^7.12.1",
"@babel/core": "^7.12.3",
"@babel/plugin-proposal-class-properties": "^7.12.1",
"@babel/preset-env": "^7.12.7",
"stimulus": "^2.0.0"
"@hotwired/stimulus": "^3.0.0"
},
"jest": {
"testRegex": "test/.*\\.test.js",
@@ -39,7 +33,6 @@
},
"files": [
"src/",
"dist/",
"setup.js"
]
}

View File

@@ -1 +1 @@
require('./dist/setup.js');
require('./src/setup.js');

View File

@@ -9,7 +9,7 @@
'use strict';
const mountDOM = (htmlString = '') => {
module.exports.mountDOM = (htmlString = '') => {
const div = document.createElement('div');
div.innerHTML = htmlString;
document.body.appendChild(div);
@@ -17,8 +17,6 @@ const mountDOM = (htmlString = '') => {
return div;
};
const clearDOM = () => {
module.exports.clearDOM = () => {
document.body.innerHTML = '';
};
export { clearDOM, mountDOM };

View File

@@ -6,10 +6,9 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
'use strict';
require("mutationobserver-shim");
require("regenerator-runtime/runtime.js");
require("@testing-library/jest-dom");
require('mutationobserver-shim');
require('regenerator-runtime/runtime.js');
require('@testing-library/jest-dom');

View File

@@ -9,9 +9,9 @@
'use strict';
import { Application, Controller } from 'stimulus';
import { Application, Controller } from '@hotwired/stimulus';
import { getByTestId, waitFor } from '@testing-library/dom';
import { clearDOM, mountDOM } from '../dist/index';
import { clearDOM, mountDOM } from '../src/index';
// Controller used to check the actual controller was properly booted
class AppController extends Controller {