chore(create-app): tests
This commit is contained in:
parent
1e4c9fc85c
commit
c416e6b23f
27
packages/create-app/test/e2e/npm.js
Normal file
27
packages/create-app/test/e2e/npm.js
Normal 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);
|
||||
});
|
19
packages/create-app/test/server/basics.js
Normal file
19
packages/create-app/test/server/basics.js
Normal 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');
|
||||
});
|
32
packages/create-app/test/server/failure-already-exists.js
Normal file
32
packages/create-app/test/server/failure-already-exists.js
Normal 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`);
|
||||
});
|
20
packages/create-app/test/server/failure-invalid-name.js
Normal file
20
packages/create-app/test/server/failure-invalid-name.js
Normal 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');
|
||||
});
|
Loading…
Reference in New Issue
Block a user