From 29fd1aabd606f9789d2be92ba7be72c00165f5f3 Mon Sep 17 00:00:00 2001 From: Ryan Christian Date: Fri, 8 Jul 2022 06:12:36 -0500 Subject: [PATCH] test: Fixing 'create' test suite --- packages/cli/tests/lib/cli.js | 11 +++++++---- packages/create-cli/package.json | 4 ++++ packages/create-cli/tests/.eslintrc | 9 +++++++++ packages/{cli => create-cli}/tests/create.test.js | 14 +++----------- .../{cli => create-cli}/tests/images/create.js | 0 5 files changed, 23 insertions(+), 15 deletions(-) create mode 100644 packages/create-cli/tests/.eslintrc rename packages/{cli => create-cli}/tests/create.test.js (72%) rename packages/{cli => create-cli}/tests/images/create.js (100%) diff --git a/packages/cli/tests/lib/cli.js b/packages/cli/tests/lib/cli.js index 8bc6eaca8..f6bfd1bc3 100644 --- a/packages/cli/tests/lib/cli.js +++ b/packages/cli/tests/lib/cli.js @@ -1,6 +1,9 @@ const { join } = require('path'); const { mkdir, symlink, readFile, writeFile } = require('fs').promises; -const cmd = require('../../lib/commands'); +const { build: buildCmd, watch: watchCmd } = require('../../lib/commands'); +const { + create: createCmd, +} = require('../../../create-cli/src/commands/create'); const { tmpDir } = require('./output'); const { disableOptimizeConfig, disableOptimize } = require('./utils'); @@ -44,7 +47,7 @@ exports.create = async function (template, name) { let dest = await tmpDir(); name = name || `test-${template}`; - await cmd.create(template, dest, { name, cwd: '.' }); + await createCmd(template, dest, { name, cwd: '.' }); return dest; }; @@ -55,7 +58,7 @@ const build = (exports.build = async function (cwd, options) { await linkPackage('preact-render-to-string', root, cwd); let opts = Object.assign({}, { cwd }, argv, options); - return await cmd.build(opts.src, opts); + return await buildCmd(opts.src, opts); }); exports.buildFast = async function (cwd, options) { @@ -68,5 +71,5 @@ exports.watch = function (cwd, port, host = '127.0.0.1') { delete args.dest; delete args['inline-css']; let opts = Object.assign({ cwd, host, port, https: false }, args); - return cmd.watch(argv.src, opts); + return watchCmd(argv.src, opts); }; diff --git a/packages/create-cli/package.json b/packages/create-cli/package.json index fa880b333..dda03db0c 100644 --- a/packages/create-cli/package.json +++ b/packages/create-cli/package.json @@ -5,6 +5,10 @@ "repository": "preactjs/preact-cli", "main": "src/index.js", "bin": "src/index.js", + "scripts": { + "pretest": "rimraf ../cli/tests/output", + "test": "jest" + }, "engines": { "node": ">=14" }, diff --git a/packages/create-cli/tests/.eslintrc b/packages/create-cli/tests/.eslintrc new file mode 100644 index 000000000..8c8f368f4 --- /dev/null +++ b/packages/create-cli/tests/.eslintrc @@ -0,0 +1,9 @@ +{ + "env": { + "jest": true, + "jasmine": true + }, + "globals": { + "jasmine": true + } +} diff --git a/packages/cli/tests/create.test.js b/packages/create-cli/tests/create.test.js similarity index 72% rename from packages/cli/tests/create.test.js rename to packages/create-cli/tests/create.test.js index 35dcece05..2dfe811ec 100644 --- a/packages/cli/tests/create.test.js +++ b/packages/create-cli/tests/create.test.js @@ -1,7 +1,7 @@ -const { readFile } = require('fs').promises; +const { readFile } = require('fs/promises'); const { relative, resolve } = require('path'); -const { create } = require('./lib/cli'); -const { expand } = require('./lib/utils'); +const { create } = require('../../cli/tests/lib/cli'); +const { expand } = require('../../cli/tests/lib/utils'); const snapshots = require('./images/create'); describe('preact create', () => { @@ -32,12 +32,4 @@ describe('preact create', () => { expect(template.includes('apple-touch-icon')).toEqual(true); }); - - it('should fail given an invalid name', async () => { - // @ts-ignore - const exit = jest.spyOn(process, 'exit').mockImplementation(() => {}); - await create('simple', '*()@!#!$-Invalid-Name'); - - expect(exit).toHaveBeenCalledWith(1); - }); }); diff --git a/packages/cli/tests/images/create.js b/packages/create-cli/tests/images/create.js similarity index 100% rename from packages/cli/tests/images/create.js rename to packages/create-cli/tests/images/create.js