2023-02-06 11:19:37 -05:00
|
|
|
import { expect } from 'chai';
|
|
|
|
|
|
|
|
import fs from 'fs';
|
|
|
|
import { execa } from 'execa';
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
expect(fixture.hasMessage('Skipping Git initialization')).to.be.true;
|
2023-02-06 11:21:48 -05:00
|
|
|
});
|
2023-02-06 11:19:37 -05:00
|
|
|
|
|
|
|
it('already initialized', async () => {
|
2023-02-06 11:21:48 -05:00
|
|
|
const context = {
|
|
|
|
git: true,
|
|
|
|
cwd: './test/fixtures/not-empty',
|
|
|
|
dryRun: true,
|
|
|
|
prompt: () => ({ git: false }),
|
|
|
|
};
|
2023-02-06 11:19:37 -05:00
|
|
|
await execa('git', ['init'], { cwd: './test/fixtures/not-empty' });
|
|
|
|
await git(context);
|
|
|
|
|
|
|
|
expect(fixture.hasMessage('Git has already been initialized')).to.be.true;
|
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
fs.rmSync('./test/fixtures/not-empty/.git', { recursive: true, force: true });
|
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);
|
|
|
|
|
|
|
|
expect(fixture.hasMessage('Skipping Git initialization')).to.be.true;
|
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);
|
|
|
|
|
|
|
|
expect(fixture.hasMessage('Skipping Git initialization')).to.be.true;
|
2023-02-06 11:21:48 -05:00
|
|
|
});
|
|
|
|
});
|