@canonical/summon-component 0.17.1 → 0.21.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.
- package/CHANGELOG.md +42 -0
- package/CONVENTIONS.md +184 -0
- package/README.md +5 -5
- package/package.json +14 -10
- package/src/{__tests__/generators.test.ts → index.test.ts} +179 -7
- package/src/index.ts +4 -4
- package/src/{webcomponents → lit}/generator.ts +33 -36
- package/src/lit/index.ts +6 -0
- package/src/lit/types.ts +8 -0
- package/src/react/generator.ts +9 -12
- package/src/react/index.ts +1 -1
- package/src/shared/createComponentPathPrompt.ts +28 -0
- package/src/shared/{template-context.ts → createTemplateContext.ts} +4 -4
- package/src/shared/file-operations/appendExportToParentIndex.test.ts +75 -0
- package/src/shared/{file-operations.ts → file-operations/appendExportToParentIndex.ts} +12 -11
- package/src/shared/file-operations/dryRunWithFileState.ts +28 -0
- package/src/shared/file-operations/index.ts +3 -0
- package/src/shared/file-operations/removeExportFromParentIndex.test.ts +52 -0
- package/src/shared/file-operations/removeExportFromParentIndex.ts +21 -0
- package/src/shared/file-operations/removeLineFromFile.test.ts +66 -0
- package/src/shared/file-operations/removeLineFromFile.ts +29 -0
- package/src/shared/index.ts +6 -5
- package/src/shared/sharedPrompts.ts +30 -0
- package/src/shared/string-helpers/getComponentName.test.ts +18 -0
- package/src/shared/string-helpers/getComponentName.ts +8 -0
- package/src/shared/string-helpers/getParentDir.test.ts +16 -0
- package/src/shared/string-helpers/getParentDir.ts +8 -0
- package/src/shared/string-helpers/index.ts +3 -0
- package/src/shared/types.ts +1 -1
- package/src/shared/validateComponentPath.test.ts +40 -0
- package/src/shared/{validation.ts → validateComponentPath.ts} +3 -13
- package/src/svelte/generator.ts +7 -10
- package/src/svelte/index.ts +1 -1
- package/src/templates/{webcomponents → lit}/component.ts.ejs +8 -10
- package/src/templates/{webcomponents → lit}/index.ts.ejs +0 -2
- package/src/templates/{webcomponents → lit}/stories.ts.ejs +3 -5
- package/src/templates/lit/styles.css.ejs +49 -0
- package/src/templates/lit/tests.ts.ejs +27 -0
- package/src/templates/lit/types.ts.ejs +6 -0
- package/src/templates/react/component.tsx.ejs +0 -2
- package/src/templates/react/index.ts.ejs +0 -2
- package/src/templates/react/ssr.test.tsx.ejs +0 -2
- package/src/templates/react/stories.tsx.ejs +1 -3
- package/src/templates/react/test.tsx.ejs +0 -2
- package/src/templates/react/types.ts.ejs +0 -2
- package/src/templates/shared/styles.css.ejs +0 -2
- package/src/templates/svelte/component.svelte.ejs +0 -2
- package/src/templates/svelte/index.ts.ejs +0 -2
- package/src/templates/svelte/ssr.test.ts.ejs +0 -2
- package/src/templates/svelte/stories.svelte.ejs +0 -1
- package/src/templates/svelte/stories.ts.ejs +0 -2
- package/src/templates/svelte/test.ts.ejs +0 -2
- package/src/templates/svelte/types.ts.ejs +0 -2
- package/src/testing/integration/generators-undo.test.ts +200 -0
- package/vitest.config.ts +12 -0
- package/src/shared/prompts.ts +0 -57
- package/src/shared/string-helpers.ts +0 -29
- package/src/templates/webcomponents/styles.css.ejs +0 -16
- package/src/templates/webcomponents/tests.ts.ejs +0 -29
- package/src/templates/webcomponents/types.ts.ejs +0 -8
- package/src/webcomponents/index.ts +0 -6
- package/src/webcomponents/types.ts +0 -8
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { PromptDefinition } from "@canonical/summon-core";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Shared prompts for component generators (styles, stories, SSR tests)
|
|
5
|
+
*/
|
|
6
|
+
const sharedPrompts: PromptDefinition[] = [
|
|
7
|
+
{
|
|
8
|
+
name: "withStyles",
|
|
9
|
+
type: "confirm",
|
|
10
|
+
message: "Include styles?",
|
|
11
|
+
default: true,
|
|
12
|
+
group: "Options",
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: "withStories",
|
|
16
|
+
type: "confirm",
|
|
17
|
+
message: "Include Storybook stories?",
|
|
18
|
+
default: true,
|
|
19
|
+
group: "Options",
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: "withSsrTests",
|
|
23
|
+
type: "confirm",
|
|
24
|
+
message: "Include SSR tests?",
|
|
25
|
+
default: true,
|
|
26
|
+
group: "Options",
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
export default sharedPrompts;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import getComponentName from "./getComponentName.js";
|
|
3
|
+
|
|
4
|
+
describe("getComponentName", () => {
|
|
5
|
+
it("extracts name from simple path", () => {
|
|
6
|
+
expect(getComponentName("src/components/Button")).toBe("Button");
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it("extracts name from nested path", () => {
|
|
10
|
+
expect(getComponentName("src/lib/components/deep/MyWidget")).toBe(
|
|
11
|
+
"MyWidget",
|
|
12
|
+
);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("returns name when given just a name", () => {
|
|
16
|
+
expect(getComponentName("Button")).toBe("Button");
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import getParentDir from "./getParentDir.js";
|
|
3
|
+
|
|
4
|
+
describe("getParentDir", () => {
|
|
5
|
+
it("extracts parent from normal path", () => {
|
|
6
|
+
expect(getParentDir("src/components/Button")).toBe("src/components");
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it("returns '.' for root-level name", () => {
|
|
10
|
+
expect(getParentDir("Button")).toBe(".");
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("extracts parent from deep path", () => {
|
|
14
|
+
expect(getParentDir("src/lib/deep/Thing")).toBe("src/lib/deep");
|
|
15
|
+
});
|
|
16
|
+
});
|
package/src/shared/types.ts
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import validateComponentPath from "./validateComponentPath.js";
|
|
3
|
+
|
|
4
|
+
describe("validateComponentPath", () => {
|
|
5
|
+
it("accepts valid path with PascalCase name", () => {
|
|
6
|
+
expect(validateComponentPath("src/components/Button")).toBe(true);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it("accepts valid path with numbers in name", () => {
|
|
10
|
+
expect(validateComponentPath("src/components/Button2")).toBe(true);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("rejects empty string", () => {
|
|
14
|
+
expect(validateComponentPath("")).not.toBe(true);
|
|
15
|
+
expect(typeof validateComponentPath("")).toBe("string");
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("rejects undefined", () => {
|
|
19
|
+
expect(validateComponentPath(undefined)).not.toBe(true);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("rejects null", () => {
|
|
23
|
+
expect(validateComponentPath(null)).not.toBe(true);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("rejects non-string value", () => {
|
|
27
|
+
expect(validateComponentPath(42)).not.toBe(true);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("rejects non-PascalCase component name", () => {
|
|
31
|
+
const result = validateComponentPath("src/components/my-button");
|
|
32
|
+
expect(result).not.toBe(true);
|
|
33
|
+
expect(result).toContain("PascalCase");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("rejects camelCase component name", () => {
|
|
37
|
+
const result = validateComponentPath("src/components/myButton");
|
|
38
|
+
expect(result).not.toBe(true);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -1,20 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Validation utilities for component generators
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
1
|
import * as path from "node:path";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Check if a string is in PascalCase
|
|
9
|
-
*/
|
|
10
|
-
export const isPascalCase = (str: string): boolean => {
|
|
11
|
-
return /^[A-Z][a-zA-Z0-9]*$/.test(str);
|
|
12
|
-
};
|
|
2
|
+
import { isPascalCase } from "./string-helpers/index.js";
|
|
13
3
|
|
|
14
4
|
/**
|
|
15
5
|
* Validate component path
|
|
16
6
|
*/
|
|
17
|
-
export
|
|
7
|
+
export default function validateComponentPath(value: unknown): true | string {
|
|
18
8
|
if (!value || typeof value !== "string") {
|
|
19
9
|
return "Component path is required";
|
|
20
10
|
}
|
|
@@ -23,4 +13,4 @@ export const validateComponentPath = (value: unknown): true | string => {
|
|
|
23
13
|
return "Component name must be in PascalCase (e.g., MyComponent)";
|
|
24
14
|
}
|
|
25
15
|
return true;
|
|
26
|
-
}
|
|
16
|
+
}
|
package/src/svelte/generator.ts
CHANGED
|
@@ -23,15 +23,9 @@
|
|
|
23
23
|
|
|
24
24
|
import * as path from "node:path";
|
|
25
25
|
import { fileURLToPath } from "node:url";
|
|
26
|
-
import {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
info,
|
|
30
|
-
mkdir,
|
|
31
|
-
sequence_,
|
|
32
|
-
template,
|
|
33
|
-
when,
|
|
34
|
-
} from "@canonical/summon";
|
|
26
|
+
import { type GeneratorDefinition, template } from "@canonical/summon-core";
|
|
27
|
+
import { debug, info, mkdir, sequence_, when } from "@canonical/task";
|
|
28
|
+
import pkg from "../../package.json" with { type: "json" };
|
|
35
29
|
|
|
36
30
|
import {
|
|
37
31
|
appendExportToParentIndex,
|
|
@@ -73,9 +67,10 @@ const svelteTemplates = {
|
|
|
73
67
|
*
|
|
74
68
|
* @see {@link https://summon.dev/generators/component/svelte} for documentation
|
|
75
69
|
*/
|
|
76
|
-
|
|
70
|
+
const generator = {
|
|
77
71
|
meta: {
|
|
78
72
|
name: "component/svelte",
|
|
73
|
+
displayName: `${pkg.name}:svelte`,
|
|
79
74
|
description:
|
|
80
75
|
"Generate a Svelte 5 component with TypeScript, tests, stories, and styles",
|
|
81
76
|
version: "0.1.0",
|
|
@@ -206,3 +201,5 @@ For example, 'src/lib/components/Button' creates a 'Button' component.`,
|
|
|
206
201
|
]);
|
|
207
202
|
},
|
|
208
203
|
} as const satisfies GeneratorDefinition<SvelteComponentAnswers>;
|
|
204
|
+
|
|
205
|
+
export default generator;
|
package/src/svelte/index.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// Generated by <%= generatorName %> v<%= version %>
|
|
2
|
-
|
|
3
1
|
import { html, LitElement } from "lit";
|
|
4
2
|
import { customElement } from "lit/decorators.js";
|
|
5
3
|
<% if (withStyles) { -%>
|
|
@@ -17,14 +15,14 @@ const componentCssClassName = "ds <%= kebabName %>";
|
|
|
17
15
|
@customElement("ds-<%= kebabName %>")
|
|
18
16
|
export default class <%= name %> extends LitElement implements <%= name %>Props {
|
|
19
17
|
<% if (withStyles) { -%>
|
|
20
|
-
|
|
18
|
+
static styles = styles;
|
|
21
19
|
|
|
22
20
|
<% } -%>
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
21
|
+
render() {
|
|
22
|
+
return html`
|
|
23
|
+
<div class="${componentCssClassName}">
|
|
24
|
+
<slot></slot>
|
|
25
|
+
</div>
|
|
26
|
+
`;
|
|
27
|
+
}
|
|
30
28
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// Generated by <%= generatorName %> v<%= version %>
|
|
2
|
-
|
|
3
1
|
import type { Meta, StoryObj } from "@storybook/web-components-vite";
|
|
4
2
|
import { html } from "lit";
|
|
5
3
|
|
|
@@ -7,13 +5,13 @@ import "./<%= name %>.js";
|
|
|
7
5
|
import type <%= name %> from "./<%= name %>.js";
|
|
8
6
|
|
|
9
7
|
const meta = {
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
title: "Web Components/<%= name %>",
|
|
9
|
+
tags: ["autodocs"],
|
|
12
10
|
} satisfies Meta<<%= name %>>;
|
|
13
11
|
|
|
14
12
|
export default meta;
|
|
15
13
|
type Story = StoryObj<<%= name %>>;
|
|
16
14
|
|
|
17
15
|
export const Default: Story = {
|
|
18
|
-
|
|
16
|
+
render: () => html`<ds-<%= kebabName %>>Hello, <%= name %>!</ds-<%= kebabName %>>`,
|
|
19
17
|
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Lit Layout Primer
|
|
3
|
+
* Delete this comment block when you're done implementing.
|
|
4
|
+
*
|
|
5
|
+
* Styles live in a shadow DOM, isolated from the page by default.
|
|
6
|
+
*
|
|
7
|
+
* Two layers:
|
|
8
|
+
*
|
|
9
|
+
* 1) :host — the outer shell, how this component presents to its parent layout.
|
|
10
|
+
* display, width, height (always apply)
|
|
11
|
+
* grid-column, grid-row, align-self, justify-self (parent must be grid/flex)
|
|
12
|
+
*
|
|
13
|
+
* 2) .ds.<%= kebabName %> — the inner shell, how this component arranges its shadow children.
|
|
14
|
+
* display: grid/flex, gap, grid-template-columns, align-items, justify-content
|
|
15
|
+
*
|
|
16
|
+
* Subgrid pattern — use when the parent defines grid tracks you want to inherit:
|
|
17
|
+
*
|
|
18
|
+
* In the parent component:
|
|
19
|
+
* .ds.parent { display: grid; grid-template-columns: repeat(4, 1fr); }
|
|
20
|
+
*
|
|
21
|
+
* In this component:
|
|
22
|
+
* :host { display: grid; grid-column: span 2; }
|
|
23
|
+
* .ds.<%= kebabName %> { display: grid; grid-template-columns: subgrid; }
|
|
24
|
+
*
|
|
25
|
+
* In this example, the parent establishes a 4-column grid.
|
|
26
|
+
* This component claims 2 of those columns and inherits their widths via subgrid.
|
|
27
|
+
*
|
|
28
|
+
* Keep in mind:
|
|
29
|
+
* - Custom elements are display: inline by default — always set display on :host.
|
|
30
|
+
* - Flex/grid rules only affect direct children of the container, not deeper descendants.
|
|
31
|
+
* - External CSS cannot pierce the shadow boundary — expose CSS custom properties for theming.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
:host {
|
|
35
|
+
/*
|
|
36
|
+
* Host controls the outer layout role.
|
|
37
|
+
* Declare component CSS variables here when needed.
|
|
38
|
+
* Variables must be on :host to be accessible inside the shadow tree.
|
|
39
|
+
*
|
|
40
|
+
* Example:
|
|
41
|
+
* --<%= kebabName %>-color-background: var(--color-background-default);
|
|
42
|
+
* --<%= kebabName %>-color-text: var(--color-text-default);
|
|
43
|
+
*/
|
|
44
|
+
display: inline-flex;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.ds.<%= kebabName %> {
|
|
48
|
+
/* Inner layout and visual styles go here. */
|
|
49
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
import "./<%= name %>.js";
|
|
3
|
+
import type <%= name %> from "./<%= name %>.js";
|
|
4
|
+
|
|
5
|
+
describe("<%= name %> component", () => {
|
|
6
|
+
let elem: <%= name %>;
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
elem = document.createElement("ds-<%= kebabName %>") as <%= name %>;
|
|
10
|
+
document.body.appendChild(elem);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
elem.remove();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("should render component", async () => {
|
|
18
|
+
await customElements.whenDefined("ds-<%= kebabName %>");
|
|
19
|
+
|
|
20
|
+
const container = elem.shadowRoot?.querySelector(".ds.<%= kebabName %>");
|
|
21
|
+
expect(container).toBeTruthy();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("should have correct tag name", () => {
|
|
25
|
+
expect(elem.tagName.toLowerCase()).toBe("ds-<%= kebabName %>");
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Undo integration tests for component generators
|
|
3
|
+
*
|
|
4
|
+
* Verifies that collectUndos produces correct undo plans for each generator.
|
|
5
|
+
* Each template() call produces 2 undos: mkdir(destDir) + writeFile(dest).
|
|
6
|
+
* Plus the generator's own mkdir(componentDir) and appendExportToParentIndex.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { collectUndos, dryRun } from "@canonical/task";
|
|
10
|
+
import { describe, expect, it } from "vitest";
|
|
11
|
+
import { generators } from "../../index.js";
|
|
12
|
+
|
|
13
|
+
// =============================================================================
|
|
14
|
+
// Helpers
|
|
15
|
+
// =============================================================================
|
|
16
|
+
|
|
17
|
+
/** Collect all undo effect tags from a generator task */
|
|
18
|
+
const getUndoEffectTags = (undos: ReturnType<typeof collectUndos>) =>
|
|
19
|
+
undos.flatMap((undo) => dryRun(undo).effects.map((e) => e._tag));
|
|
20
|
+
|
|
21
|
+
// =============================================================================
|
|
22
|
+
// React
|
|
23
|
+
// =============================================================================
|
|
24
|
+
|
|
25
|
+
describe("component/react undo plan", () => {
|
|
26
|
+
const generator = generators["component/react"];
|
|
27
|
+
|
|
28
|
+
it("produces undos for full component (all options)", () => {
|
|
29
|
+
const task = generator.generate({
|
|
30
|
+
componentPath: "src/components/Button",
|
|
31
|
+
withStyles: true,
|
|
32
|
+
withStories: true,
|
|
33
|
+
withSsrTests: true,
|
|
34
|
+
});
|
|
35
|
+
const undos = collectUndos(task);
|
|
36
|
+
|
|
37
|
+
// 1 mkdir(componentDir) + 7 templates × 2 + 1 appendExport(writeFile) = 16
|
|
38
|
+
expect(undos.length).toBeGreaterThan(0);
|
|
39
|
+
expect(undos.length).toBe(16);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("produces fewer undos for minimal component", () => {
|
|
43
|
+
const fullTask = generator.generate({
|
|
44
|
+
componentPath: "src/components/Button",
|
|
45
|
+
withStyles: true,
|
|
46
|
+
withStories: true,
|
|
47
|
+
withSsrTests: true,
|
|
48
|
+
});
|
|
49
|
+
const minTask = generator.generate({
|
|
50
|
+
componentPath: "src/components/Button",
|
|
51
|
+
withStyles: false,
|
|
52
|
+
withStories: false,
|
|
53
|
+
withSsrTests: false,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const fullUndos = collectUndos(fullTask);
|
|
57
|
+
const minUndos = collectUndos(minTask);
|
|
58
|
+
|
|
59
|
+
expect(minUndos.length).toBeLessThan(fullUndos.length);
|
|
60
|
+
// 1 mkdir + 4 templates × 2 + 1 appendExport = 10
|
|
61
|
+
expect(minUndos.length).toBe(10);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("undo effects are only DeleteFile and DeleteDirectory", () => {
|
|
65
|
+
const task = generator.generate({
|
|
66
|
+
componentPath: "src/components/Button",
|
|
67
|
+
withStyles: true,
|
|
68
|
+
withStories: true,
|
|
69
|
+
withSsrTests: true,
|
|
70
|
+
});
|
|
71
|
+
const undos = collectUndos(task);
|
|
72
|
+
const tags = getUndoEffectTags(undos);
|
|
73
|
+
|
|
74
|
+
for (const tag of tags) {
|
|
75
|
+
expect(["DeleteFile", "DeleteDirectory"]).toContain(tag);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("undo includes DeleteDirectory for component dir", () => {
|
|
80
|
+
const task = generator.generate({
|
|
81
|
+
componentPath: "src/components/Card",
|
|
82
|
+
withStyles: false,
|
|
83
|
+
withStories: false,
|
|
84
|
+
withSsrTests: false,
|
|
85
|
+
});
|
|
86
|
+
const undos = collectUndos(task);
|
|
87
|
+
|
|
88
|
+
// First undo should be the mkdir(componentDir) → DeleteDirectory
|
|
89
|
+
const firstUndoEffects = dryRun(undos[0]).effects;
|
|
90
|
+
expect(firstUndoEffects[0]._tag).toBe("DeleteDirectory");
|
|
91
|
+
expect((firstUndoEffects[0] as { path: string }).path).toBe(
|
|
92
|
+
"src/components/Card",
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// =============================================================================
|
|
98
|
+
// Svelte
|
|
99
|
+
// =============================================================================
|
|
100
|
+
|
|
101
|
+
describe("component/svelte undo plan", () => {
|
|
102
|
+
const generator = generators["component/svelte"];
|
|
103
|
+
|
|
104
|
+
it("produces undos for full component (all options)", () => {
|
|
105
|
+
const task = generator.generate({
|
|
106
|
+
componentPath: "src/lib/components/Button",
|
|
107
|
+
withStyles: true,
|
|
108
|
+
withStories: true,
|
|
109
|
+
useTsStories: false,
|
|
110
|
+
withSsrTests: true,
|
|
111
|
+
});
|
|
112
|
+
const undos = collectUndos(task);
|
|
113
|
+
|
|
114
|
+
// 1 mkdir + 7 templates × 2 + 1 appendExport = 16
|
|
115
|
+
expect(undos.length).toBe(16);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("TS stories and Svelte CSF stories produce same undo count", () => {
|
|
119
|
+
const svelteCSF = generator.generate({
|
|
120
|
+
componentPath: "src/lib/components/Button",
|
|
121
|
+
withStyles: false,
|
|
122
|
+
withStories: true,
|
|
123
|
+
useTsStories: false,
|
|
124
|
+
withSsrTests: false,
|
|
125
|
+
});
|
|
126
|
+
const tsStories = generator.generate({
|
|
127
|
+
componentPath: "src/lib/components/Button",
|
|
128
|
+
withStyles: false,
|
|
129
|
+
withStories: true,
|
|
130
|
+
useTsStories: true,
|
|
131
|
+
withSsrTests: false,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
expect(collectUndos(svelteCSF).length).toBe(collectUndos(tsStories).length);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("produces fewer undos for minimal component", () => {
|
|
138
|
+
const minTask = generator.generate({
|
|
139
|
+
componentPath: "src/lib/components/Button",
|
|
140
|
+
withStyles: false,
|
|
141
|
+
withStories: false,
|
|
142
|
+
useTsStories: false,
|
|
143
|
+
withSsrTests: false,
|
|
144
|
+
});
|
|
145
|
+
const minUndos = collectUndos(minTask);
|
|
146
|
+
|
|
147
|
+
// 1 mkdir + 4 templates × 2 + 1 appendExport = 10
|
|
148
|
+
expect(minUndos.length).toBe(10);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
// =============================================================================
|
|
153
|
+
// Lit
|
|
154
|
+
// =============================================================================
|
|
155
|
+
|
|
156
|
+
describe("component/lit undo plan", () => {
|
|
157
|
+
const generator = generators["component/lit"];
|
|
158
|
+
|
|
159
|
+
it("produces undos for full component (all options)", () => {
|
|
160
|
+
const task = generator.generate({
|
|
161
|
+
componentPath: "src/lib/components/Button",
|
|
162
|
+
withStyles: true,
|
|
163
|
+
withStories: true,
|
|
164
|
+
withSsrTests: false,
|
|
165
|
+
});
|
|
166
|
+
const undos = collectUndos(task);
|
|
167
|
+
|
|
168
|
+
// 1 mkdir + 6 templates × 2 + 1 appendExport = 14
|
|
169
|
+
// (lit has: component, index, types, tests, stories, styles = 6 templates)
|
|
170
|
+
expect(undos.length).toBe(14);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("produces fewer undos for minimal component", () => {
|
|
174
|
+
const minTask = generator.generate({
|
|
175
|
+
componentPath: "src/lib/components/Button",
|
|
176
|
+
withStyles: false,
|
|
177
|
+
withStories: false,
|
|
178
|
+
withSsrTests: false,
|
|
179
|
+
});
|
|
180
|
+
const minUndos = collectUndos(minTask);
|
|
181
|
+
|
|
182
|
+
// 1 mkdir + 4 templates × 2 + 1 appendExport = 10
|
|
183
|
+
expect(minUndos.length).toBe(10);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it("undo effects are only DeleteFile and DeleteDirectory", () => {
|
|
187
|
+
const task = generator.generate({
|
|
188
|
+
componentPath: "src/lib/components/Widget",
|
|
189
|
+
withStyles: true,
|
|
190
|
+
withStories: true,
|
|
191
|
+
withSsrTests: false,
|
|
192
|
+
});
|
|
193
|
+
const undos = collectUndos(task);
|
|
194
|
+
const tags = getUndoEffectTags(undos);
|
|
195
|
+
|
|
196
|
+
for (const tag of tags) {
|
|
197
|
+
expect(["DeleteFile", "DeleteDirectory"]).toContain(tag);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
});
|