diff options
author | 2023-02-06 10:19:37 -0600 | |
---|---|---|
committer | 2023-02-06 10:19:37 -0600 | |
commit | 8d2187d8b8587b2a3a0207d9ffa8667c43686436 (patch) | |
tree | ab7c3c1217a430ecf1b6036350d7143f235ad287 /packages/create-astro/test/project-name.test.js | |
parent | 91dc0f401545bef49f19193029349fc01c811b1d (diff) | |
download | astro-8d2187d8b8587b2a3a0207d9ffa8667c43686436.tar.gz astro-8d2187d8b8587b2a3a0207d9ffa8667c43686436.tar.zst astro-8d2187d8b8587b2a3a0207d9ffa8667c43686436.zip |
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>
Diffstat (limited to 'packages/create-astro/test/project-name.test.js')
-rw-r--r-- | packages/create-astro/test/project-name.test.js | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/packages/create-astro/test/project-name.test.js b/packages/create-astro/test/project-name.test.js new file mode 100644 index 000000000..38f1359b6 --- /dev/null +++ b/packages/create-astro/test/project-name.test.js @@ -0,0 +1,79 @@ +import { expect } from 'chai'; + +import { projectName } from '../dist/index.js'; +import { setup } from './utils.js'; + +describe('project name', () => { + const fixture = setup(); + + it('pass in name', async () => { + const context = { projectName: '', cwd: './foo/bar/baz', prompt: (() => {})}; + await projectName(context); + + expect(context.cwd).to.eq('./foo/bar/baz'); + expect(context.projectName).to.eq('baz'); + }) + + it('dot', async () => { + const context = { projectName: '', cwd: '.', prompt: (() => ({ name: 'foobar' }))}; + await projectName(context); + + expect(fixture.hasMessage('"." is not empty!')).to.be.true; + expect(context.projectName).to.eq('foobar'); + }) + + it('dot slash', async () => { + const context = { projectName: '', cwd: './', prompt: (() => ({ name: 'foobar' }))}; + await projectName(context); + + expect(fixture.hasMessage('"./" is not empty!')).to.be.true; + expect(context.projectName).to.eq('foobar'); + }) + + it('empty', async () => { + const context = { projectName: '', cwd: './test/fixtures/empty', prompt: (() => ({ name: 'foobar' }))}; + await projectName(context); + + expect(fixture.hasMessage('"./test/fixtures/empty" is not empty!')).to.be.false; + expect(context.projectName).to.eq('empty'); + }) + + it('not empty', async () => { + const context = { projectName: '', cwd: './test/fixtures/not-empty', prompt: (() => ({ name: 'foobar' }))}; + await projectName(context); + + expect(fixture.hasMessage('"./test/fixtures/not-empty" is not empty!')).to.be.true; + expect(context.projectName).to.eq('foobar'); + }) + + it('basic', async () => { + const context = { projectName: '', cwd: '', prompt: (() => ({ name: 'foobar' }))}; + await projectName(context); + + expect(context.cwd).to.eq('foobar'); + expect(context.projectName).to.eq('foobar'); + }) + + it('normalize', async () => { + const context = { projectName: '', cwd: '', prompt: (() => ({ name: 'Invalid Name' }))}; + await projectName(context); + + expect(context.cwd).to.eq('Invalid Name'); + expect(context.projectName).to.eq('invalid-name'); + }) + + it('remove leading/trailing dashes', async () => { + const context = { projectName: '', cwd: '', prompt: (() => ({ name: '(invalid)' }))}; + await projectName(context); + + expect(context.projectName).to.eq('invalid'); + }) + + it('handles scoped packages', async () => { + const context = { projectName: '', cwd: '', prompt: (() => ({ name: '@astro/site' }))}; + await projectName(context); + + expect(context.cwd).to.eq('@astro/site'); + expect(context.projectName).to.eq('@astro/site'); + }) +}) |