Skip to content

Commit 1048620

Browse files
committed
Update tests
1 parent 5128bb6 commit 1048620

File tree

6 files changed

+64
-44
lines changed

6 files changed

+64
-44
lines changed

packages/create-next-stack/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"test:large": "pnpm build && ts-node src/tests/e2e/test-manual.ts --debug --package-manager=pnpm --styling=emotion --react-hook-form --formik --prettier --formatting-pre-commit-hook --chakra --framer-motion --github-actions",
5858
"test:cna": "pnpm build && ts-node src/tests/e2e/test-live-cna.ts",
5959
"test:cns": "pnpm build && ts-node src/tests/e2e/test-live-cns.ts",
60+
"test:raw": "pnpm build && ./bin/dev",
6061
"print:help": "pnpm build && ./bin/dev --help",
6162
"print:version": "pnpm build && ./bin/dev --version",
6263
"lint": "eslint --ext=.ts --config=.eslintrc --ignore-path=../../.prettierignore ."

packages/create-next-stack/src/main/commands/create-next-stack.ts

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
import { Args, Command, Flags } from "@oclif/core"
2-
import chalk from "chalk"
3-
import endent from "endent"
42
import { commandInstance } from "../command-instance"
53
import {
6-
CreateNextStackFlags,
74
validateArgs,
85
validateFlags,
96
writablePackageManagerOptions,
107
writableStylingOptions,
118
} from "../create-next-stack-types"
129
import { exitWithError } from "../helpers/exit-with-error"
13-
import { logInfo } from "../logging"
1410
import { performSetupSteps } from "../setup/setup"
1511

1612
export default class CreateNextStack extends Command {
@@ -106,36 +102,16 @@ export default class CreateNextStack extends Command {
106102

107103
if (flags.debug) process.env["DEBUG"] = "true"
108104

109-
if (calledWithoutFlags(flags)) {
110-
logInfo()
111-
logInfo(endent`
112-
Create Next Stack does not support being run without flags.
113-
114-
${chalk.cyan`Please visit ${chalk.bold`https://create-next-stack.com/`} to pick your technologies.`}
115-
116-
You can also use the --help flag for a list of available flags.
117-
`)
118-
logInfo()
119-
} else {
120-
if (!validateArgs(args)) {
121-
process.exit(1) // This tells TypeScript that this block is unreachable. validateArgs(args) either throws or returns true.
122-
}
123-
if (!validateFlags(flags)) {
124-
process.exit(1) // This tells TypeScript that this block is unreachable. validateFlags(flags) either throws or returns true.
125-
}
126-
await performSetupSteps({ args, flags })
105+
if (!validateArgs(args)) {
106+
process.exit(1) // This tells TypeScript that this block is unreachable. validateArgs(args) either throws or returns true.
127107
}
108+
if (!validateFlags(flags)) {
109+
process.exit(1) // This tells TypeScript that this block is unreachable. validateFlags(flags) either throws or returns true.
110+
}
111+
112+
await performSetupSteps({ args, flags })
128113
} catch (error) {
129114
exitWithError(error)
130115
}
131116
}
132117
}
133-
134-
const calledWithoutFlags = (flags: CreateNextStackFlags): boolean => {
135-
const numOfAllFlags = Object.keys(flags).length
136-
137-
let numOfNonGeneralFlags = numOfAllFlags
138-
if (flags.debug != null) numOfNonGeneralFlags--
139-
140-
return numOfNonGeneralFlags === 0
141-
}

packages/create-next-stack/src/main/helpers/exit-with-error.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@ import { inDebugMode } from "./in-debug-mode"
55
export const exitWithError = (error: unknown): never => {
66
if (error instanceof Errors.ExitError && error.oclif.exit === 0) {
77
process.exit(0)
8+
} else if (error instanceof Errors.CLIError) {
9+
logError(error.message)
10+
process.exit(1)
811
} else if (error instanceof Error) {
9-
if (error.stack != null) {
12+
logError("An unknown error occurred.")
13+
if (
14+
(process.env.NODE_ENV === "development" || inDebugMode()) &&
15+
error.stack != null
16+
) {
1017
logError(error.stack)
1118
}
1219
} else {

packages/create-next-stack/src/tests/e2e/test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { testTailwindCssAllFlags } from "./tests/tailwind-css/tailwind-css-all-f
1414
import { testTailwindCssOnly } from "./tests/tailwind-css/tailwind-css-only"
1515
import { testHelpFlag } from "./tests/test-help-flag"
1616
import { testInvalidInputs } from "./tests/test-invalid-inputs"
17+
import { testNoAppName } from "./tests/test-no-app-name"
1718
import { testNoFlags } from "./tests/test-no-flags"
1819
import { testNpm } from "./tests/test-npm"
1920
import { testVersionFlag } from "./tests/test-version-flag"
@@ -36,8 +37,9 @@ import { testYarn } from "./tests/test-yarn"
3637
// Invalid inputs
3738
await testInvalidInputs(createNextStackDir)
3839

39-
// No flags test
40+
// Missing args and flags
4041
await testNoFlags(createNextStackDir)
42+
await testNoAppName(createNextStackDir)
4143

4244
// Package manager tests
4345
// pnpm is used in all other tests, so not tested here.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { runCommand } from "../../../main/helpers/run-command"
2+
import { logTestMeta } from "../helpers/log-test-meta"
3+
import { minutesToMilliseconds } from "../helpers/minutes-to-milliseconds"
4+
import { prepareE2eTest } from "../helpers/prepare-e2e-test"
5+
6+
export const testNoAppName = async (
7+
createNextStackDir: string
8+
): Promise<void> => {
9+
logTestMeta(testNoAppName.name, __filename)
10+
11+
const { pathToCLI, runDirectory } = await prepareE2eTest(createNextStackDir)
12+
13+
const argsVariants: string[][] = [
14+
//
15+
[],
16+
["--debug"],
17+
["--package-manager=pnpm"],
18+
]
19+
20+
for (const args of argsVariants) {
21+
await runCommand(pathToCLI, args, {
22+
timeout: minutesToMilliseconds(1),
23+
cwd: runDirectory,
24+
}).catch((error) => {
25+
if (
26+
!error.stderr.includes("Missing 1 required arg") ||
27+
!error.stderr.includes("app_name")
28+
) {
29+
throw new Error(
30+
"Expected create-next-stack to error on missing app_name argument."
31+
)
32+
}
33+
})
34+
}
35+
}

packages/create-next-stack/src/tests/e2e/tests/test-no-flags.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,23 @@ export const testNoFlags = async (
1111
const { pathToCLI, runDirectory } = await prepareE2eTest(createNextStackDir)
1212

1313
const argsVariants: string[][] = [
14-
[],
15-
["--debug"],
14+
//
1615
["app-name"],
1716
["app-name --debug"],
1817
]
1918

2019
for (const args of argsVariants) {
21-
const result = await runCommand(pathToCLI, args, {
20+
await runCommand(pathToCLI, args, {
2221
timeout: minutesToMilliseconds(1),
2322
cwd: runDirectory,
23+
}).catch((error) => {
24+
if (
25+
!error.stderr.includes("Missing required flag package-manager") ||
26+
!error.stderr.includes("Missing required flag styling")
27+
) {
28+
console.log("throwing error")
29+
throw new Error("Expected create-next-stack to error on missing flags.")
30+
}
2431
})
25-
26-
if (
27-
!result.stdout.includes(
28-
"Please visit https://create-next-stack.com/ to pick your technologies."
29-
)
30-
) {
31-
throw new Error("Expected create-next-stack to post link to website.")
32-
}
3332
}
3433
}

0 commit comments

Comments
 (0)