From 1dd30984d455794395694e1468e815564c23868c Mon Sep 17 00:00:00 2001 From: "M. George Hansen" Date: Wed, 10 Jun 2020 12:39:54 -0700 Subject: [PATCH] fix: dont require config file Fixes a couple of issues with config files in websnacks projects. First, config files are no longer required and the dev and build commands will no longer error out if a websnacks.ts/js file doesn't exist. Second, all optional user config params are now actually optional - before some parameters were assumed to exist and would error out if not present (e.g. the "watch" parameter). Finally, e2e tests were added to prevent regressions on these issues and test helpers were extracted to a separate file. --- src/cli/commands/dev.ts | 57 ++++++++++---- src/config.ts | 33 +++++--- test/e2e/build.tsx | 121 +++++++++++++++++++++++++++++ test/e2e/dev.tsx | 152 ++++++++++++++---------------------- test/helpers/e2e.ts | 167 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 410 insertions(+), 120 deletions(-) create mode 100644 test/e2e/build.tsx create mode 100644 test/helpers/e2e.ts diff --git a/src/cli/commands/dev.ts b/src/cli/commands/dev.ts index 3de8984..bc2f97e 100644 --- a/src/cli/commands/dev.ts +++ b/src/cli/commands/dev.ts @@ -5,20 +5,21 @@ import { existsSync, promises as fs, watch } from "fs"; import * as http from "http"; +import * as net from "net"; import * as path from "path"; import { renderSite } from "../../build"; import { Config, loadConfig } from "../../config"; import { Command, UsageError } from "../types"; -const SERVER_PORT = 8080; +const DEFAULT_SERVER_PORT = 8080; -const injectLiveReloadScript = (htmlContents: string): string => +const injectLiveReloadScript = (htmlContents: string, port: number): string => htmlContents.replace( "", `