diff options
Diffstat (limited to 'packages/create-astro')
-rw-r--r-- | packages/create-astro/package.json | 5 | ||||
-rw-r--r-- | packages/create-astro/test/.gitignore | 1 | ||||
-rw-r--r-- | packages/create-astro/test/create-astro.test.js | 39 |
3 files changed, 43 insertions, 2 deletions
diff --git a/packages/create-astro/package.json b/packages/create-astro/package.json index a7e61871d..25b3c4899 100644 --- a/packages/create-astro/package.json +++ b/packages/create-astro/package.json @@ -9,8 +9,9 @@ "create-astro": "./create-astro.js" }, "scripts": { - "build": "astro-scripts build src/index.tsx", - "postbuild": "astro-scripts copy \"src/templates/**\" --tgz" + "build": "ENV=production astro-scripts build src/index.tsx", + "postbuild": "astro-scripts copy \"src/templates/**\" --tgz", + "test": "uvu" }, "files": [ "dist", diff --git a/packages/create-astro/test/.gitignore b/packages/create-astro/test/.gitignore new file mode 100644 index 000000000..116caa127 --- /dev/null +++ b/packages/create-astro/test/.gitignore @@ -0,0 +1 @@ +fixtures diff --git a/packages/create-astro/test/create-astro.test.js b/packages/create-astro/test/create-astro.test.js new file mode 100644 index 000000000..5fb556ef3 --- /dev/null +++ b/packages/create-astro/test/create-astro.test.js @@ -0,0 +1,39 @@ +import fs from 'fs'; +import path from 'path'; +import { fileURLToPath } from 'url'; +import { suite } from 'uvu'; +import execa from 'execa'; +import del from 'del'; +import * as assert from 'uvu/assert'; + +const CreateAstro = suite('npm init astro'); + +const cwd = fileURLToPath(new URL('./fixtures/', import.meta.url)); + +const templates = ['blank', 'starter']; + +CreateAstro.before(async () => { + await del(cwd); + await fs.promises.mkdir(cwd); +}); + +for (const template of templates) { + CreateAstro(template, async () => { + await execa('../../create-astro.js', [template, '--template', template], { cwd }); + + const DOES_HAVE = ['.gitignore', 'package.json', 'public', 'src']; + const DOES_NOT_HAVE = ['_gitignore', 'meta.json']; + + // test: template contains essential files & folders + for (const file of DOES_HAVE) { + assert.ok(fs.existsSync(path.join(cwd, template, file)), `has ${file}`); + } + + // test: template DOES NOT contain files supposed to be stripped away + for (const file of DOES_NOT_HAVE) { + assert.not.ok(fs.existsSync(path.join(cwd, template, `does not have ${file}`))); + } + }); +} + +CreateAstro.run(); |