chore(create-app): tests

This commit is contained in:
cha0s 2024-02-10 00:18:17 -06:00
parent 1e4c9fc85c
commit c416e6b23f
4 changed files with 98 additions and 0 deletions

View File

@ -0,0 +1,27 @@
import {join} from 'path';
import {createWorkspace} from '@flecks/core/build/testing';
import {processCode, spawnWith} from '@flecks/core/server';
import {expect} from 'chai';
const {
FLECKS_CORE_ROOT = process.cwd(),
} = process.env;
it('generates a working application with npm', async () => {
const workspace = await createWorkspace();
const child = spawnWith(
[join(FLECKS_CORE_ROOT, 'build', 'cli.js'), 'test-application'],
{
env: {FLECKS_CORE_ROOT: workspace},
stdio: 'ignore',
},
);
expect(await processCode(child))
.to.equal(0);
expect(await processCode(spawnWith(
['node', join(workspace, 'test-application', 'dist', 'server')],
{stdio: 'ignore'},
)))
.to.equal(0);
});

View File

@ -0,0 +1,19 @@
import {join} from 'path';
import {pipesink, processCode, spawnWith} from '@flecks/core/server';
import {expect} from 'chai';
const {
FLECKS_CORE_ROOT = process.cwd(),
} = process.env;
it('shows help text', async () => {
const child = spawnWith(
[join(FLECKS_CORE_ROOT, 'build', 'cli.js'), '--help'],
{stdio: 'pipe'},
);
const buffer = await pipesink(child.stdout);
await processCode(child);
expect(buffer.toString())
.to.contain('display help for command');
});

View File

@ -0,0 +1,32 @@
import {mkdir} from 'fs/promises';
import {join} from 'path';
import {pipesink, processCode, spawnWith} from '@flecks/core/server';
import {expect} from 'chai';
const {
FLECKS_CORE_ROOT = process.cwd(),
} = process.env;
it('fails if destination already exists', async () => {
const cacheLocation = join(
FLECKS_CORE_ROOT,
'node_modules',
'.cache',
'@flecks',
'create-app',
);
await mkdir(join(cacheLocation, 'failure'), {recursive: true});
const child = spawnWith(
[join(FLECKS_CORE_ROOT, 'build', 'cli.js'), 'failure'],
{
env: {FLECKS_CORE_ROOT: cacheLocation},
stdio: 'pipe',
},
);
const buffer = await pipesink(child.stderr);
expect(await processCode(child))
.to.equal(1);
expect(buffer.toString())
.to.contain(`destination '${join(cacheLocation, 'failure')}' already exists`);
});

View File

@ -0,0 +1,20 @@
import {join} from 'path';
import {pipesink, processCode, spawnWith} from '@flecks/core/server';
import {expect} from 'chai';
const {
FLECKS_CORE_ROOT = process.cwd(),
} = process.env;
it('fails on invalid name', async () => {
const child = spawnWith(
[join(FLECKS_CORE_ROOT, 'build', 'cli.js'), "'R%@#'"],
{stdio: 'pipe'},
);
const buffer = await pipesink(child.stderr);
expect(await processCode(child))
.to.equal(1);
expect(buffer.toString())
.to.contain('invalid app name');
});