|
| 1 | +import assert from 'node:assert'; |
| 2 | +import fs from 'fs'; |
| 3 | +import os from 'os'; |
| 4 | +import path from 'path'; |
| 5 | +import { RemovePropertyNameTask } from '../src/migrate/runner/tasks/common/RemovePropertyNameTask'; |
| 6 | +import { setRemoveMode } from '../src/migrate/shares/reuse'; |
| 7 | + |
| 8 | +describe('RemovePropertyNameTask', () => { |
| 9 | + it('prefixes removed property by default', () => { |
| 10 | + const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'kolibri-cli-')); |
| 11 | + const tsxPath = path.join(tmpDir, 'component.tsx'); |
| 12 | + fs.writeFileSync(tsxPath, '<KolButton _deprecated />'); |
| 13 | + const htmlPath = path.join(tmpDir, 'sample.html'); |
| 14 | + fs.writeFileSync(htmlPath, '<kol-button _deprecated></kol-button>'); |
| 15 | + |
| 16 | + const task = RemovePropertyNameTask.getInstance('kol-button', '_deprecated', '^1'); |
| 17 | + task.run(tmpDir); |
| 18 | + |
| 19 | + const tsxContent = fs.readFileSync(tsxPath, 'utf8'); |
| 20 | + const htmlContent = fs.readFileSync(htmlPath, 'utf8'); |
| 21 | + assert.ok(tsxContent.includes('data-removed-_deprecated')); |
| 22 | + assert.ok(htmlContent.includes('data-removed-_deprecated')); |
| 23 | + }); |
| 24 | + |
| 25 | + it('deletes removed property when mode is delete', () => { |
| 26 | + const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'kolibri-cli-')); |
| 27 | + const tsxPath = path.join(tmpDir, 'component.tsx'); |
| 28 | + fs.writeFileSync(tsxPath, '<KolButton _deprecated="something" />'); |
| 29 | + const htmlPath = path.join(tmpDir, 'sample.html'); |
| 30 | + fs.writeFileSync(htmlPath, '<kol-button _deprecated="something"></kol-button>'); |
| 31 | + |
| 32 | + setRemoveMode('delete'); |
| 33 | + const task = RemovePropertyNameTask.getInstance('kol-button', '_deprecated', '^1'); |
| 34 | + task.run(tmpDir); |
| 35 | + setRemoveMode('prefix'); |
| 36 | + |
| 37 | + const tsxContent = fs.readFileSync(tsxPath, 'utf8'); |
| 38 | + const htmlContent = fs.readFileSync(htmlPath, 'utf8'); |
| 39 | + assert.ok(!tsxContent.includes('_deprecated')); |
| 40 | + assert.ok(!htmlContent.includes('_deprecated')); |
| 41 | + }); |
| 42 | +}); |
0 commit comments