| 92 | } |
| 93 | |
| 94 | func TestNodeModules(t *testing.T) { |
| 95 | is := is.New(t) |
| 96 | log := testlog.New() |
| 97 | ctx := context.Background() |
| 98 | dir := t.TempDir() |
| 99 | td := testdir.New(dir) |
| 100 | td.Files["view/index.svelte"] = `<h1>hi world</h1>` |
| 101 | td.NodeModules["svelte"] = versions.Svelte |
| 102 | is.NoErr(td.Write(ctx)) |
| 103 | module, err := gomod.Find(dir) |
| 104 | is.NoErr(err) |
| 105 | gfs := genfs.New(dag.Discard, module, log) |
| 106 | gfs.FileServer("bud/node_modules", nodemodules.New(module)) |
| 107 | // Read the re-written node_modules |
| 108 | code, err := fs.ReadFile(gfs, "bud/node_modules/svelte/internal") |
| 109 | is.NoErr(err) |
| 110 | is.True(strings.Contains(string(code), `function element(`)) |
| 111 | is.True(strings.Contains(string(code), `function text(`)) |
| 112 | } |
| 113 | |
| 114 | func TestGenerateDir(t *testing.T) { |
| 115 | is := is.New(t) |