astro/packages/create-astro/test/git.test.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

Refactor `create-astro` (#6082) * refactor: new version of create-astro * chore: update README * fix(create-astro): update project name logic * test(create-astro): fix test on windows * test(create-astro): fix test on windows * test(create-astro): remove unused import * chore: remove log * chore: increase test timeout * fix: message when skipping * fix: message for env.d.ts file * fix: always hard exit * fix: return from next-steps * chore: add message * refactor dependencies, bundle create-astro * chore: disable create-astro typings * chore: switch to arg * chore: update message * fix: split typescript into two steps, fix context test * chore: update wording * chore: update wording * Update packages/create-astro/src/actions/dependencies.ts Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com> * refactor: move tests back to mocha/chai * chore: update cli-kit * update test script * chore: add comment about setStdout * chore: update cli-kit * Update packages/create-astro/src/messages.ts Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update packages/create-astro/src/messages.ts Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * chore: update lockfile * fix(create-astro): support scoped package names, improve project-name tests * better git initialization * update cli-kit --------- Co-authored-by: Nate Moore <nate@astro.build> Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com> Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
2023-02-06 16:19:37 +00:00
import { expect } from 'chai';
2023-08-14 19:23:14 +00:00
import { mkdir, writeFile } from 'node:fs/promises';
import { rmSync } from 'node:fs';
Refactor `create-astro` (#6082) * refactor: new version of create-astro * chore: update README * fix(create-astro): update project name logic * test(create-astro): fix test on windows * test(create-astro): fix test on windows * test(create-astro): remove unused import * chore: remove log * chore: increase test timeout * fix: message when skipping * fix: message for env.d.ts file * fix: always hard exit * fix: return from next-steps * chore: add message * refactor dependencies, bundle create-astro * chore: disable create-astro typings * chore: switch to arg * chore: update message * fix: split typescript into two steps, fix context test * chore: update wording * chore: update wording * Update packages/create-astro/src/actions/dependencies.ts Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com> * refactor: move tests back to mocha/chai * chore: update cli-kit * update test script * chore: add comment about setStdout * chore: update cli-kit * Update packages/create-astro/src/messages.ts Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update packages/create-astro/src/messages.ts Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * chore: update lockfile * fix(create-astro): support scoped package names, improve project-name tests * better git initialization * update cli-kit --------- Co-authored-by: Nate Moore <nate@astro.build> Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com> Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
2023-02-06 16:19:37 +00:00
import { git } from '../dist/index.js';
import { setup } from './utils.js';
describe('git', () => {
const fixture = setup();
it('none', async () => {
2023-02-06 16:21:48 +00:00
const context = { cwd: '', dryRun: true, prompt: () => ({ git: false }) };
Refactor `create-astro` (#6082) * refactor: new version of create-astro * chore: update README * fix(create-astro): update project name logic * test(create-astro): fix test on windows * test(create-astro): fix test on windows * test(create-astro): remove unused import * chore: remove log * chore: increase test timeout * fix: message when skipping * fix: message for env.d.ts file * fix: always hard exit * fix: return from next-steps * chore: add message * refactor dependencies, bundle create-astro * chore: disable create-astro typings * chore: switch to arg * chore: update message * fix: split typescript into two steps, fix context test * chore: update wording * chore: update wording * Update packages/create-astro/src/actions/dependencies.ts Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com> * refactor: move tests back to mocha/chai * chore: update cli-kit * update test script * chore: add comment about setStdout * chore: update cli-kit * Update packages/create-astro/src/messages.ts Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update packages/create-astro/src/messages.ts Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * chore: update lockfile * fix(create-astro): support scoped package names, improve project-name tests * better git initialization * update cli-kit --------- Co-authored-by: Nate Moore <nate@astro.build> Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com> Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
2023-02-06 16:19:37 +00:00
await git(context);
expect(fixture.hasMessage('Skipping Git initialization')).to.be.true;
2023-02-06 16:21:48 +00:00
});
Refactor `create-astro` (#6082) * refactor: new version of create-astro * chore: update README * fix(create-astro): update project name logic * test(create-astro): fix test on windows * test(create-astro): fix test on windows * test(create-astro): remove unused import * chore: remove log * chore: increase test timeout * fix: message when skipping * fix: message for env.d.ts file * fix: always hard exit * fix: return from next-steps * chore: add message * refactor dependencies, bundle create-astro * chore: disable create-astro typings * chore: switch to arg * chore: update message * fix: split typescript into two steps, fix context test * chore: update wording * chore: update wording * Update packages/create-astro/src/actions/dependencies.ts Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com> * refactor: move tests back to mocha/chai * chore: update cli-kit * update test script * chore: add comment about setStdout * chore: update cli-kit * Update packages/create-astro/src/messages.ts Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update packages/create-astro/src/messages.ts Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * chore: update lockfile * fix(create-astro): support scoped package names, improve project-name tests * better git initialization * update cli-kit --------- Co-authored-by: Nate Moore <nate@astro.build> Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com> Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
2023-02-06 16:19:37 +00:00
it('yes (--dry-run)', async () => {
2023-02-06 16:21:48 +00:00
const context = { cwd: '', dryRun: true, prompt: () => ({ git: true }) };
Refactor `create-astro` (#6082) * refactor: new version of create-astro * chore: update README * fix(create-astro): update project name logic * test(create-astro): fix test on windows * test(create-astro): fix test on windows * test(create-astro): remove unused import * chore: remove log * chore: increase test timeout * fix: message when skipping * fix: message for env.d.ts file * fix: always hard exit * fix: return from next-steps * chore: add message * refactor dependencies, bundle create-astro * chore: disable create-astro typings * chore: switch to arg * chore: update message * fix: split typescript into two steps, fix context test * chore: update wording * chore: update wording * Update packages/create-astro/src/actions/dependencies.ts Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com> * refactor: move tests back to mocha/chai * chore: update cli-kit * update test script * chore: add comment about setStdout * chore: update cli-kit * Update packages/create-astro/src/messages.ts Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update packages/create-astro/src/messages.ts Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * chore: update lockfile * fix(create-astro): support scoped package names, improve project-name tests * better git initialization * update cli-kit --------- Co-authored-by: Nate Moore <nate@astro.build> Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com> Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
2023-02-06 16:19:37 +00:00
await git(context);
expect(fixture.hasMessage('Skipping Git initialization')).to.be.true;
2023-02-06 16:21:48 +00:00
});
Refactor `create-astro` (#6082) * refactor: new version of create-astro * chore: update README * fix(create-astro): update project name logic * test(create-astro): fix test on windows * test(create-astro): fix test on windows * test(create-astro): remove unused import * chore: remove log * chore: increase test timeout * fix: message when skipping * fix: message for env.d.ts file * fix: always hard exit * fix: return from next-steps * chore: add message * refactor dependencies, bundle create-astro * chore: disable create-astro typings * chore: switch to arg * chore: update message * fix: split typescript into two steps, fix context test * chore: update wording * chore: update wording * Update packages/create-astro/src/actions/dependencies.ts Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com> * refactor: move tests back to mocha/chai * chore: update cli-kit * update test script * chore: add comment about setStdout * chore: update cli-kit * Update packages/create-astro/src/messages.ts Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update packages/create-astro/src/messages.ts Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * chore: update lockfile * fix(create-astro): support scoped package names, improve project-name tests * better git initialization * update cli-kit --------- Co-authored-by: Nate Moore <nate@astro.build> Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com> Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
2023-02-06 16:19:37 +00:00
it('no (--dry-run)', async () => {
2023-02-06 16:21:48 +00:00
const context = { cwd: '', dryRun: true, prompt: () => ({ git: false }) };
Refactor `create-astro` (#6082) * refactor: new version of create-astro * chore: update README * fix(create-astro): update project name logic * test(create-astro): fix test on windows * test(create-astro): fix test on windows * test(create-astro): remove unused import * chore: remove log * chore: increase test timeout * fix: message when skipping * fix: message for env.d.ts file * fix: always hard exit * fix: return from next-steps * chore: add message * refactor dependencies, bundle create-astro * chore: disable create-astro typings * chore: switch to arg * chore: update message * fix: split typescript into two steps, fix context test * chore: update wording * chore: update wording * Update packages/create-astro/src/actions/dependencies.ts Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com> * refactor: move tests back to mocha/chai * chore: update cli-kit * update test script * chore: add comment about setStdout * chore: update cli-kit * Update packages/create-astro/src/messages.ts Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update packages/create-astro/src/messages.ts Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * chore: update lockfile * fix(create-astro): support scoped package names, improve project-name tests * better git initialization * update cli-kit --------- Co-authored-by: Nate Moore <nate@astro.build> Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com> Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
2023-02-06 16:19:37 +00:00
await git(context);
expect(fixture.hasMessage('Skipping Git initialization')).to.be.true;
2023-02-06 16:21:48 +00:00
});
});
2023-08-14 19:23:14 +00: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 19:25:29 +00:00
});
2023-08-14 19:23:14 +00:00
it('already initialized', async () => {
const context = {
git: true,
cwd: './test/fixtures/not-empty',
dryRun: false,
prompt: () => ({ git: false }),
};
await git(context);
expect(fixture.hasMessage('Git has already been initialized')).to.be.true;
});
after(() => {
rmSync(dir, { recursive: true, force: true });
2023-08-14 19:25:29 +00:00
});
});