vite-plugin-testem 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/README.md +15 -1
- package/index.js +44 -1
- package/package.json +6 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [1.0.2] - 2026-10-07
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Optional `testem` peer range is now `^3.20.0 || ^4.0.0-beta.1`. `^4.0.0` does not match `4.0.0-beta.1`.
|
|
15
|
+
- Node.js engines are `^20.19.0 || ^22.12.0 || ^24.0.0 || >=26.0.0`. Node 25 is not supported.
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- **`createTestemViteMiddleware`:** Transform `*.html` with Vite so `vitePluginTestem` injection runs in middleware mode. `appType` stays `custom`, so paths Vite does not serve still fall through to Testem.
|
|
20
|
+
|
|
21
|
+
## [1.0.1] - 2026-04-19
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- **`createTestemViteMiddleware`:** Strip Testem’s per-browser URL prefix (`/<sessionId>/…`) before forwarding to Vite so the runner page and assets resolve correctly when Testem opens `/:id/tests_run.html` (fixes “testem.js not loaded” / connection timeout in CI).
|
|
26
|
+
|
|
27
|
+
## [1.0.0] - 2026-04-19
|
|
28
|
+
|
|
29
|
+
First stable release: Vite plugin and Testem middleware helper for browser tests.
|
|
30
|
+
|
|
31
|
+
### Install
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install vite-plugin-testem --save-dev
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Install a compatible **Vite** version (peer dependency: `^7.0.0 || ^8.0.0`). To run browser tests with Testem, install **Testem** (optional peer: `^3.20.0`):
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm install testem@^3.20.0 --save-dev
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Links
|
|
44
|
+
|
|
45
|
+
- **npm:** [vite-plugin-testem](https://www.npmjs.com/package/vite-plugin-testem)
|
|
46
|
+
- **Docs:** [README on GitHub](https://github.com/Gaurav0/vite-plugin-testem#readme)
|
package/README.md
CHANGED
|
@@ -8,12 +8,16 @@
|
|
|
8
8
|
npm install vite-plugin-testem --save-dev
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
Node.js `^20.19.0 || ^22.12.0 || ^24.0.0 || >=26.0.0` is required.
|
|
12
|
+
|
|
11
13
|
You must also install a compatible Vite version (peer dependency: `^7.0.0 || ^8.0.0`).
|
|
12
14
|
|
|
13
|
-
To run browser tests with Testem, install Testem in your project (optional peer dependency: `^3.20.0`):
|
|
15
|
+
To run browser tests with Testem, install Testem in your project (optional peer dependency: `^3.20.0 || ^4.0.0-beta.1`):
|
|
14
16
|
|
|
15
17
|
```bash
|
|
16
18
|
npm install testem@^3.20.0 --save-dev
|
|
19
|
+
# or, on Node ^22.17.0 || ^24.0.0 || >=26.0.0:
|
|
20
|
+
npm install testem@^4.0.0-beta.1 --save-dev
|
|
17
21
|
```
|
|
18
22
|
|
|
19
23
|
## `vitePluginTestem(options)`
|
|
@@ -65,6 +69,16 @@ module.exports = async function testemConfig() {
|
|
|
65
69
|
};
|
|
66
70
|
```
|
|
67
71
|
|
|
72
|
+
## Development
|
|
73
|
+
|
|
74
|
+
`npm test` runs the smoke test. It does not need Testem or a browser.
|
|
75
|
+
|
|
76
|
+
`npm run test:integration` installs Testem into `fixtures/integration` and runs headless Chrome. `TESTEM_VERSION` defaults to `3.20.0`. Testem 4 needs Chrome and Node `^22.17.0 || ^24.0.0 || >=26.0.0`:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
TESTEM_VERSION=4.0.0-beta.1 npm run test:integration
|
|
80
|
+
```
|
|
81
|
+
|
|
68
82
|
## License
|
|
69
83
|
|
|
70
84
|
MIT
|
package/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const fs = require('fs/promises');
|
|
3
4
|
const path = require('path');
|
|
4
5
|
const vite = require('vite');
|
|
5
6
|
|
|
@@ -47,6 +48,9 @@ Testem.handleConsoleMessage = function (msg) {
|
|
|
47
48
|
|
|
48
49
|
/**
|
|
49
50
|
* Creates Express middleware (for Testem `middleware:`) that forwards requests to Vite in middleware mode.
|
|
51
|
+
* Strips Testem’s per-browser session prefix (`/:id/…`) so Vite resolves paths from the project root.
|
|
52
|
+
* Transforms `*.html` with `server.transformIndexHtml` so plugins such as `vitePluginTestem` run.
|
|
53
|
+
* `appType: 'custom'` stays in place so a missing file falls through to Testem instead of Vite’s 404.
|
|
50
54
|
* Skips `/testem.js`, `/testem/*`, and `/socket.io` so Testem’s own routes run later in the stack.
|
|
51
55
|
*
|
|
52
56
|
* @param {import('vite').InlineConfig} [inlineConfig] merged after defaults; set `configFile: false` to skip loading `vite.config.js`
|
|
@@ -76,7 +80,23 @@ async function createTestemViteMiddleware(inlineConfig = {}) {
|
|
|
76
80
|
|
|
77
81
|
function middleware(app) {
|
|
78
82
|
app.use((req, res, next) => {
|
|
79
|
-
|
|
83
|
+
let url = req.url;
|
|
84
|
+
const qIdx = url.indexOf('?');
|
|
85
|
+
const pathPart = qIdx === -1 ? url : url.slice(0, qIdx);
|
|
86
|
+
const queryPart = qIdx === -1 ? '' : url.slice(qIdx);
|
|
87
|
+
// Testem opens the runner under /:id/… (browser session). Strip it so Vite resolves files
|
|
88
|
+
// from project root (same path layout as bare /tests_run.html).
|
|
89
|
+
const withPath = pathPart.match(/^\/-?\d+\/(.+)$/);
|
|
90
|
+
const idOnly = pathPart.match(/^\/-?\d+$/);
|
|
91
|
+
if (withPath) {
|
|
92
|
+
req.url = `/${withPath[1]}${queryPart}`;
|
|
93
|
+
url = req.url;
|
|
94
|
+
} else if (idOnly) {
|
|
95
|
+
req.url = `/${queryPart}`;
|
|
96
|
+
url = req.url;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const pathname = url.split('?')[0];
|
|
80
100
|
if (
|
|
81
101
|
pathname === '/testem.js' ||
|
|
82
102
|
pathname.startsWith('/testem/') ||
|
|
@@ -84,6 +104,29 @@ async function createTestemViteMiddleware(inlineConfig = {}) {
|
|
|
84
104
|
) {
|
|
85
105
|
return next();
|
|
86
106
|
}
|
|
107
|
+
|
|
108
|
+
if (pathname.endsWith('.html')) {
|
|
109
|
+
const rootPath = path.resolve(cwd);
|
|
110
|
+
const filePath = path.resolve(rootPath, pathname.slice(1));
|
|
111
|
+
const relative = path.relative(rootPath, filePath);
|
|
112
|
+
if (!relative.startsWith('..') && !path.isAbsolute(relative)) {
|
|
113
|
+
fs.readFile(filePath, 'utf8')
|
|
114
|
+
.then((html) => server.transformIndexHtml(url, html))
|
|
115
|
+
.then((html) => {
|
|
116
|
+
res.statusCode = 200;
|
|
117
|
+
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
118
|
+
res.end(html);
|
|
119
|
+
})
|
|
120
|
+
.catch((err) => {
|
|
121
|
+
if (err && err.code === 'ENOENT') {
|
|
122
|
+
return server.middlewares(req, res, next);
|
|
123
|
+
}
|
|
124
|
+
return next(err);
|
|
125
|
+
});
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
87
130
|
server.middlewares(req, res, next);
|
|
88
131
|
});
|
|
89
132
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-testem",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Vite plugin and Testem middleware helper for running browser tests with Testem",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vite",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"url": "https://github.com/Gaurav0/vite-plugin-testem/issues"
|
|
20
20
|
},
|
|
21
21
|
"engines": {
|
|
22
|
-
"node": "^20.19.0 || ^22.12.0 ||
|
|
22
|
+
"node": "^20.19.0 || ^22.12.0 || ^24.0.0 || >=26.0.0"
|
|
23
23
|
},
|
|
24
24
|
"main": "./index.js",
|
|
25
25
|
"exports": {
|
|
@@ -31,11 +31,12 @@
|
|
|
31
31
|
"files": [
|
|
32
32
|
"index.js",
|
|
33
33
|
"README.md",
|
|
34
|
+
"CHANGELOG.md",
|
|
34
35
|
"LICENSE"
|
|
35
36
|
],
|
|
36
37
|
"peerDependencies": {
|
|
37
38
|
"vite": "^7.0.0 || ^8.0.0",
|
|
38
|
-
"testem": "^3.20.0"
|
|
39
|
+
"testem": "^3.20.0 || ^4.0.0-beta.1"
|
|
39
40
|
},
|
|
40
41
|
"peerDependenciesMeta": {
|
|
41
42
|
"testem": {
|
|
@@ -44,7 +45,8 @@
|
|
|
44
45
|
},
|
|
45
46
|
"scripts": {
|
|
46
47
|
"lint": "eslint .",
|
|
47
|
-
"test": "node scripts/smoke-test.js"
|
|
48
|
+
"test": "node scripts/smoke-test.js",
|
|
49
|
+
"test:integration": "node scripts/integration-test.js"
|
|
48
50
|
},
|
|
49
51
|
"devDependencies": {
|
|
50
52
|
"@eslint/js": "^10.0.0",
|