Skip to content

Commit 0e84af0

Browse files
committed
test(cli): cover additional migration tasks
1 parent 69d0bde commit 0e84af0

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import assert from 'node:assert';
2+
import fs from 'fs';
3+
import os from 'os';
4+
import path from 'path';
5+
import { RenameTagNameTask } from '../src/migrate/runner/tasks/common/RenameTagNameTask';
6+
7+
describe('RenameTagNameTask', () => {
8+
it('renames tag names in code files', () => {
9+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'kolibri-cli-'));
10+
const tsxPath = path.join(tmpDir, 'component.tsx');
11+
fs.writeFileSync(tsxPath, '<KolAlert />');
12+
const htmlPath = path.join(tmpDir, 'sample.html');
13+
fs.writeFileSync(htmlPath, '<kol-alert></kol-alert>');
14+
15+
const task = RenameTagNameTask.getInstance('kol-alert', 'kol-notice', '^1');
16+
task.run(tmpDir);
17+
18+
const tsxContent = fs.readFileSync(tsxPath, 'utf8');
19+
const htmlContent = fs.readFileSync(htmlPath, 'utf8');
20+
assert.ok(tsxContent.includes('KolNotice'));
21+
assert.ok(htmlContent.includes('kol-notice'));
22+
});
23+
});

0 commit comments

Comments
 (0)