git.test.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import assert from 'node:assert/strict';
  2. import { describe, it, before, after } from 'node:test';
  3. import { mkdir, writeFile } from 'node:fs/promises';
  4. import { rmSync } from 'node:fs';
  5. import { git } from '../dist/index.js';
  6. import { setup } from './utils.js';
  7. describe('git', () => {
  8. const fixture = setup();
  9. it('none', async () => {
  10. const context = { cwd: '', dryRun: true, prompt: () => ({ git: false }) };
  11. await git(context);
  12. assert.ok(fixture.hasMessage('Skipping Git initialization'));
  13. });
  14. it('yes (--dry-run)', async () => {
  15. const context = { cwd: '', dryRun: true, prompt: () => ({ git: true }) };
  16. await git(context);
  17. assert.ok(fixture.hasMessage('Skipping Git initialization'));
  18. });
  19. it('no (--dry-run)', async () => {
  20. const context = { cwd: '', dryRun: true, prompt: () => ({ git: false }) };
  21. await git(context);
  22. assert.ok(fixture.hasMessage('Skipping Git initialization'));
  23. });
  24. });
  25. describe('git initialized', () => {
  26. const fixture = setup();
  27. const dir = new URL(new URL('./fixtures/not-empty/.git', import.meta.url));
  28. before(async () => {
  29. await mkdir(dir, { recursive: true });
  30. await writeFile(new URL('./git.json', dir), '{}', { encoding: 'utf8' });
  31. });
  32. it('already initialized', async () => {
  33. const context = {
  34. git: true,
  35. cwd: './test/fixtures/not-empty',
  36. dryRun: false,
  37. prompt: () => ({ git: false }),
  38. };
  39. await git(context);
  40. assert.ok(fixture.hasMessage('Git has already been initialized'));
  41. });
  42. after(() => {
  43. rmSync(dir, { recursive: true, force: true });
  44. });
  45. });