@alloy-js/core 0.20.0-dev.7 → 0.20.0-dev.9

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.
Files changed (36) hide show
  1. package/dist/src/components/Output.d.ts.map +1 -1
  2. package/dist/src/components/Output.js +16 -12
  3. package/dist/src/components/Output.js.map +1 -1
  4. package/dist/src/components/SourceFile.d.ts.map +1 -1
  5. package/dist/src/components/SourceFile.js +5 -3
  6. package/dist/src/components/SourceFile.js.map +1 -1
  7. package/dist/src/context/format-options.d.ts +10 -0
  8. package/dist/src/context/format-options.d.ts.map +1 -0
  9. package/dist/src/context/format-options.js +32 -0
  10. package/dist/src/context/format-options.js.map +1 -0
  11. package/dist/src/context/index.d.ts +1 -0
  12. package/dist/src/context/index.d.ts.map +1 -1
  13. package/dist/src/context/index.js +1 -0
  14. package/dist/src/context/index.js.map +1 -1
  15. package/dist/src/render.d.ts +5 -0
  16. package/dist/src/render.d.ts.map +1 -1
  17. package/dist/src/render.js +6 -7
  18. package/dist/src/render.js.map +1 -1
  19. package/dist/test/components/source-file.test.d.ts.map +1 -1
  20. package/dist/test/components/source-file.test.js +123 -9
  21. package/dist/test/components/source-file.test.js.map +1 -1
  22. package/dist/test/rendering/formatting.test.js +2 -0
  23. package/dist/test/rendering/formatting.test.js.map +1 -1
  24. package/dist/testing/extend-expect.js +12 -7
  25. package/dist/testing/extend-expect.js.map +1 -1
  26. package/dist/tsconfig.tsbuildinfo +1 -1
  27. package/package.json +1 -1
  28. package/src/components/Output.tsx +14 -14
  29. package/src/components/SourceFile.tsx +4 -2
  30. package/src/context/format-options.ts +31 -0
  31. package/src/context/index.ts +1 -0
  32. package/src/render.ts +21 -20
  33. package/temp/api.json +269 -0
  34. package/test/components/source-file.test.tsx +110 -12
  35. package/test/rendering/formatting.test.tsx +2 -0
  36. package/testing/extend-expect.ts +17 -19
@@ -4,9 +4,9 @@ import {
4
4
  SymbolCreator,
5
5
  } from "../binder.js";
6
6
  import { BinderContext } from "../context/binder.js";
7
+ import { FormatOptions } from "../context/format-options.js";
7
8
  import { NamePolicyContext } from "../context/name-policy.js";
8
9
  import { NamePolicy } from "../name-policy.js";
9
- import { getContext } from "../reactivity.js";
10
10
  import { PrintTreeOptions } from "../render.js";
11
11
  import type { Children } from "../runtime/component.js";
12
12
  import { SourceDirectory } from "./SourceDirectory.js";
@@ -50,14 +50,6 @@ export function Output(props: OutputProps) {
50
50
  nameConflictResolver: props.nameConflictResolver,
51
51
  });
52
52
 
53
- const nodeContext = getContext()!;
54
- nodeContext.meta ??= {};
55
- nodeContext.meta.printOptions = {
56
- printWidth: props.printWidth,
57
- tabWidth: props.tabWidth,
58
- useTabs: props.useTabs,
59
- };
60
-
61
53
  const dir = (
62
54
  <SourceDirectory path={basePath}>{props.children}</SourceDirectory>
63
55
  );
@@ -70,11 +62,19 @@ export function Output(props: OutputProps) {
70
62
 
71
63
  return (
72
64
  <BinderContext.Provider value={binder}>
73
- {props.namePolicy ?
74
- <NamePolicyContext.Provider value={props.namePolicy}>
75
- {dir}
76
- </NamePolicyContext.Provider>
77
- : dir}
65
+ <FormatOptions
66
+ value={{
67
+ printWidth: props.printWidth,
68
+ tabWidth: props.tabWidth,
69
+ useTabs: props.useTabs,
70
+ }}
71
+ >
72
+ {props.namePolicy ?
73
+ <NamePolicyContext.Provider value={props.namePolicy}>
74
+ {dir}
75
+ </NamePolicyContext.Provider>
76
+ : dir}
77
+ </FormatOptions>
78
78
  </BinderContext.Provider>
79
79
  );
80
80
  }
@@ -1,5 +1,6 @@
1
1
  import { join } from "pathe";
2
2
  import { useContext } from "../context.js";
3
+ import { useFormatOptions } from "../context/format-options.js";
3
4
  import { SourceDirectoryContext } from "../context/source-directory.js";
4
5
  import { SourceFileContext } from "../context/source-file.js";
5
6
  import { getContext } from "../reactivity.js";
@@ -44,11 +45,12 @@ export function SourceFile(props: SourceFileProps) {
44
45
  const nodeContext = getContext()!;
45
46
  nodeContext.meta ??= {};
46
47
  nodeContext.meta.sourceFile = context;
47
- nodeContext.meta.printOptions = {
48
+ nodeContext.meta.printOptions = useFormatOptions({
48
49
  printWidth: props.printWidth,
49
50
  tabWidth: props.tabWidth,
50
51
  useTabs: props.useTabs,
51
- };
52
+ insertFinalNewLine: props.insertFinalNewLine,
53
+ });
52
54
 
53
55
  return (
54
56
  <SourceFileContext.Provider value={context}>
@@ -0,0 +1,31 @@
1
+ import { createNamedContext, useContext } from "../context.js";
2
+ import { PrintTreeOptions } from "../render.js";
3
+
4
+ export interface CommonFormatOptions extends PrintTreeOptions {}
5
+
6
+ export const { Provider: FormatOptions, useFormatOptions } =
7
+ createFormatOptionsContextFor<CommonFormatOptions>("*");
8
+
9
+ /** Create a format options context for a specific file type */
10
+ export function createFormatOptionsContextFor<T>(
11
+ filetype: string,
12
+ defaults?: T,
13
+ ) {
14
+ const context = createNamedContext<T>(`FormatOptions.${filetype}`);
15
+ return {
16
+ Provider: context.Provider,
17
+ useFormatOptions: (overrides?: Partial<T>): T => {
18
+ const base = { ...defaults, ...useContext(context) };
19
+ if (overrides === undefined) {
20
+ return base as any;
21
+ }
22
+ const result: any = { ...base };
23
+ for (const [key, value] of Object.entries(overrides)) {
24
+ if (value !== undefined) {
25
+ result[key] = value;
26
+ }
27
+ }
28
+ return result;
29
+ },
30
+ };
31
+ }
@@ -1,6 +1,7 @@
1
1
  export * from "./assignment.js";
2
2
  export * from "./binder.js";
3
3
  export * from "./declaration.js";
4
+ export * from "./format-options.js";
4
5
  export * from "./member-declaration.js";
5
6
  export * from "./member-scope.js";
6
7
  export * from "./name-policy.js";
package/src/render.ts CHANGED
@@ -208,13 +208,6 @@ export function sourceFilesForTree(
208
208
  ): OutputDirectory {
209
209
  let rootDirectory: OutputDirectory | undefined = undefined;
210
210
 
211
- // when passing Output, the first render tree child is the Output component.
212
- const rootRenderOptions =
213
- Array.isArray(tree) ?
214
- (getContextForRenderNode(tree[0] as RenderedTextTree)?.meta
215
- ?.printOptions ?? {})
216
- : {};
217
-
218
211
  collectSourceFiles(undefined, tree);
219
212
 
220
213
  if (!rootDirectory) {
@@ -265,17 +258,13 @@ export function sourceFilesForTree(
265
258
  filetype: context.meta?.sourceFile.filetype,
266
259
  contents: printTree(root, {
267
260
  printWidth:
268
- options?.printWidth ??
269
- context.meta?.printOptions?.printWidth ??
270
- rootRenderOptions.printWidth,
271
- tabWidth:
272
- options?.tabWidth ??
273
- context.meta?.printOptions?.tabWidth ??
274
- rootRenderOptions.tabWidth,
275
- useTabs:
276
- options?.useTabs ??
277
- context.meta?.printOptions?.useTabs ??
278
- rootRenderOptions.useTabs,
261
+ options?.printWidth ?? context.meta?.printOptions?.printWidth,
262
+ tabWidth: options?.tabWidth ?? context.meta?.printOptions?.tabWidth,
263
+ useTabs: options?.useTabs ?? context.meta?.printOptions?.useTabs,
264
+ insertFinalNewLine:
265
+ options?.insertFinalNewLine ??
266
+ context.meta?.printOptions?.insertFinalNewLine ??
267
+ true,
279
268
  }),
280
269
  };
281
270
 
@@ -605,6 +594,12 @@ export interface PrintTreeOptions {
605
594
  * The number of spaces to use for indentation. Defaults to 2 spaces.
606
595
  */
607
596
  tabWidth?: number;
597
+
598
+ /**
599
+ * If files should end with a final new line.
600
+ * @default true
601
+ */
602
+ insertFinalNewLine?: boolean;
608
603
  }
609
604
 
610
605
  const defaultPrintTreeOptions: PrintTreeOptions = {
@@ -624,8 +619,14 @@ export function printTree(tree: RenderedTextTree, options?: PrintTreeOptions) {
624
619
  flushJobs();
625
620
 
626
621
  const d = printTreeWorker(tree);
627
- return doc.printer.printDocToString(d, options as doc.printer.Options)
628
- .formatted;
622
+ const result = doc.printer.printDocToString(
623
+ d,
624
+ options as doc.printer.Options,
625
+ ).formatted;
626
+
627
+ return options.insertFinalNewLine && !result.endsWith("\n") ?
628
+ `${result}\n`
629
+ : result;
629
630
  }
630
631
 
631
632
  function printTreeWorker(tree: RenderedTextTree): Doc {
package/temp/api.json CHANGED
@@ -117,6 +117,10 @@
117
117
  {
118
118
  "tagName": "@reactive",
119
119
  "syntaxKind": "modifier"
120
+ },
121
+ {
122
+ "tagName": "@default",
123
+ "syntaxKind": "block"
120
124
  }
121
125
  ],
122
126
  "reportUnsupportedHtmlElements": false
@@ -2584,6 +2588,37 @@
2584
2588
  ],
2585
2589
  "name": "code"
2586
2590
  },
2591
+ {
2592
+ "kind": "Interface",
2593
+ "canonicalReference": "@alloy-js/core!CommonFormatOptions:interface",
2594
+ "docComment": "",
2595
+ "excerptTokens": [
2596
+ {
2597
+ "kind": "Content",
2598
+ "text": "export interface CommonFormatOptions extends "
2599
+ },
2600
+ {
2601
+ "kind": "Reference",
2602
+ "text": "PrintTreeOptions",
2603
+ "canonicalReference": "@alloy-js/core!PrintTreeOptions:interface"
2604
+ },
2605
+ {
2606
+ "kind": "Content",
2607
+ "text": " "
2608
+ }
2609
+ ],
2610
+ "fileUrlPath": "src/context/format-options.ts",
2611
+ "releaseTag": "Public",
2612
+ "name": "CommonFormatOptions",
2613
+ "preserveMemberOrder": false,
2614
+ "members": [],
2615
+ "extendsTokenRanges": [
2616
+ {
2617
+ "startIndex": 1,
2618
+ "endIndex": 2
2619
+ }
2620
+ ]
2621
+ },
2587
2622
  {
2588
2623
  "kind": "Interface",
2589
2624
  "canonicalReference": "@alloy-js/core!Component:interface",
@@ -4302,6 +4337,107 @@
4302
4337
  ],
4303
4338
  "name": "createFileResource"
4304
4339
  },
4340
+ {
4341
+ "kind": "Function",
4342
+ "canonicalReference": "@alloy-js/core!createFormatOptionsContextFor:function(1)",
4343
+ "docComment": "/**\n * Create a format options context for a specific file type\n */\n",
4344
+ "excerptTokens": [
4345
+ {
4346
+ "kind": "Content",
4347
+ "text": "export declare function createFormatOptionsContextFor<T>(filetype: "
4348
+ },
4349
+ {
4350
+ "kind": "Content",
4351
+ "text": "string"
4352
+ },
4353
+ {
4354
+ "kind": "Content",
4355
+ "text": ", defaults?: "
4356
+ },
4357
+ {
4358
+ "kind": "Content",
4359
+ "text": "T"
4360
+ },
4361
+ {
4362
+ "kind": "Content",
4363
+ "text": "): "
4364
+ },
4365
+ {
4366
+ "kind": "Content",
4367
+ "text": "{\n Provider: import(\"../index.js\")."
4368
+ },
4369
+ {
4370
+ "kind": "Reference",
4371
+ "text": "ComponentDefinition",
4372
+ "canonicalReference": "@alloy-js/core!ComponentDefinition:interface"
4373
+ },
4374
+ {
4375
+ "kind": "Content",
4376
+ "text": "<import(\"../context.js\")."
4377
+ },
4378
+ {
4379
+ "kind": "Reference",
4380
+ "text": "ContextProviderProps",
4381
+ "canonicalReference": "@alloy-js/core!ContextProviderProps:interface"
4382
+ },
4383
+ {
4384
+ "kind": "Content",
4385
+ "text": "<T>>;\n useFormatOptions: (overrides?: "
4386
+ },
4387
+ {
4388
+ "kind": "Reference",
4389
+ "text": "Partial",
4390
+ "canonicalReference": "!Partial:type"
4391
+ },
4392
+ {
4393
+ "kind": "Content",
4394
+ "text": "<T>) => T;\n}"
4395
+ },
4396
+ {
4397
+ "kind": "Content",
4398
+ "text": ";"
4399
+ }
4400
+ ],
4401
+ "fileUrlPath": "src/context/format-options.ts",
4402
+ "returnTypeTokenRange": {
4403
+ "startIndex": 5,
4404
+ "endIndex": 12
4405
+ },
4406
+ "releaseTag": "Public",
4407
+ "overloadIndex": 1,
4408
+ "parameters": [
4409
+ {
4410
+ "parameterName": "filetype",
4411
+ "parameterTypeTokenRange": {
4412
+ "startIndex": 1,
4413
+ "endIndex": 2
4414
+ },
4415
+ "isOptional": false
4416
+ },
4417
+ {
4418
+ "parameterName": "defaults",
4419
+ "parameterTypeTokenRange": {
4420
+ "startIndex": 3,
4421
+ "endIndex": 4
4422
+ },
4423
+ "isOptional": true
4424
+ }
4425
+ ],
4426
+ "typeParameters": [
4427
+ {
4428
+ "typeParameterName": "T",
4429
+ "constraintTokenRange": {
4430
+ "startIndex": 0,
4431
+ "endIndex": 0
4432
+ },
4433
+ "defaultTypeTokenRange": {
4434
+ "startIndex": 0,
4435
+ "endIndex": 0
4436
+ }
4437
+ }
4438
+ ],
4439
+ "name": "createFormatOptionsContextFor"
4440
+ },
4305
4441
  {
4306
4442
  "kind": "Function",
4307
4443
  "canonicalReference": "@alloy-js/core!createIntrinsic:function(1)",
@@ -6581,6 +6717,56 @@
6581
6717
  "endIndex": 14
6582
6718
  }
6583
6719
  },
6720
+ {
6721
+ "kind": "Variable",
6722
+ "canonicalReference": "@alloy-js/core!FormatOptions:var",
6723
+ "docComment": "",
6724
+ "excerptTokens": [
6725
+ {
6726
+ "kind": "Content",
6727
+ "text": "FormatOptions: "
6728
+ },
6729
+ {
6730
+ "kind": "Content",
6731
+ "text": "import(\"../index.js\")."
6732
+ },
6733
+ {
6734
+ "kind": "Reference",
6735
+ "text": "ComponentDefinition",
6736
+ "canonicalReference": "@alloy-js/core!ComponentDefinition:interface"
6737
+ },
6738
+ {
6739
+ "kind": "Content",
6740
+ "text": "<import(\"../context.js\")."
6741
+ },
6742
+ {
6743
+ "kind": "Reference",
6744
+ "text": "ContextProviderProps",
6745
+ "canonicalReference": "@alloy-js/core!ContextProviderProps:interface"
6746
+ },
6747
+ {
6748
+ "kind": "Content",
6749
+ "text": "<"
6750
+ },
6751
+ {
6752
+ "kind": "Reference",
6753
+ "text": "CommonFormatOptions",
6754
+ "canonicalReference": "@alloy-js/core!CommonFormatOptions:interface"
6755
+ },
6756
+ {
6757
+ "kind": "Content",
6758
+ "text": ">>"
6759
+ }
6760
+ ],
6761
+ "fileUrlPath": "src/context/format-options.ts",
6762
+ "isReadonly": true,
6763
+ "releaseTag": "Public",
6764
+ "name": "FormatOptions",
6765
+ "variableTypeTokenRange": {
6766
+ "startIndex": 1,
6767
+ "endIndex": 8
6768
+ }
6769
+ },
6584
6770
  {
6585
6771
  "kind": "Interface",
6586
6772
  "canonicalReference": "@alloy-js/core!ForProps:interface",
@@ -16332,6 +16518,33 @@
16332
16518
  "name": "PrintTreeOptions",
16333
16519
  "preserveMemberOrder": false,
16334
16520
  "members": [
16521
+ {
16522
+ "kind": "PropertySignature",
16523
+ "canonicalReference": "@alloy-js/core!PrintTreeOptions#insertFinalNewLine:member",
16524
+ "docComment": "/**\n * If files should end with a final new line.\n *\n * @default\n *\n * true\n */\n",
16525
+ "excerptTokens": [
16526
+ {
16527
+ "kind": "Content",
16528
+ "text": "insertFinalNewLine?: "
16529
+ },
16530
+ {
16531
+ "kind": "Content",
16532
+ "text": "boolean"
16533
+ },
16534
+ {
16535
+ "kind": "Content",
16536
+ "text": ";"
16537
+ }
16538
+ ],
16539
+ "isReadonly": false,
16540
+ "isOptional": true,
16541
+ "releaseTag": "Public",
16542
+ "name": "insertFinalNewLine",
16543
+ "propertyTypeTokenRange": {
16544
+ "startIndex": 1,
16545
+ "endIndex": 2
16546
+ }
16547
+ },
16335
16548
  {
16336
16549
  "kind": "PropertySignature",
16337
16550
  "canonicalReference": "@alloy-js/core!PrintTreeOptions#printWidth:member",
@@ -23291,6 +23504,62 @@
23291
23504
  ],
23292
23505
  "name": "useContext"
23293
23506
  },
23507
+ {
23508
+ "kind": "Function",
23509
+ "canonicalReference": "@alloy-js/core!useFormatOptions:function(1)",
23510
+ "docComment": "",
23511
+ "excerptTokens": [
23512
+ {
23513
+ "kind": "Content",
23514
+ "text": "useFormatOptions: (overrides?: "
23515
+ },
23516
+ {
23517
+ "kind": "Reference",
23518
+ "text": "Partial",
23519
+ "canonicalReference": "!Partial:type"
23520
+ },
23521
+ {
23522
+ "kind": "Content",
23523
+ "text": "<"
23524
+ },
23525
+ {
23526
+ "kind": "Reference",
23527
+ "text": "CommonFormatOptions",
23528
+ "canonicalReference": "@alloy-js/core!CommonFormatOptions:interface"
23529
+ },
23530
+ {
23531
+ "kind": "Content",
23532
+ "text": "> | undefined"
23533
+ },
23534
+ {
23535
+ "kind": "Content",
23536
+ "text": ") => "
23537
+ },
23538
+ {
23539
+ "kind": "Reference",
23540
+ "text": "CommonFormatOptions",
23541
+ "canonicalReference": "@alloy-js/core!CommonFormatOptions:interface"
23542
+ }
23543
+ ],
23544
+ "fileUrlPath": "src/context/format-options.ts",
23545
+ "returnTypeTokenRange": {
23546
+ "startIndex": 6,
23547
+ "endIndex": 7
23548
+ },
23549
+ "releaseTag": "Public",
23550
+ "overloadIndex": 1,
23551
+ "parameters": [
23552
+ {
23553
+ "parameterName": "overrides",
23554
+ "parameterTypeTokenRange": {
23555
+ "startIndex": 1,
23556
+ "endIndex": 5
23557
+ },
23558
+ "isOptional": true
23559
+ }
23560
+ ],
23561
+ "name": "useFormatOptions"
23562
+ },
23294
23563
  {
23295
23564
  "kind": "Function",
23296
23565
  "canonicalReference": "@alloy-js/core!useMemberContext:function(1)",
@@ -1,13 +1,18 @@
1
1
  import {
2
+ Children,
3
+ CommonFormatOptions,
2
4
  computed,
3
5
  ContentOutputFile,
6
+ FormatOptions,
7
+ Indent,
4
8
  Output,
9
+ Prose,
5
10
  render,
6
11
  renderTree,
7
12
  SourceFile,
8
13
  useContext,
9
14
  } from "@alloy-js/core";
10
- import { expect, it } from "vitest";
15
+ import { describe, expect, it } from "vitest";
11
16
  import { SourceDirectoryContext } from "../../src/context/source-directory.js";
12
17
  import "../../testing/extend-expect.js";
13
18
  import { d } from "../../testing/render.js";
@@ -42,32 +47,125 @@ it("has reactive context", () => {
42
47
  );
43
48
  }
44
49
 
45
- const tree = render(
50
+ expect(
46
51
  <Output>
47
52
  <SourceFile path="hi.txt" filetype="text">
48
53
  hello!
49
54
  </SourceFile>
50
55
  <TrackContents />
51
56
  </Output>,
52
- );
53
-
54
- expect((tree.contents[1] as ContentOutputFile).contents).toEqual(
55
- "hi.txt contents.txt",
56
- );
57
+ ).toRenderTo({
58
+ "hi.txt": "hello!",
59
+ "contents.txt": "hi.txt contents.txt",
60
+ });
57
61
  });
58
62
 
59
- it("Includes header", () => {
63
+ it("includes header", () => {
60
64
  const header = <># This is a header</>;
61
- const tree = render(
65
+
66
+ expect(
62
67
  <Output>
63
68
  <SourceFile path="hi.txt" filetype="text" header={header}>
64
69
  hello!
65
70
  </SourceFile>
66
71
  </Output>,
67
- );
68
-
69
- expect((tree.contents[0] as ContentOutputFile).contents).toEqual(d`
72
+ ).toRenderTo(`
70
73
  # This is a header
71
74
  hello!
75
+ `);
76
+ });
77
+
78
+ describe("format options", () => {
79
+ function FileWithFormatOptions(props: {
80
+ options: CommonFormatOptions;
81
+ children: Children;
82
+ }) {
83
+ return (
84
+ <FormatOptions value={props.options}>
85
+ <SourceFile path="hi.txt" filetype="text">
86
+ {props.children}
87
+ </SourceFile>
88
+ </FormatOptions>
89
+ );
90
+ }
91
+
92
+ it("respect tabWidth", () => {
93
+ expect(
94
+ <FileWithFormatOptions options={{ tabWidth: 5 }}>
95
+ hello
96
+ <Indent>indented 5 spaces</Indent>
97
+ </FileWithFormatOptions>,
98
+ ).toRenderTo(`
99
+ hello
100
+ indented 5 spaces
101
+ `);
102
+ });
103
+
104
+ it("respect useTabs", () => {
105
+ expect(
106
+ <FileWithFormatOptions options={{ useTabs: true }}>
107
+ hello
108
+ <Indent>indented with tabs</Indent>
109
+ </FileWithFormatOptions>,
110
+ ).toRenderTo(`
111
+ hello
112
+ \tindented with tabs
72
113
  `);
114
+ });
115
+
116
+ it("respect printWidth", () => {
117
+ expect(
118
+ <FileWithFormatOptions options={{ printWidth: 10 }}>
119
+ <Prose>this is too long</Prose>
120
+ </FileWithFormatOptions>,
121
+ ).toRenderTo(`
122
+ this is
123
+ too long
124
+ `);
125
+ });
126
+
127
+ it("source file overrides take precedence", () => {
128
+ expect(
129
+ <FormatOptions value={{ tabWidth: 5 }}>
130
+ <SourceFile path="hi.txt" filetype="text" tabWidth={3}>
131
+ hello
132
+ <Indent>indented 3 spaces</Indent>
133
+ </SourceFile>
134
+ </FormatOptions>,
135
+ ).toRenderTo(`
136
+ hello
137
+ indented 3 spaces
138
+ `);
139
+ });
140
+
141
+ describe("trailing line", () => {
142
+ function testRender(comp: any) {
143
+ const tree = render(<Output>{comp}</Output>);
144
+ return (tree.contents[0] as ContentOutputFile).contents;
145
+ }
146
+
147
+ it("add trailing new line by default", () => {
148
+ expect(
149
+ testRender(
150
+ <SourceFile filetype="text" path="abc.txt">
151
+ end with new line
152
+ </SourceFile>,
153
+ ),
154
+ ).toEqual(d`
155
+ end with new line
156
+
157
+ `);
158
+ });
159
+ it("add trailing new line by default", () => {
160
+ expect(
161
+ testRender(
162
+ <SourceFile filetype="text" path="abc.txt" insertFinalNewLine={false}>
163
+ end with no line
164
+ </SourceFile>,
165
+ ),
166
+ ).toEqual(d`
167
+ end with no line
168
+ `);
169
+ });
170
+ });
73
171
  });
@@ -467,6 +467,7 @@ it("formats based on the output component props", () => {
467
467
  4
468
468
  5
469
469
  6
470
+
470
471
  `);
471
472
  });
472
473
 
@@ -489,5 +490,6 @@ it("formats based on the source file component props", () => {
489
490
  4
490
491
  5
491
492
  6
493
+
492
494
  `);
493
495
  });