2021-05-24 17:18:56 -05: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';
|
2021-06-08 10:12:07 -05:00
|
|
|
import { TEMPLATES } from '../dist/templates.js';
|
2021-05-24 17:18:56 -05:00
|
|
|
|
|
|
|
const CreateAstro = suite('npm init astro');
|
|
|
|
|
2021-05-28 11:06:22 -05:00
|
|
|
const cwd = fileURLToPath(path.dirname(import.meta.url));
|
2021-06-08 10:10:56 -05:00
|
|
|
const fixturesDir = path.join(cwd, 'fixtures');
|
2021-05-24 17:18:56 -05:00
|
|
|
|
|
|
|
CreateAstro.before(async () => {
|
2021-05-28 11:06:22 -05:00
|
|
|
await del(fixturesDir);
|
|
|
|
await fs.promises.mkdir(fixturesDir);
|
2021-05-24 17:18:56 -05:00
|
|
|
});
|
|
|
|
|
2021-06-08 10:12:07 -05:00
|
|
|
for (const { value: template } of TEMPLATES) {
|
2021-06-08 10:10:56 -05:00
|
|
|
// TODO: Unskip once repo is made public. Because the repo is private, the templates can't yet be downloaded.
|
|
|
|
CreateAstro.skip(template, async () => {
|
|
|
|
const testDirectory = path.join(fixturesDir, template);
|
|
|
|
const { stdout } = await execa('../../create-astro.mjs', [testDirectory, '--template', template, '--force-overwrite'], { cwd: path.join(cwd, 'fixtures') });
|
2021-05-25 17:16:49 -05:00
|
|
|
|
2021-06-08 10:12:07 -05:00
|
|
|
console.log(stdout);
|
|
|
|
// test: path should formatted as './{dirName}'
|
2021-05-25 17:16:49 -05:00
|
|
|
assert.not.match(stdout, '././');
|
2021-05-24 17:18:56 -05:00
|
|
|
|
|
|
|
const DOES_HAVE = ['.gitignore', 'package.json', 'public', 'src'];
|
2021-06-08 10:10:56 -05:00
|
|
|
const DOES_NOT_HAVE = ['meta.json', 'node_modules', 'yarn.lock'];
|
2021-05-24 17:18:56 -05:00
|
|
|
|
|
|
|
// test: template contains essential files & folders
|
|
|
|
for (const file of DOES_HAVE) {
|
2021-06-08 10:10:56 -05:00
|
|
|
console.log(path.join(testDirectory, file));
|
|
|
|
assert.ok(fs.existsSync(path.join(testDirectory, file)), `has ${file}`);
|
2021-05-24 17:18:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// test: template DOES NOT contain files supposed to be stripped away
|
|
|
|
for (const file of DOES_NOT_HAVE) {
|
2021-06-08 10:10:56 -05:00
|
|
|
assert.not.ok(fs.existsSync(path.join(testDirectory, file)), `does not have ${file}`);
|
2021-05-24 17:18:56 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
CreateAstro.run();
|