Add test for npm init astro (#238)

* Add test for npm init astro

* Use Lerna to run test
This commit is contained in:
Drew Powers 2021-05-24 16:18:56 -06:00 committed by GitHub
parent 860a84d4f4
commit f5ecbee192
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 5 deletions

View file

@ -10,9 +10,7 @@
"dev:vscode": "lerna run dev --scope astro-languageserver --scope astro-vscode --scope astro-parser --parallel --stream",
"format": "prettier -w \"**/*.{js,jsx,ts,tsx,md,json}\"",
"lint": "eslint \"packages/**/*.ts\"",
"test": "yarn test:core && yarn test:prettier",
"test:core": "cd packages/astro && npm test",
"test:prettier": "cd tools/prettier-plugin-astro && npm test"
"test": "lerna run test --scope astro --scope prettier-plugin-astro --scope create-astro --stream"
},
"workspaces": [
"packages/*",

View file

@ -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",

1
packages/create-astro/test/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
fixtures

View file

@ -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();