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

Function TestInjectSideEffectImport

imports_test.go:142–170  ·  view source on GitHub ↗

TestInjectSideEffectImport exercises the bare-import form, deduplication, and per-module placement against a clausal import for the same module.

(t *testing.T)

Source from the content-addressed store, hash-verified

140// TestInjectSideEffectImport exercises the bare-import form, deduplication,
141// and per-module placement against a clausal import for the same module.
142func TestInjectSideEffectImport(t *testing.T) {
143 t.Parallel()
144
145 ts := loadTypescript(t)
146 ts.ApplyMutations(
147 config.InjectImport("zod", "z"),
148 config.InjectSideEffectImport("./polyfill"),
149 // Second call must dedupe.
150 config.InjectSideEffectImport("./polyfill"),
151 // Side-effect for a module that also has a clausal import. Side-effect
152 // goes before the clausal import for the same module.
153 config.InjectSideEffectImport("zod"),
154 )
155 output, err := ts.Serialize()
156 require.NoError(t, err, "serialize")
157
158 block := importBlock(t, output)
159 require.Contains(t, block, `import "./polyfill";`,
160 "side-effect import must emit with no clause")
161 require.Equal(t, 1, strings.Count(block, `import "./polyfill";`),
162 "side-effect imports must dedupe per module")
163
164 sideZodIdx := strings.Index(block, `import "zod";`)
165 clausalZodIdx := strings.Index(block, `import { z } from "zod";`)
166 require.GreaterOrEqual(t, sideZodIdx, 0, "side-effect zod import must appear")
167 require.GreaterOrEqual(t, clausalZodIdx, 0, "clausal zod import must appear")
168 require.Less(t, sideZodIdx, clausalZodIdx,
169 "side-effect import must precede clausal import for the same module")
170}

Callers

nothing calls this directly

Calls 6

InjectImportFunction · 0.92
InjectSideEffectImportFunction · 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…