yarn-version 1.0.0-pre → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,86 +1,88 @@
1
1
  import { URL, fileURLToPath } from "node:url";
2
- import versionCommand from "./version";
2
+ import { Level } from "nightingale";
3
+ import { StringHandler } from "nightingale-string";
4
+ import type { VersionCommandOptions } from "./version";
5
+ import { Defaults, versionCommandAction } from "./version";
3
6
 
4
7
  interface ExecuteCommandResult {
5
8
  exitCode: number;
6
9
  stdout: string;
7
10
  stderr: string;
8
11
  }
12
+ const presetOption = {
13
+ // preset: fileURLToPath(
14
+ // new URL(
15
+ // "../../node_modules/conventional-changelog-conventionalcommits",
16
+ // import.meta.url,
17
+ // ),
18
+ // ),
19
+ };
9
20
 
10
- function executeCommand(
11
- args: string[],
12
- options: {
13
- cwd: URL;
14
- },
15
- ): ExecuteCommandResult {
16
- try {
17
- versionCommand.parse(args, { cwd: options.cwd });
18
- // const stdout = execFileSync("yarn", [command, ...args], {
19
- // cwd: fileURLToPath(options.cwd),
20
- // stdio: "pipe",
21
- // });
22
- // return { exitCode: 0, stdout: stdout.toString("utf8"), stderr: "" };
23
- } catch (error: any) {
24
- if (error.status == null) {
25
- throw error;
26
- }
27
-
28
- return {
29
- exitCode: error.status,
30
- stdout: error.stdout?.toString("utf8"),
31
- stderr: error.stderr?.toString("utf8"),
32
- };
33
- }
21
+ class NightingaleTestHandler extends StringHandler {
22
+ isHandling = () => true;
34
23
  }
35
24
 
36
- const presetOption = [
37
- "--preset",
38
- fileURLToPath(
39
- new URL(
40
- "../../node_modules/conventional-changelog-conventionalcommits",
41
- import.meta.url,
42
- ),
43
- ),
44
- ];
25
+ const executeAction = async (
26
+ options: Partial<VersionCommandOptions>,
27
+ ): Promise<ExecuteCommandResult> => {
28
+ const nightingaleHandler = new NightingaleTestHandler(Level.ALL);
45
29
 
46
- describe("version", () => {
47
- it("should fail if package has no version", () => {
48
- const { exitCode, stdout, stderr } = executeCommand(
49
- "yarn-version",
50
- [...presetOption, "--dry-run"],
30
+ try {
31
+ await versionCommandAction(
32
+ { ...Defaults, ...options, cwdIsRoot: true },
51
33
  {
52
- cwd: new URL("../__fixtures__/no-version", import.meta.url),
34
+ nightingaleHandler,
53
35
  },
54
36
  );
37
+ } catch (error) {
38
+ return {
39
+ exitCode: 1,
40
+ stdout: "",
41
+ stderr: (error as any).toString(),
42
+ };
43
+ }
44
+ return {
45
+ exitCode: 0,
46
+ stdout: nightingaleHandler.string,
47
+ stderr: "",
48
+ };
49
+ };
50
+
51
+ describe("version", () => {
52
+ it("should fail if package has no version", async () => {
53
+ const { exitCode, stdout, stderr } = await executeAction({
54
+ ...presetOption,
55
+ dryRun: true,
56
+ cwd: fileURLToPath(
57
+ new URL("../__fixtures__/no-version", import.meta.url),
58
+ ),
59
+ });
55
60
  expect(exitCode).toBe(1);
56
- expect(stdout).toContain(
61
+ expect(stderr).toContain(
57
62
  'UsageError: package.json has no version in its manifest. For the first release, set to "1.0.0-pre" or "0.1.0-pre".',
58
63
  ); // replace with expected output
59
- expect(stderr).toBeFalsy();
64
+ expect(stdout).toBeFalsy();
60
65
  });
61
66
 
62
- it("should fail if --prerelease is passed", () => {
63
- const { exitCode, stdout, stderr } = executeCommand(
64
- "version",
65
- [...presetOption, "--prerelease=alpha", "--dry-run"],
66
- {
67
- cwd: new URL("../__fixtures__/basic", import.meta.url),
68
- },
69
- );
67
+ it("should fail if --prerelease is passed", async () => {
68
+ const { exitCode, stdout, stderr } = await executeAction({
69
+ ...presetOption,
70
+ prerelease: "alpha",
71
+ dryRun: true,
72
+ cwd: fileURLToPath(new URL("../__fixtures__/basic", import.meta.url)),
73
+ });
70
74
  expect(exitCode).toBe(1);
71
- expect(stdout).toContain("prerelease is not supported yet."); // replace with expected output
72
- expect(stderr).toBeFalsy();
75
+ expect(stderr).toContain("prerelease is not supported yet."); // replace with expected output
76
+ expect(stdout).toBeFalsy();
73
77
  });
74
78
 
75
- it("should pass with dry-run and force", () => {
76
- const { exitCode, stdout, stderr } = executeCommand(
77
- "version",
78
- [...presetOption, "--force=minor", "--dry-run"],
79
- {
80
- cwd: new URL("../__fixtures__/basic", import.meta.url),
81
- },
82
- );
83
- console.log(stdout);
79
+ it("should pass with dry-run and force", async () => {
80
+ const { exitCode, stdout, stderr } = await executeAction({
81
+ ...presetOption,
82
+ force: "minor",
83
+ dryRun: true,
84
+ cwd: fileURLToPath(new URL("../__fixtures__/basic", import.meta.url)),
85
+ });
84
86
  expect(stderr).toBeFalsy();
85
87
  expect(exitCode).toBe(0);
86
88
  expect(stdout).toContain("basic: 1.0.0 -> 1.1.0"); // replace with expected output