Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions packages/tools/kolibri-cli/test/cli-interface.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ describe('CLI interface', () => {
const cwd = process.cwd();
process.chdir(tmpDir);

import * as typedBem from 'typed-bem/scss';
const original = typedBem.generateBemScssFile;
const typedBem = require('typed-bem/scss');
const original = typedBem.generateBemScssFile;
const calls: string[] = [];
typedBem.generateBemScssFile = (_: unknown, name: string) => { calls.push(name); };

Expand Down Expand Up @@ -52,8 +52,9 @@ describe('CLI interface', () => {
process.chdir(tmpDir);


const execOrig = childProc.exec;
childProc.exec = (_: string, cb: (err: null, out: string) => void) => cb(null, '');
const childProc = require('child_process');
const execOrig = childProc.exec;
(childProc as any).exec = (_: string, cb: (err: null, out: string) => void) => cb(null, '');

let runCalled = false;
const runOrig = TaskRunner.prototype.run;
Expand Down Expand Up @@ -82,7 +83,7 @@ describe('CLI interface', () => {
'--test-tasks',
]);

childProc.exec = execOrig;
(childProc as any).exec = execOrig;
TaskRunner.prototype.run = runOrig;
TaskRunner.prototype.getStatus = getStatusOrig;
TaskRunner.prototype.getPendingMinVersion = getPendingOrig;
Expand Down
6 changes: 3 additions & 3 deletions packages/tools/kolibri-cli/test/exec-task.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import { ExecTask } from '../src/migrate/runner/tasks/common/ExecTask';

describe('ExecTask', () => {
it('executes given command', () => {
import * as cp from 'child_process';
const cp = require('child_process');
const original = cp.execSync;
let called = '';
cp.execSync = (cmd: string) => {
(cp as any).execSync = (cmd: string) => {
called = cmd;
return Buffer.from('');
};

const task = ExecTask.getInstance('echo "works"', '^1');
task.run();

cp.execSync = original;
(cp as any).execSync = original;
assert.strictEqual(called, 'echo "works"');
});
});
6 changes: 3 additions & 3 deletions packages/tools/kolibri-cli/test/handle-dependency.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { HandleDependencyTask } from '../src/migrate/runner/tasks/common/HandleD

describe('HandleDependencyTask', () => {
it('calls package manager with dependencies', async () => {
import * as childProc from 'child_process';
const childProc = require('child_process');
const original = childProc.execSync;
let commands: string[] = [];
childProc.execSync = (cmd: string) => { commands.push(cmd); return Buffer.from(''); };
(childProc as any).execSync = (cmd: string) => { commands.push(cmd); return Buffer.from(''); };

const task = HandleDependencyTask.getInstance('add', { lodash: '1.0.0' }, { mocha: '2.0.0' }, '^1');
task.run();

childProc.execSync = original;
(childProc as any).execSync = original;
assert.ok(commands[0].includes('add')); // first call
assert.ok(commands[1].includes('-D'));
});
Expand Down
2 changes: 1 addition & 1 deletion packages/tools/kolibri-cli/test/json-task.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('JsonTask', () => {
process.chdir(tmpDir);
fs.writeFileSync('package.json', '{"name":"test"}');

const task = JsonTask.getInstance('scripts', { test: 'mocha' }, '^1');
const task = JsonTask.getInstance('scripts', { scripts: { test: 'mocha' } }, '^1');
task.run();

process.chdir(cwd);
Expand Down
10 changes: 6 additions & 4 deletions packages/tools/kolibri-cli/test/remove-task.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@ import assert from 'node:assert';
import fs from 'fs';
import os from 'os';
import path from 'path';
import { RemoveTask } from '../src/migrate/runner/tasks/common/RemoveTask';

describe('RemoveTask', () => {
it('executes rimraf command', async () => {
const childProc = require('child_process');
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'kolibri-cli-'));
const filePath = path.join(tmpDir, 'to-remove.txt');
fs.writeFileSync(filePath, 'data');

const original = childProc.execSync;
let executed = '';
childProc.execSync = (cmd: string) => {
const original = childProc.execSync;
let executed = '';
(childProc as any).execSync = (cmd: string) => {
executed = cmd;
fs.rmSync(filePath, { force: true });
return Buffer.from('');
};

const task = RemoveTask.getInstance(filePath, '^1');
task.run();
childProc.execSync = original;
(childProc as any).execSync = original;

assert.ok(!fs.existsSync(filePath));
assert.ok(executed.includes('rimraf'));
Expand Down
11 changes: 6 additions & 5 deletions packages/tools/kolibri-cli/test/rename-slot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ describe('RenameSlotNameTask', () => {
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'kolibri-cli-'));
const tsxPath = path.join(tmpDir, 'component.tsx');
fs.writeFileSync(tsxPath, '<KolCard slot="header"></KolCard>');
const htmlPath = path.join(tmpDir, 'sample.html');
fs.writeFileSync(htmlPath, '<kol-card slot="header"></kol-card>');
const htmlPath = path.join(tmpDir, 'sample.html');
fs.writeFileSync(htmlPath, '<kol-card slot="header"></kol-card>');

const task = RenameSlotNameTask.getInstance('kol-card', 'header', 'header-right', '^1');
task.run(tmpDir);

const tsxContent = fs.readFileSync(tsxPath, 'utf8');
const htmlContent = fs.readFileSync(htmlPath, 'utf8');
assert.ok(tsxContent.includes('slot="header-right"'));
assert.ok(htmlContent.includes('slot="header-right"'));
const htmlContent = fs.readFileSync(htmlPath, 'utf8');
assert.ok(tsxContent.includes('slot="header-right"'));
// Only component files are processed; HTML files remain unchanged
assert.ok(htmlContent.includes('slot="header"'));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('TsConfigReconfigureTask', () => {
process.chdir(tmpDir);
fs.writeFileSync('tsconfig.json', '{}');

const task = TsConfigReconfigureTask.getInstance('compilerOptions', { target: 'ESNext' }, '^1');
const task = TsConfigReconfigureTask.getInstance('compilerOptions', { compilerOptions: { target: 'ESNext' } }, '^1');
task.run();

process.chdir(cwd);
Expand Down
Loading