From c416e6b23f3dde18a67773bdf336ba17d6998d28 Mon Sep 17 00:00:00 2001 From: cha0s Date: Sat, 10 Feb 2024 00:18:17 -0600 Subject: [PATCH] chore(create-app): tests --- packages/create-app/test/e2e/npm.js | 27 ++++++++++++++++ packages/create-app/test/server/basics.js | 19 +++++++++++ .../test/server/failure-already-exists.js | 32 +++++++++++++++++++ .../test/server/failure-invalid-name.js | 20 ++++++++++++ 4 files changed, 98 insertions(+) create mode 100644 packages/create-app/test/e2e/npm.js create mode 100644 packages/create-app/test/server/basics.js create mode 100644 packages/create-app/test/server/failure-already-exists.js create mode 100644 packages/create-app/test/server/failure-invalid-name.js diff --git a/packages/create-app/test/e2e/npm.js b/packages/create-app/test/e2e/npm.js new file mode 100644 index 0000000..f283889 --- /dev/null +++ b/packages/create-app/test/e2e/npm.js @@ -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); +}); diff --git a/packages/create-app/test/server/basics.js b/packages/create-app/test/server/basics.js new file mode 100644 index 0000000..f7605d1 --- /dev/null +++ b/packages/create-app/test/server/basics.js @@ -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'); +}); diff --git a/packages/create-app/test/server/failure-already-exists.js b/packages/create-app/test/server/failure-already-exists.js new file mode 100644 index 0000000..8a10496 --- /dev/null +++ b/packages/create-app/test/server/failure-already-exists.js @@ -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`); +}); diff --git a/packages/create-app/test/server/failure-invalid-name.js b/packages/create-app/test/server/failure-invalid-name.js new file mode 100644 index 0000000..ad1e5b1 --- /dev/null +++ b/packages/create-app/test/server/failure-invalid-name.js @@ -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'); +});