mirror of
https://github.com/PR0M3TH3AN/TORCH.git
synced 2026-11-05 04:11:53 +00:00
fix: ensure torch init adds .gitignore with node_modules
Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
5783f995d7
commit
c36735dbde
2 files changed
+89
No files matched your search
@@ -0,0 +1,65 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert';
|
||||
import { cmdInit } from '../src/ops.mjs';
|
||||
|
||||
test('ops.mjs: cmdInit creates .gitignore with node_modules', async (t) => {
|
||||
const tmpDir = fs.mkdtempSync(path.join(process.cwd(), 'test-gitignore-'));
|
||||
|
||||
// Clean up afterwards
|
||||
t.after(() => {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
const mockAnswers = {
|
||||
installDir: 'torch',
|
||||
namespace: 'test-ns',
|
||||
hashtag: 'test-hash',
|
||||
relays: ['wss://relay.damus.io'],
|
||||
};
|
||||
|
||||
// Run init
|
||||
// We silence console logs to keep test output clean, if possible, but it's fine.
|
||||
await cmdInit(false, tmpDir, mockAnswers);
|
||||
|
||||
const gitIgnorePath = path.join(tmpDir, 'torch', '.gitignore');
|
||||
|
||||
if (fs.existsSync(gitIgnorePath)) {
|
||||
const content = fs.readFileSync(gitIgnorePath, 'utf8');
|
||||
assert.match(content, /node_modules/, '.gitignore should contain node_modules');
|
||||
} else {
|
||||
assert.fail('.gitignore was not created');
|
||||
}
|
||||
});
|
||||
|
||||
test('ops.mjs: cmdInit appends to existing .gitignore', async (t) => {
|
||||
const tmpDir = fs.mkdtempSync(path.join(process.cwd(), 'test-gitignore-existing-'));
|
||||
|
||||
// Clean up afterwards
|
||||
t.after(() => {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
const torchDir = path.join(tmpDir, 'torch');
|
||||
fs.mkdirSync(torchDir, { recursive: true });
|
||||
|
||||
// Create existing .gitignore without node_modules
|
||||
fs.writeFileSync(path.join(torchDir, '.gitignore'), 'existing-pattern\n', 'utf8');
|
||||
|
||||
const mockAnswers = {
|
||||
installDir: 'torch',
|
||||
namespace: 'test-ns',
|
||||
hashtag: 'test-hash',
|
||||
relays: ['wss://relay.damus.io'],
|
||||
};
|
||||
|
||||
// Run init (force=true because directory exists)
|
||||
await cmdInit(true, tmpDir, mockAnswers);
|
||||
|
||||
const gitIgnorePath = path.join(torchDir, '.gitignore');
|
||||
const content = fs.readFileSync(gitIgnorePath, 'utf8');
|
||||
|
||||
assert.match(content, /existing-pattern/, 'Should preserve existing content');
|
||||
assert.match(content, /node_modules/, 'Should append node_modules');
|
||||
});
|
||||
Reference in new issue
Block a user