Skip to content

Commit 12fcf2d

Browse files
committed
Reverted toHaveDiagnostics change
1 parent 89f8d72 commit 12fcf2d

File tree

10 files changed

+48
-42
lines changed

10 files changed

+48
-42
lines changed

test/cli/parse.spec.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe("command line", () => {
1212
const commandLine = "--project tsconfig.json --noHeader -t es3 -lt 5.3";
1313
const result = tstl.parseCommandLine(commandLine.split(" "));
1414

15-
expect(result.errors).not.toHaveErrorDiagnostics();
15+
expect(result.errors).not.toHaveDiagnostics();
1616
expect(result.options).toEqual({
1717
project: "tsconfig.json",
1818
noHeader: true,
@@ -24,75 +24,75 @@ describe("command line", () => {
2424
test("should error on unknown options", () => {
2525
const result = tstl.parseCommandLine(["--unknownOption"]);
2626

27-
expect(result.errors).toHaveErrorDiagnostics();
27+
expect(result.errors).toHaveDiagnostics();
2828
});
2929

3030
test("should parse options case-insensitively", () => {
3131
const result = tstl.parseCommandLine(["--NoHeader"]);
3232

33-
expect(result.errors).not.toHaveErrorDiagnostics();
33+
expect(result.errors).not.toHaveDiagnostics();
3434
expect(result.options.noHeader).toBe(true);
3535
});
3636

3737
describe("enum options", () => {
3838
test("should parse enums", () => {
3939
const result = tstl.parseCommandLine(["--luaTarget", "5.1"]);
4040

41-
expect(result.errors).not.toHaveErrorDiagnostics();
41+
expect(result.errors).not.toHaveDiagnostics();
4242
expect(result.options.luaTarget).toBe(tstl.LuaTarget.Lua51);
4343
});
4444

4545
test("should be case-insensitive", () => {
4646
for (const value of ["jit", "JiT", "JIT"]) {
4747
const result = tstl.parseCommandLine(["--luaTarget", value]);
4848

49-
expect(result.errors).not.toHaveErrorDiagnostics();
49+
expect(result.errors).not.toHaveDiagnostics();
5050
expect(result.options.luaTarget).toBe(tstl.LuaTarget.LuaJIT);
5151
}
5252
});
5353

5454
test("should error on invalid value", () => {
5555
const result = tstl.parseCommandLine(["--luaTarget", "invalid"]);
5656

57-
expect(result.errors).toHaveErrorDiagnostics();
57+
expect(result.errors).toHaveDiagnostics();
5858
});
5959
});
6060

6161
describe("boolean options", () => {
6262
test.each([true, false])("should parse booleans (%p)", value => {
6363
const result = tstl.parseCommandLine(["--noHeader", value.toString()]);
6464

65-
expect(result.errors).not.toHaveErrorDiagnostics();
65+
expect(result.errors).not.toHaveDiagnostics();
6666
expect(result.options.noHeader).toBe(value);
6767
});
6868

6969
test("should be case-sensitive", () => {
7070
const result = tstl.parseCommandLine(["--noHeader", "FALSE"]);
7171

72-
expect(result.errors).not.toHaveErrorDiagnostics();
72+
expect(result.errors).not.toHaveDiagnostics();
7373
expect(result.options.noHeader).toBe(true);
7474
expect(result.fileNames).toEqual(["FALSE"]);
7575
});
7676

7777
test("should be parsed without a value", () => {
7878
const result = tstl.parseCommandLine(["--noHeader"]);
7979

80-
expect(result.errors).not.toHaveErrorDiagnostics();
80+
expect(result.errors).not.toHaveDiagnostics();
8181
expect(result.options.noHeader).toBe(true);
8282
});
8383

8484
test("shouldn't parse following arguments as values", () => {
8585
const result = tstl.parseCommandLine(["--noHeader", "--noHoisting"]);
8686

87-
expect(result.errors).not.toHaveErrorDiagnostics();
87+
expect(result.errors).not.toHaveDiagnostics();
8888
expect(result.options.noHeader).toBe(true);
8989
expect(result.options.noHoisting).toBe(true);
9090
});
9191

9292
test("shouldn't parse following files as values", () => {
9393
const result = tstl.parseCommandLine(["--noHeader", "file.ts"]);
9494

95-
expect(result.errors).not.toHaveErrorDiagnostics();
95+
expect(result.errors).not.toHaveDiagnostics();
9696
expect(result.options.noHeader).toBe(true);
9797
});
9898
});
@@ -121,7 +121,7 @@ describe("command line", () => {
121121
])("--%s %s", (optionName, value, expected) => {
122122
const result = tstl.parseCommandLine([`--${optionName}`, value]);
123123

124-
expect(result.errors).not.toHaveErrorDiagnostics();
124+
expect(result.errors).not.toHaveDiagnostics();
125125
expect(result.options).toEqual(expected);
126126
});
127127
});
@@ -146,21 +146,21 @@ describe("tsconfig", () => {
146146
test("should allow unknown root-level options", () => {
147147
const result = parseConfigFileContent({ unknownOption: true });
148148

149-
expect(result.errors).not.toHaveErrorDiagnostics();
149+
expect(result.errors).not.toHaveDiagnostics();
150150
expect(result.options.unknownOption).toBeUndefined();
151151
});
152152

153153
test("should error on unknown namespaced options", () => {
154154
const result = parseConfigFileContent({ tstl: { unknownOption: true } });
155155

156-
expect(result.errors).toHaveErrorDiagnostics();
156+
expect(result.errors).toHaveDiagnostics();
157157
expect(result.options.unknownOption).toBeUndefined();
158158
});
159159

160160
test("should parse options case-sensitively", () => {
161161
const result = parseConfigFileContent({ tstl: { NoHeader: true } });
162162

163-
expect(result.errors).toHaveErrorDiagnostics();
163+
expect(result.errors).toHaveDiagnostics();
164164
expect(result.options.NoHeader).toBeUndefined();
165165
expect(result.options.noHeader).toBeUndefined();
166166
});
@@ -169,38 +169,38 @@ describe("tsconfig", () => {
169169
test("should parse enums", () => {
170170
const result = parseConfigFileContent({ tstl: { luaTarget: "5.1" } });
171171

172-
expect(result.errors).not.toHaveErrorDiagnostics();
172+
expect(result.errors).not.toHaveDiagnostics();
173173
expect(result.options.luaTarget).toBe(tstl.LuaTarget.Lua51);
174174
});
175175

176176
test("should be case-insensitive", () => {
177177
for (const value of ["jit", "JiT", "JIT"]) {
178178
const result = parseConfigFileContent({ tstl: { luaTarget: value } });
179179

180-
expect(result.errors).not.toHaveErrorDiagnostics();
180+
expect(result.errors).not.toHaveDiagnostics();
181181
expect(result.options.luaTarget).toBe(tstl.LuaTarget.LuaJIT);
182182
}
183183
});
184184

185185
test("should error on invalid value", () => {
186186
const result = parseConfigFileContent({ tstl: { luaTarget: "invalid" } });
187187

188-
expect(result.errors).toHaveErrorDiagnostics();
188+
expect(result.errors).toHaveDiagnostics();
189189
});
190190
});
191191

192192
describe("boolean options", () => {
193193
test.each([true, false])("should parse booleans (%p)", value => {
194194
const result = parseConfigFileContent({ tstl: { noHeader: value } });
195195

196-
expect(result.errors).not.toHaveErrorDiagnostics();
196+
expect(result.errors).not.toHaveDiagnostics();
197197
expect(result.options.noHeader).toBe(value);
198198
});
199199

200200
test("shouldn't parse strings", () => {
201201
const result = parseConfigFileContent({ tstl: { noHeader: "true" } });
202202

203-
expect(result.errors).toHaveErrorDiagnostics();
203+
expect(result.errors).toHaveDiagnostics();
204204
expect(result.options.noHeader).toBeUndefined();
205205
});
206206
});
@@ -229,7 +229,7 @@ describe("tsconfig", () => {
229229
])("{ %p: %p }", (optionName, value, expected) => {
230230
const result = parseConfigFileContent({ tstl: { [optionName]: value } });
231231

232-
expect(result.errors).not.toHaveErrorDiagnostics();
232+
expect(result.errors).not.toHaveDiagnostics();
233233
expect(result.options).toEqual(expected);
234234
});
235235
});

test/cli/tsconfig.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ describe("inferred", () => {
7979

8080
describe("errors", () => {
8181
test("specified file does not exist", () => {
82-
expect([locate("tsconfig.json")]).toHaveErrorDiagnostics();
82+
expect([locate("tsconfig.json")]).toHaveDiagnostics();
8383
});
8484

8585
test("specified directory does not exist", () => {
86-
expect([locate("project")]).toHaveErrorDiagnostics();
86+
expect([locate("project")]).toHaveDiagnostics();
8787
});
8888

8989
test("cannot be mixed", async () => {
9090
await fs.outputFile("tsconfig.json", "");
91-
expect([locate("tsconfig.json", [""])]).toHaveErrorDiagnostics();
91+
expect([locate("tsconfig.json", [""])]).toHaveDiagnostics();
9292
});
9393
});

test/legacy-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function transpileString(
1414
expect(file.lua).toBeDefined();
1515

1616
const errors = diagnostics.filter(d => !ignoreDiagnostics || d.source === "typescript-to-lua");
17-
expect(errors).not.toHaveErrorDiagnostics();
17+
expect(errors).not.toHaveDiagnostics();
1818

1919
return file.lua!.trim();
2020
}

test/setup.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ declare global {
55
namespace jest {
66
interface Matchers<R> {
77
toThrowExactError(error: Error): R;
8-
toHaveErrorDiagnostics(): R;
8+
toHaveDiagnostics(): R;
99
}
1010
}
1111
}
@@ -30,7 +30,7 @@ expect.extend({
3030

3131
return { pass: true, message: () => "" };
3232
},
33-
toHaveErrorDiagnostics(diagnostics: ts.Diagnostic[]): jest.CustomMatcherResult {
33+
toHaveDiagnostics(diagnostics: ts.Diagnostic[]): jest.CustomMatcherResult {
3434
expect(diagnostics).toBeInstanceOf(Array);
3535
// @ts-ignore
3636
const matcherHint = this.utils.matcherHint("toHaveErrorDiagnostics", undefined, "", this);
@@ -42,7 +42,7 @@ expect.extend({
4242
});
4343

4444
return {
45-
pass: diagnostics.filter(d => d.category === ts.DiagnosticCategory.Error).length > 0,
45+
pass: diagnostics.length > 0,
4646
message: () => {
4747
return (
4848
matcherHint +

test/transpile/bundle.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const inputProject = path.join(projectDir, "tsconfig.json");
88
test("should transpile into one file", () => {
99
const transpileResult = transpileProject(inputProject);
1010

11-
expect(transpileResult.diagnostics).not.toHaveErrorDiagnostics();
11+
expect(transpileResult.diagnostics).not.toHaveDiagnostics();
1212
expect(transpileResult.emitResult.length).toBe(1);
1313

1414
const { name, text } = transpileResult.emitResult[0];

test/transpile/directories.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ test.each<DirectoryTestCase>([
2828
);
2929

3030
const { diagnostics, emittedFiles } = buildVirtualProject(fileNames, options);
31-
expect(diagnostics).not.toHaveErrorDiagnostics();
31+
expect(diagnostics).not.toHaveDiagnostics();
3232
expect(emittedFiles).toMatchSnapshot();
3333
});

test/transpile/project.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const inputProject = path.join(projectDir, "tsconfig.json");
77
test("should transpile", () => {
88
const transpileResult = transpileProject(inputProject);
99

10-
expect(transpileResult.diagnostics).not.toHaveErrorDiagnostics();
10+
expect(transpileResult.diagnostics).not.toHaveDiagnostics();
1111

1212
// Check output paths relative to projectDir
1313
const relativeResult = transpileResult.emitResult.map(({ name, text }) => ({

test/unit/bundle.spec.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,22 @@ test("entry point in directory", () => {
8787
.expectToEqual({ value: true });
8888
});
8989

90-
test.each([LuaLibImportKind.Inline, LuaLibImportKind.Require])("LuaLibs", lualibOption => {
91-
util.testBundle`
90+
test.each([LuaLibImportKind.Inline, LuaLibImportKind.Require])("LuaLib %p", lualibOption => {
91+
const testBundle = util.testBundle`
9292
export const result = [1, 2];
9393
result.push(3);
94-
`
95-
.setOptions({ luaLibImport: lualibOption })
96-
.expectToEqual({ result: [1, 2, 3] });
94+
`.setOptions({ luaLibImport: lualibOption });
95+
96+
if (lualibOption === LuaLibImportKind.Inline) {
97+
testBundle.expectToHaveDiagnostic(d => d.category === DiagnosticCategory.Warning);
98+
} else {
99+
expect(testBundle.getLuaResult().diagnostics).toEqual([]);
100+
}
101+
expect(testBundle.getLuaExecutionResult()).toEqual({ result: [1, 2, 3] });
97102
});
98103

99104
test("LuaBundle and LuaLibImport.Inline generate warning", () => {
100-
util.testBundle`
105+
const testBundle = util.testBundle`
101106
export const result = [1, 2];
102107
result.push(3);
103108
`
@@ -108,8 +113,9 @@ test("LuaBundle and LuaLibImport.Inline generate warning", () => {
108113
d.messageText ===
109114
`Using 'luaBundle' with 'luaLibImport: "inline"' might generate duplicate code. ` +
110115
`It is recommended to use 'luaLibImport: "require"'`
111-
)
112-
.expectToEqual({ result: [1, 2, 3] }); // Result should still be the same
116+
);
117+
118+
expect(testBundle.getLuaExecutionResult()).toEqual({ result: [1, 2, 3] }); // Result should still be the same
113119
});
114120

115121
test("cyclic imports", () => {

test/unit/transformers/transformers.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe("resolution", () => {
4444
const transform = path.join(__dirname, "error.ts");
4545
const options = optionsOfTransformer({ transform });
4646
const { diagnostics } = util.transpileStringResult("", options);
47-
expect(diagnostics).toHaveErrorDiagnostics();
47+
expect(diagnostics).toHaveDiagnostics();
4848
});
4949
});
5050

test/util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ export abstract class TestBuilder {
351351
}
352352

353353
public expectToHaveErrorDiagnostics(): this {
354-
expect(this.getLuaDiagnostics()).toHaveErrorDiagnostics();
354+
expect(this.getLuaDiagnostics()).toHaveDiagnostics();
355355
return this;
356356
}
357357

@@ -364,7 +364,7 @@ export abstract class TestBuilder {
364364
}
365365

366366
public expectToHaveNoErrorDiagnostics(): this {
367-
expect(this.getLuaDiagnostics()).not.toHaveErrorDiagnostics();
367+
expect(this.getLuaDiagnostics()).not.toHaveDiagnostics();
368368
return this;
369369
}
370370

0 commit comments

Comments
 (0)