2021-05-24 22:18:56 +00:00
|
|
|
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 () => {
|
2021-05-25 22:16:49 +00:00
|
|
|
const { stdout } = await execa('../../create-astro.js', [`./${template}`, '--template', template, '--skip-install'], { cwd });
|
|
|
|
|
|
|
|
// test: path should formatted as './{dirName}'
|
|
|
|
assert.not.match(stdout, '././');
|
2021-05-24 22:18:56 +00:00
|
|
|
|
|
|
|
const DOES_HAVE = ['.gitignore', 'package.json', 'public', 'src'];
|
2021-05-25 22:16:49 +00:00
|
|
|
const DOES_NOT_HAVE = ['_gitignore', 'meta.json', 'node_modules'];
|
2021-05-24 22:18:56 +00:00
|
|
|
|
|
|
|
// 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) {
|
2021-05-25 22:16:49 +00:00
|
|
|
assert.not.ok(fs.existsSync(path.join(cwd, template, file)), `does not have ${file}`);
|
2021-05-24 22:18:56 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
CreateAstro.run();
|