summaryrefslogtreecommitdiff
path: root/packages/create-astro/test/create-astro.test.js
blob: d7abb7e64c42555d91f59f339df6807c253a481d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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 () => {
    const { stdout } = await execa('../../create-astro.js', [`./${template}`, '--template', template, '--skip-install'], { cwd });

    // test: path should formatted as './{dirName}'
    assert.not.match(stdout, '././');

    const DOES_HAVE = ['.gitignore', 'package.json', 'public', 'src'];
    const DOES_NOT_HAVE = ['_gitignore', 'meta.json', 'node_modules'];

    // 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, file)), `does not have ${file}`);
    }
  });
}

CreateAstro.run();