@createiq/htmldiff 1.0.3 → 1.0.4-beta.1
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/.claude/settings.local.json +15 -0
- package/.gitlab-ci.yml +5 -5
- package/biome.json +3 -0
- package/dist/HtmlDiff.cjs +812 -810
- package/dist/HtmlDiff.cjs.map +1 -1
- package/dist/HtmlDiff.d.cts +151 -104
- package/dist/HtmlDiff.d.mts +154 -0
- package/dist/HtmlDiff.mjs +852 -0
- package/dist/HtmlDiff.mjs.map +1 -0
- package/mise.toml +1 -1
- package/package.json +21 -14
- package/src/HtmlDiff.ts +220 -13
- package/test/HtmlDiff.spec.ts +87 -27
- package/test/structural1.html +366 -0
- package/test/structural2.html +366 -0
- package/{tsup.config.ts → tsdown.config.ts} +1 -3
- package/vitest.config.mts +1 -1
- package/dist/HtmlDiff.d.ts +0 -106
- package/dist/HtmlDiff.js +0 -827
- package/dist/HtmlDiff.js.map +0 -1
package/test/HtmlDiff.spec.ts
CHANGED
|
@@ -82,14 +82,16 @@ describe('HtmlDiff', () => {
|
|
|
82
82
|
"<del class='diffmod'>one</del><ins class='diffmod'>two</ins> a<ins class='diffins'> nother</ins> word is somewhere",
|
|
83
83
|
0.1,
|
|
84
84
|
],
|
|
85
|
-
] as const)(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
85
|
+
] as const)('should diff (%s, %s) -> %s with orphanMatchThreshold %d', ([
|
|
86
|
+
oldText,
|
|
87
|
+
newText,
|
|
88
|
+
expected,
|
|
89
|
+
orphanMatchThreshold,
|
|
90
|
+
]) => {
|
|
91
|
+
const diff = new HtmlDiff(oldText, newText)
|
|
92
|
+
diff.orphanMatchThreshold = orphanMatchThreshold
|
|
93
|
+
expect(diff.build()).toEqual(expected)
|
|
94
|
+
})
|
|
93
95
|
|
|
94
96
|
it.for([
|
|
95
97
|
[
|
|
@@ -104,16 +106,18 @@ describe('HtmlDiff', () => {
|
|
|
104
106
|
"This is a date <del class='diffmod'>1</del><ins class='diffmod'>22</ins> <del class='diffmod'>Jan</del><ins class='diffmod'>Feb</ins> <del class='diffmod'>2016</del><ins class='diffmod'>2017</ins> that <del class='diffmod'>will</del><ins class='diffmod'>won't</ins> change",
|
|
105
107
|
null,
|
|
106
108
|
],
|
|
107
|
-
] as const)(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
109
|
+
] as const)('should diff (%s, %s) %s with grouping expression %s', ([
|
|
110
|
+
oldText,
|
|
111
|
+
newText,
|
|
112
|
+
expected,
|
|
113
|
+
groupExpression,
|
|
114
|
+
]) => {
|
|
115
|
+
const diff = new HtmlDiff(oldText, newText)
|
|
116
|
+
if (groupExpression) {
|
|
117
|
+
diff.addBlockExpression(groupExpression)
|
|
115
118
|
}
|
|
116
|
-
|
|
119
|
+
expect(diff.build()).toEqual(expected)
|
|
120
|
+
})
|
|
117
121
|
|
|
118
122
|
it('should throw ArgumentException with invalid overlapping groups', () => {
|
|
119
123
|
const oldText = 'This is a date 1 Jan 2016 that will change'
|
|
@@ -250,15 +254,71 @@ describe('HtmlDiff', () => {
|
|
|
250
254
|
expect(HtmlDiff.execute(oldText, newText)).toEqual(expected)
|
|
251
255
|
})
|
|
252
256
|
|
|
253
|
-
it(
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
257
|
+
it('should calculate a diff for a real-world example within 5s', {
|
|
258
|
+
// CI is slower so give it more time
|
|
259
|
+
timeout: process.env.CI ? 15_000 : 5_000,
|
|
260
|
+
}, async () => {
|
|
261
|
+
const oldText = await fs.readFile('test/input1.html', 'utf-8')
|
|
262
|
+
const newText = await fs.readFile('test/input2.html', 'utf-8')
|
|
263
|
+
const expected = await fs.readFile('test/expected.html', 'utf-8')
|
|
260
264
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
265
|
+
expect(HtmlDiff.execute(oldText, newText)).toEqual(expected)
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
it('should appropriately calculate a partial diff for changes within a paragraph', () => {
|
|
269
|
+
const oldText = `<ol data-type="a">
|
|
270
|
+
<li>
|
|
271
|
+
<p class="justify" data-html="applicability_and_scope">The “<em><strong>Cross-Default</strong></em>” provisions of Section 5(a)(vi) will apply to Party A and will apply to Party B but shall exclude any default that results solely from wire transfer difficulties or an error or omission of an administrative or operational nature (so long as sufficient funds are available to the relevant party on the relevant date), but only if payment is made within three Local Business Days after such transfer difficulties have been corrected or the error or omission has been discovered.</p><p></p>
|
|
272
|
+
</li>
|
|
273
|
+
</ol>`
|
|
274
|
+
const newText = `<ol data-type="a">
|
|
275
|
+
<li>
|
|
276
|
+
<div class="justify" data-html="applicability_and_scope">
|
|
277
|
+
<p>The “<em><strong>Cross-Default</strong></em>” provisions of Section 5(a)(vi) will apply to Party A and will apply to Party B provided that the phrase "or becoming capable at such time of being declared" shall be deleted from clause (1) of such Section 5(a)(vi); but shall exclude any default that results solely from wire transfer difficulties or an error or omission of an administrative or operational nature (so long as sufficient funds are available to the relevant party on the relevant date), but only if payment is made within three Local Business Days after such transfer difficulties have been corrected or the error or omission has been discovered.</p>
|
|
278
|
+
<p></p>
|
|
279
|
+
</div>
|
|
280
|
+
<p></p>
|
|
281
|
+
</li>
|
|
282
|
+
</ol>`
|
|
283
|
+
|
|
284
|
+
const expected = `<ol data-type="a">
|
|
285
|
+
<li>
|
|
286
|
+
<p class="justify" data-html="applicability_and_scope">The “<em><strong>Cross-Default</strong></em>” provisions of Section 5(a)(vi) will apply to Party A and will apply to Party B<ins class='diffins'> provided that the phrase "or becoming capable at such time of being declared" shall be deleted from clause (1) of such Section 5(a)(vi);</ins> but shall exclude any default that results solely from wire transfer difficulties or an error or omission of an administrative or operational nature (so long as sufficient funds are available to the relevant party on the relevant date), but only if payment is made within three Local Business Days after such transfer difficulties have been corrected or the error or omission has been discovered.</p><p></p>
|
|
287
|
+
</li>
|
|
288
|
+
</ol>`
|
|
289
|
+
|
|
290
|
+
expect(HtmlDiff.execute(oldText, newText)).toEqual(expected)
|
|
291
|
+
})
|
|
292
|
+
|
|
293
|
+
it('should not strip structural wrappers when diffing against empty content', () => {
|
|
294
|
+
// When one side is empty and the other has content wrapped in structural tags,
|
|
295
|
+
// the wrapper tags should be preserved in the diff output (not stripped by normalization).
|
|
296
|
+
expect(HtmlDiff.execute('', '<div data-html="test"><strong>Hello World</strong></div>')).toEqual(
|
|
297
|
+
`<div data-html="test"><strong><ins class='diffins'>Hello World</ins></strong></div>`
|
|
298
|
+
)
|
|
299
|
+
})
|
|
300
|
+
|
|
301
|
+
it('should not strip structural wrappers when diffing empty content against wrapped content', () => {
|
|
302
|
+
expect(HtmlDiff.execute('<div data-html="test"><strong>Hello World</strong></div>', '')).toEqual(
|
|
303
|
+
`<div data-html="test"><strong><del class='diffdel'>Hello World</del></div>`
|
|
304
|
+
)
|
|
305
|
+
})
|
|
306
|
+
|
|
307
|
+
it('should preserve old wrapper structure when diffing a p against a div with same content', () => {
|
|
308
|
+
expect(
|
|
309
|
+
HtmlDiff.execute(
|
|
310
|
+
'<p class="justify">Same content here</p>',
|
|
311
|
+
'<div class="justify"><p>Same content here</p></div>'
|
|
312
|
+
)
|
|
313
|
+
).toEqual('<p class="justify">Same content here</p>')
|
|
314
|
+
})
|
|
315
|
+
|
|
316
|
+
it('should preserve old wrapper structure and highlight content changes when wrappers differ', () => {
|
|
317
|
+
expect(
|
|
318
|
+
HtmlDiff.execute(
|
|
319
|
+
'<p class="justify" data-html="test">Some content here</p>',
|
|
320
|
+
'<div class="justify" data-html="test"><p>Some different content here</p></div>'
|
|
321
|
+
)
|
|
322
|
+
).toEqual(`<p class="justify" data-html="test">Some<ins class='diffins'> different</ins> content here</p>`)
|
|
323
|
+
})
|
|
264
324
|
})
|