Skip to content

Commit 7f524d2

Browse files
committed
fix(rollup-plugin-html): use expectIncludes and restore test:watch script
Replace assert.ok(x.includes(y)) with expectIncludes for better error messages on failure. Add back test:watch script that was accidentally removed during migration. Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c3f9b10 commit 7f524d2

3 files changed

Lines changed: 40 additions & 23 deletions

File tree

packages/rollup-plugin-html/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"demo:mpa": "rm -rf demo/dist && rollup -c demo/mpa/rollup.config.js --watch & npm run serve-demo",
2929
"demo:spa": "rm -rf demo/dist && rollup -c demo/spa/rollup.config.js --watch & npm run serve-demo",
3030
"serve-demo": "node ../dev-server/dist/bin.js --watch --root-dir demo/dist --app-index index.html --compatibility none --open",
31-
"test:node": "node --experimental-strip-types --test --test-force-exit 'test/**/*.test.ts'"
31+
"test:node": "node --experimental-strip-types --test --test-force-exit 'test/**/*.test.ts'",
32+
"test:watch": "node --experimental-strip-types --test --test-force-exit --watch 'test/**/*.test.ts'"
3233
},
3334
"files": [
3435
"*.js",

packages/rollup-plugin-html/test/rollup-plugin-html.test.ts

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ import { rollup } from 'rollup';
22
import type { OutputChunk, OutputOptions, Plugin } from 'rollup';
33
import assert from 'node:assert/strict';
44
import { describe, it, afterEach } from 'node:test';
5+
6+
function expectIncludes(actual: string, expected: string) {
7+
if (!actual.includes(expected)) {
8+
throw new Error(
9+
`Expected substring not found.\n\nExpected:\n${expected}\n\nActual:\n${actual}`,
10+
);
11+
}
12+
}
513
import path from 'path';
614
import { rollupPluginHTML } from '../dist/index.js';
715
import {
@@ -71,8 +79,8 @@ describe('rollup-plugin-html', () => {
7179
assert.equal(Object.keys(chunks).length, 3);
7280
assert.equal(Object.keys(assets).length, 1);
7381

74-
assert.ok(chunks['entrypoint-a.js'].includes(js`console.log('entrypoint-a.js');`));
75-
assert.ok(chunks['entrypoint-b.js'].includes(js`console.log('entrypoint-b.js');`));
82+
expectIncludes(chunks['entrypoint-a.js'], js`console.log('entrypoint-a.js');`);
83+
expectIncludes(chunks['entrypoint-b.js'], js`console.log('entrypoint-b.js');`);
7684
7785
assert.equal(
7886
assets['index.html'],
@@ -131,8 +139,8 @@ describe('rollup-plugin-html', () => {
131139
assert.equal(Object.keys(chunks).length, 3);
132140
assert.equal(Object.keys(assets).length, 1);
133141

134-
assert.ok(chunks['entrypoint-a.js'].includes(js`console.log('entrypoint-a.js');`));
135-
assert.ok(chunks['entrypoint-b.js'].includes(js`console.log('entrypoint-b.js');`));
142+
expectIncludes(chunks['entrypoint-a.js'], js`console.log('entrypoint-a.js');`);
143+
expectIncludes(chunks['entrypoint-b.js'], js`console.log('entrypoint-b.js');`);
136144

137145
assert.equal(
138146
assets['index.html'],
@@ -191,8 +199,8 @@ describe('rollup-plugin-html', () => {
191199
assert.equal(Object.keys(chunks).length, 3);
192200
assert.equal(Object.keys(assets).length, 1);
193201

194-
assert.ok(chunks['entrypoint-a.js'].includes(js`console.log('entrypoint-a.js');`));
195-
assert.ok(chunks['entrypoint-b.js'].includes(js`console.log('entrypoint-b.js');`));
202+
expectIncludes(chunks['entrypoint-a.js'], js`console.log('entrypoint-a.js');`);
203+
expectIncludes(chunks['entrypoint-b.js'], js`console.log('entrypoint-b.js');`);
196204

197205
assert.equal(
198206
assets['index.html'],
@@ -407,7 +415,7 @@ describe('rollup-plugin-html', () => {
407415

408416
const hash = '16165cb387fc14ed1fe1749d05f19f7b';
409417

410-
assert.ok(chunks[`inline-module-${hash}.js`].includes(js`console.log('app.js');`));
418+
expectIncludes(chunks[`inline-module-${hash}.js`], js`console.log('app.js');`);
411419

412420
assert.equal(
413421
assets['index.html'],
@@ -455,7 +463,7 @@ describe('rollup-plugin-html', () => {
455463
assert.equal(Object.keys(assets).length, 1);
456464

457465
const hash = 'b774aefb8bf002b291fd54d27694a34d';
458-
assert.ok(chunks[`inline-module-${hash}.js`].includes(js`console.log('app.js');`));
466+
expectIncludes(chunks[`inline-module-${hash}.js`], js`console.log('app.js');`);
459467
});
460468

461469
it('can build transforming final output', async () => {
@@ -622,10 +630,10 @@ describe('rollup-plugin-html', () => {
622630
assert.equal(Object.keys(chunksB).length, 1);
623631
assert.equal(Object.keys(assetsB).length, 1);
624632

625-
assert.ok(chunksA['app.js'].includes(js`console.log('app.js');`));
626-
assert.ok(chunksA['app.js'].includes(js`console.log('module.js');`));
627-
assert.ok(chunksB['app.js'].includes(js`console.log('app.js');`));
628-
assert.ok(chunksB['app.js'].includes(js`console.log('module.js');`));
633+
expectIncludes(chunksA['app.js'], js`console.log('app.js');`);
634+
expectIncludes(chunksA['app.js'], js`console.log('module.js');`);
635+
expectIncludes(chunksB['app.js'], js`console.log('app.js');`);
636+
expectIncludes(chunksB['app.js'], js`console.log('module.js');`);
629637

630638
assert.equal(assetsA['index.html'], undefined);
631639
assert.equal(
@@ -1322,8 +1330,8 @@ describe('rollup-plugin-html', () => {
13221330
assert.equal(Object.keys(chunks).length, 3);
13231331
assert.equal(Object.keys(assets).length, 1);
13241332
1325-
assert.ok(chunks['entrypoint-a.js'].includes(js`console.log('entrypoint-a.js');`));
1326-
assert.ok(chunks['entrypoint-b.js'].includes(js`console.log('entrypoint-b.js');`));
1333+
expectIncludes(chunks['entrypoint-a.js'], js`console.log('entrypoint-a.js');`);
1334+
expectIncludes(chunks['entrypoint-b.js'], js`console.log('entrypoint-b.js');`);
13271335

13281336
assert.equal(
13291337
assets['index.html'],
@@ -1929,8 +1937,8 @@ describe('rollup-plugin-html', () => {
19291937
assert.equal(Object.keys(chunks).length, 2);
19301938
assert.equal(Object.keys(assets).length, 1);
19311939

1932-
assert.ok(chunks['entrypoint-a.js'].includes(js`console.log('entrypoint-a.js');`));
1933-
assert.ok(chunks['entrypoint-b.js'].includes(js`console.log('entrypoint-b.js');`));
1940+
expectIncludes(chunks['entrypoint-a.js'], js`console.log('entrypoint-a.js');`);
1941+
expectIncludes(chunks['entrypoint-b.js'], js`console.log('entrypoint-b.js');`);
19341942

19351943
assert.equal(
19361944
assets['index.html'],
@@ -2003,8 +2011,8 @@ describe('rollup-plugin-html', () => {
20032011
assert.equal(Object.keys(chunks).length, 2);
20042012
assert.equal(Object.keys(assets).length, 1);
20052013

2006-
assert.ok(chunks['entrypoint-a.js'].includes(js`console.log('entrypoint-a.js');`));
2007-
assert.ok(chunks['entrypoint-b.js'].includes(js`console.log('entrypoint-b.js');`));
2014+
expectIncludes(chunks['entrypoint-a.js'], js`console.log('entrypoint-a.js');`);
2015+
expectIncludes(chunks['entrypoint-b.js'], js`console.log('entrypoint-b.js');`);
20082016

20092017
assert.equal(
20102018
assets['index.html'],
@@ -2077,8 +2085,8 @@ describe('rollup-plugin-html', () => {
20772085
assert.equal(Object.keys(chunks).length, 2);
20782086
assert.equal(Object.keys(assets).length, 1);
20792087

2080-
assert.ok(chunks['entrypoint-a.js'].includes(js`console.log('entrypoint-a.js');`));
2081-
assert.ok(chunks['entrypoint-b.js'].includes(js`console.log('entrypoint-b.js');`));
2088+
expectIncludes(chunks['entrypoint-a.js'], js`console.log('entrypoint-a.js');`);
2089+
expectIncludes(chunks['entrypoint-b.js'], js`console.log('entrypoint-b.js');`);
20822090

20832091
assert.equal(
20842092
assets['index.html'],

packages/rollup-plugin-html/test/src/output/css.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import assert from 'node:assert/strict';
22
import { describe, it } from 'node:test';
3+
4+
function expectIncludes(actual: string, expected: string) {
5+
if (!actual.includes(expected)) {
6+
throw new Error(
7+
`Expected substring not found.\n\nExpected:\n${expected}\n\nActual:\n${actual}`,
8+
);
9+
}
10+
}
311
import {
412
createAssetPlaceholder,
513
replacePlaceholders,
@@ -52,8 +60,8 @@ describe('replacePlaceholders', () => {
5260
return undefined;
5361
};
5462
const result = replacePlaceholders(css, resolver);
55-
assert.ok(result.includes("url('assets/image1.png')"));
56-
assert.ok(result.includes("url('assets/image2.png')"));
63+
expectIncludes(result, "url('assets/image1.png')");
64+
expectIncludes(result, "url('assets/image2.png')");
5765
});
5866
});
5967

0 commit comments

Comments
 (0)