2024-02-13 09:41:59 -05:00
|
|
|
import assert from 'node:assert/strict';
|
2023-08-14 14:23:14 -05:00
|
|
|
import { rmSync } from 'node:fs';
|
|
|
|
import { mkdir, writeFile } from 'node:fs/promises';
|
2024-02-13 09:41:59 -05:00
|
|
|
import { after, before, describe, it } from 'node:test';
|
2023-02-06 11:19:37 -05:00
|
|
|
|
|
|
|
import { git } from '../dist/index.js';
|
|
|
|
import { setup } from './utils.js';
|
|
|
|
|
|
|
|
describe('git', () => {
|
|
|
|
const fixture = setup();
|
|
|
|
|
|
|
|
it('none', async () => {
|
2023-02-06 11:21:48 -05:00
|
|
|
const context = { cwd: '', dryRun: true, prompt: () => ({ git: false }) };
|
2023-02-06 11:19:37 -05:00
|
|
|
await git(context);
|
|
|
|
|
2024-02-13 09:41:59 -05:00
|
|
|
assert.ok(fixture.hasMessage('Skipping Git initialization'));
|
2023-02-06 11:21:48 -05:00
|
|
|
});
|
2023-02-06 11:19:37 -05:00
|
|
|
|
|
|
|
it('yes (--dry-run)', async () => {
|
2023-02-06 11:21:48 -05:00
|
|
|
const context = { cwd: '', dryRun: true, prompt: () => ({ git: true }) };
|
2023-02-06 11:19:37 -05:00
|
|
|
await git(context);
|
2024-02-13 09:41:59 -05:00
|
|
|
assert.ok(fixture.hasMessage('Skipping Git initialization'));
|
2023-02-06 11:21:48 -05:00
|
|
|
});
|
2023-02-06 11:19:37 -05:00
|
|
|
|
|
|
|
it('no (--dry-run)', async () => {
|
2023-02-06 11:21:48 -05:00
|
|
|
const context = { cwd: '', dryRun: true, prompt: () => ({ git: false }) };
|
2023-02-06 11:19:37 -05:00
|
|
|
await git(context);
|
|
|
|
|
2024-02-13 09:41:59 -05:00
|
|
|
assert.ok(fixture.hasMessage('Skipping Git initialization'));
|
2023-02-06 11:21:48 -05:00
|
|
|
});
|
|
|
|
});
|
2023-08-14 14:23:14 -05:00
|
|
|
|
|
|
|
describe('git initialized', () => {
|
|
|
|
const fixture = setup();
|
|
|
|
const dir = new URL(new URL('./fixtures/not-empty/.git', import.meta.url));
|
|
|
|
|
|
|
|
before(async () => {
|
|
|
|
await mkdir(dir, { recursive: true });
|
|
|
|
await writeFile(new URL('./git.json', dir), '{}', { encoding: 'utf8' });
|
2023-08-14 14:25:29 -05:00
|
|
|
});
|
2023-08-14 14:23:14 -05:00
|
|
|
|
|
|
|
it('already initialized', async () => {
|
|
|
|
const context = {
|
|
|
|
git: true,
|
|
|
|
cwd: './test/fixtures/not-empty',
|
|
|
|
dryRun: false,
|
|
|
|
prompt: () => ({ git: false }),
|
|
|
|
};
|
|
|
|
await git(context);
|
|
|
|
|
2024-02-13 09:41:59 -05:00
|
|
|
assert.ok(fixture.hasMessage('Git has already been initialized'));
|
2023-08-14 14:23:14 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
after(() => {
|
|
|
|
rmSync(dir, { recursive: true, force: true });
|
2023-08-14 14:25:29 -05:00
|
|
|
});
|
|
|
|
});
|