Skip to content

Commit 41f58d9

Browse files
committed
Test incremental edit
// Options are always detected as changed so everything is refreshed on incremental build
1 parent 5e01867 commit 41f58d9

File tree

5 files changed

+991
-27
lines changed

5 files changed

+991
-27
lines changed

internal/execute/testsys_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,12 @@ func (s *testSys) WriteFileNoError(path string, content string, writeByteOrderMa
313313
panic(err)
314314
}
315315
}
316+
317+
func (s *testSys) ReplaceFileText(path string, oldText string, newText string) {
318+
content, ok := s.FS().ReadFile(path)
319+
if !ok {
320+
panic("File not found: " + path)
321+
}
322+
content = strings.Replace(content, oldText, newText, 1)
323+
s.WriteFileNoError(path, content, false)
324+
}

internal/execute/tscincremental_test.go

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,23 @@ func TestIncremental(t *testing.T) {
7171
type InstanceType<T extends abstract new (...args: any) => any> = T extends abstract new (...args: any) => infer R ? R : any;`,
7272
}, "/home/src/workspaces/project"),
7373
commandLineArgs: []string{"--incremental"},
74-
// edits: [
75-
// noChangeRun,
76-
// {
77-
// caption: "modify public to protected",
78-
// edit: sys => sys.replaceFileText("/home/src/workspaces/project/MessageablePerson.ts", "public", "protected"),
79-
// },
80-
// noChangeRun,
81-
// {
82-
// caption: "modify protected to public",
83-
// edit: sys => sys.replaceFileText("/home/src/workspaces/project/MessageablePerson.ts", "protected", "public"),
84-
// },
85-
// noChangeRun,
86-
// ],
74+
edits: []*testTscEdit{
75+
noChange,
76+
{
77+
caption: "modify public to protected",
78+
edit: func(sys *testSys) {
79+
sys.ReplaceFileText("/home/src/workspaces/project/MessageablePerson.ts", "public", "protected")
80+
},
81+
},
82+
noChange,
83+
{
84+
caption: "modify protected to public",
85+
edit: func(sys *testSys) {
86+
sys.ReplaceFileText("/home/src/workspaces/project/MessageablePerson.ts", "protected", "public")
87+
},
88+
},
89+
noChange,
90+
},
8791
},
8892
{
8993
subScenario: "change to modifier of class expression field",
@@ -108,19 +112,23 @@ func TestIncremental(t *testing.T) {
108112
type InstanceType<T extends abstract new (...args: any) => any> = T extends abstract new (...args: any) => infer R ? R : any;`,
109113
}, "/home/src/workspaces/project"),
110114
commandLineArgs: []string{"--incremental"},
111-
// edits: [
112-
// noChangeRun,
113-
// {
114-
// caption: "modify public to protected",
115-
// edit: sys => sys.replaceFileText("/home/src/workspaces/project/MessageablePerson.ts", "public", "protected"),
116-
// },
117-
// noChangeRun,
118-
// {
119-
// caption: "modify protected to public",
120-
// edit: sys => sys.replaceFileText("/home/src/workspaces/project/MessageablePerson.ts", "protected", "public"),
121-
// },
122-
// noChangeRun,
123-
// ],
115+
edits: []*testTscEdit{
116+
noChange,
117+
{
118+
caption: "modify public to protected",
119+
edit: func(sys *testSys) {
120+
sys.ReplaceFileText("/home/src/workspaces/project/MessageablePerson.ts", "public", "protected")
121+
},
122+
},
123+
noChange,
124+
{
125+
caption: "modify protected to public",
126+
edit: func(sys *testSys) {
127+
sys.ReplaceFileText("/home/src/workspaces/project/MessageablePerson.ts", "protected", "public")
128+
},
129+
},
130+
noChange,
131+
},
124132
},
125133
}
126134

internal/execute/tsctestrunner_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"strings"
99
"testing"
1010

11+
"github.com/microsoft/typescript-go/internal/core"
1112
"github.com/microsoft/typescript-go/internal/execute"
1213
"github.com/microsoft/typescript-go/internal/incremental"
1314
"github.com/microsoft/typescript-go/internal/testutil/baseline"
@@ -19,6 +20,11 @@ type testTscEdit struct {
1920
edit func(*testSys)
2021
}
2122

23+
var noChange = &testTscEdit{
24+
caption: "no change",
25+
edit: func(sys *testSys) {},
26+
}
27+
2228
type tscInput struct {
2329
subScenario string
2430
commandLineArgs []string
@@ -50,7 +56,7 @@ func (test *tscInput) run(t *testing.T, scenario string) {
5056

5157
var incrementalProgram *incremental.Program
5258
if watcher == nil {
53-
exit, parsedCommandLine, incrementalProgram, watcher = execute.CommandLine(test.sys, test.commandLineArgs, true)
59+
exit, parsedCommandLine, incrementalProgram, watcher = execute.CommandLine(test.sys, core.IfElse(do.commandLineArgs == nil, test.commandLineArgs, do.commandLineArgs), true)
5460
baselineBuilder.WriteString("ExitStatus:: " + fmt.Sprint(exit))
5561
} else {
5662
watcher.DoCycle()

0 commit comments

Comments
 (0)