MCPcopy Create free account
hub / github.com/coder/guts / TestInjectImport_Merge

Function TestInjectImport_Merge

imports_test.go:52–68  ·  view source on GitHub ↗

TestInjectImport_Merge proves that repeated InjectImport calls for the same module collapse into a single statement and that specifiers are sorted by name regardless of the order they were appended.

(t *testing.T)

Source from the content-addressed store, hash-verified

50// module collapse into a single statement and that specifiers are sorted by
51// name regardless of the order they were appended.
52func TestInjectImport_Merge(t *testing.T) {
53 t.Parallel()
54
55 ts := loadTypescript(t)
56 ts.ApplyMutations(
57 config.InjectImport("zod", "z"),
58 config.InjectImport("zod", "AnyZod"),
59 )
60 output, err := ts.Serialize()
61 require.NoError(t, err, "serialize")
62
63 require.Contains(t, importBlock(t, output),
64 `import { AnyZod, z } from "zod";`,
65 "merged value import must include both specifiers in sorted order")
66 require.Equal(t, 1, strings.Count(output, `from "zod"`),
67 "zod import must be merged")
68}
69
70// TestInjectImport_AliasAndType exercises the "Name=Alias" specifier shorthand
71// and the type-only declaration form together.

Callers

nothing calls this directly

Calls 5

InjectImportFunction · 0.92
loadTypescriptFunction · 0.85
importBlockFunction · 0.85
ApplyMutationsMethod · 0.80
SerializeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…