Skip to content

Commit aa9d809

Browse files
committed
fix tests for TS 6.0.2 strict defaults
1 parent 186df13 commit aa9d809

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+210
-174
lines changed

test/transpile/__snapshots__/module-resolution.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ exports[`supports complicated paths configuration 1`] = `
1010

1111
exports[`supports paths configuration 1`] = `
1212
[
13-
"/paths-simple/myprogram/dist/main.lua",
1413
"/paths-simple/myprogram/dist/mypackage/bar.lua",
1514
"/paths-simple/myprogram/dist/mypackage/index.lua",
15+
"/paths-simple/myprogram/dist/myprogram/main.lua",
1616
]
1717
`;

test/transpile/module-resolution.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,10 @@ describe("module resolution should not try to resolve modules in noResolvePaths"
471471
export function foo(): void;
472472
}`
473473
)
474+
.addExtraFile(
475+
"preload.d.ts",
476+
`declare module "preload" {}`
477+
)
474478
.setOptions({ noResolvePaths: ["ignore*"] })
475479
.expectToHaveNoDiagnostics()
476480
.expectToEqual({ result: "foo" });
@@ -598,7 +602,7 @@ test("module resolution uses baseURL to resolve imported files", () => {
598602
return { baz = function() return "baz" end }
599603
`
600604
)
601-
.setOptions({ baseUrl: "./myproject/mydeps" })
605+
.setOptions({ baseUrl: "./myproject/mydeps", ignoreDeprecations: "6.0" })
602606
.expectToEqual({
603607
fooResult: "foo",
604608
barResult: "bar",

test/transpile/module-resolution/paths-base-tsconfig/tsconfig.base.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"compilerOptions": {
33
"rootDir": ".",
44
"baseUrl": ".",
5+
"ignoreDeprecations": "6.0",
56
"paths": {
67
"mypackage": ["packages/mypackage/src/index.ts"],
78
"mypackage/*": ["packages/mypackage/src/*"]

test/transpile/module-resolution/paths-simple/myprogram/tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"compilerOptions": {
33
"baseUrl": ".",
4+
"ignoreDeprecations": "6.0",
5+
"rootDir": "..",
46
"outDir": "dist",
57
"paths": {
68
"myOtherPackage": ["../mypackage"],

test/transpile/module-resolution/project-with-node-modules/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"target": "esnext",
88
"lib": ["esnext"],
99
"types": [],
10-
"rootDir": "."
10+
"rootDir": ".",
11+
"noUncheckedSideEffectImports": false
1112
}
1213
}

test/unit/__snapshots__/identifiers.spec.ts.snap

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,14 @@ exports[`ambient identifier must be a valid lua identifier ("enum $$ {}"): code
5252

5353
exports[`ambient identifier must be a valid lua identifier ("enum $$ {}"): diagnostics 1`] = `"main.ts(3,9): error TSTL: Invalid ambient identifier name '$$$'. Ambient identifiers must be valid lua identifiers."`;
5454

55-
exports[`ambient identifier must be a valid lua identifier ("function $$();"): code 1`] = `"local ____ = _____24_24_24"`;
55+
exports[`ambient identifier must be a valid lua identifier ("function $$(): void;"): code 1`] = `"local ____ = _____24_24_24"`;
5656

57-
exports[`ambient identifier must be a valid lua identifier ("function $$();"): diagnostics 1`] = `"main.ts(3,9): error TSTL: Invalid ambient identifier name '$$$'. Ambient identifiers must be valid lua identifiers."`;
57+
exports[`ambient identifier must be a valid lua identifier ("function $$(): void;"): diagnostics 1`] = `"main.ts(3,9): error TSTL: Invalid ambient identifier name '$$$'. Ambient identifiers must be valid lua identifiers."`;
5858

5959
exports[`ambient identifier must be a valid lua identifier ("let $$: any;"): code 1`] = `"local ____ = _____24_24_24"`;
6060

6161
exports[`ambient identifier must be a valid lua identifier ("let $$: any;"): diagnostics 1`] = `"main.ts(3,9): error TSTL: Invalid ambient identifier name '$$$'. Ambient identifiers must be valid lua identifiers."`;
6262

63-
exports[`ambient identifier must be a valid lua identifier ("module $$ { export const bar: any; }"): code 1`] = `"local ____ = _____24_24_24"`;
64-
65-
exports[`ambient identifier must be a valid lua identifier ("module $$ { export const bar: any; }"): diagnostics 1`] = `"main.ts(3,9): error TSTL: Invalid ambient identifier name '$$$'. Ambient identifiers must be valid lua identifiers."`;
66-
6763
exports[`ambient identifier must be a valid lua identifier ("namespace $$ { export const bar: any; }"): code 1`] = `"local ____ = _____24_24_24"`;
6864

6965
exports[`ambient identifier must be a valid lua identifier ("namespace $$ { export const bar: any; }"): diagnostics 1`] = `"main.ts(3,9): error TSTL: Invalid ambient identifier name '$$$'. Ambient identifiers must be valid lua identifiers."`;

test/unit/annotations/customConstructor.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ test("CustomCreate", () => {
1111
const tsHeader = `
1212
/** @customConstructor Point2DCreate */
1313
class Point2D {
14-
public x: number;
15-
public y: number;
14+
public x!: number;
15+
public y!: number;
1616
constructor(x: number, y: number) {
1717
// No values assigned
1818
}

test/unit/assignments.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ test.each([
342342

343343
test("local variable declaration referencing self indirectly", () => {
344344
util.testFunction`
345-
let cb: () => void;
345+
let cb!: () => void;
346346
347347
function foo(newCb: () => void) {
348348
cb = newCb;
@@ -360,7 +360,7 @@ test("local variable declaration referencing self indirectly", () => {
360360

361361
test("local multiple variable declaration referencing self indirectly", () => {
362362
util.testFunction`
363-
let cb: () => void;
363+
let cb!: () => void;
364364
365365
function foo(newCb: () => void) {
366366
cb = newCb;
@@ -395,7 +395,7 @@ describe.each(["x &&= y", "x ||= y"])("boolean compound assignment (%p)", assign
395395

396396
test.each([undefined, 3])("nullish coalescing compound assignment", initialValue => {
397397
util.testFunction`
398-
let x: number = ${util.formatCode(initialValue)};
398+
let x: number | undefined = ${util.formatCode(initialValue)};
399399
x ??= 5;
400400
return x;
401401
`.expectToMatchJsResult();

test/unit/builtins/array.spec.ts

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ test("array.forEach (%p)", () => {
316316
});
317317

318318
test.each([
319-
{ array: [], predicate: "elem > 3" },
319+
{ array: [] as number[], predicate: "elem > 3" },
320320
{ array: [0, 2, 4, 8], predicate: "elem > 10" },
321321
{ array: [0, 2, 4, 8], predicate: "elem > 7" },
322322
{ array: [0, 2, 4, 8], predicate: "elem == 0" },
@@ -325,19 +325,19 @@ test.each([
325325
{ array: [0, 2, 4, 8], predicate: "false" },
326326
])("array.find (%p)", ({ array, predicate }) => {
327327
util.testFunction`
328-
const array = ${util.formatCode(array)};
328+
const array: number[] = ${util.formatCode(array)};
329329
return array.find((elem, index, arr) => ${predicate} && arr[index] === elem);
330330
`.expectToMatchJsResult();
331331
});
332332

333333
test.each([
334-
{ array: [], searchElement: 3 },
334+
{ array: [] as number[], searchElement: 3 },
335335
{ array: [0, 2, 4, 8], searchElement: 10 },
336336
{ array: [0, 2, 4, 8], searchElement: 0 },
337337
{ array: [0, 2, 4, 8], searchElement: 8 },
338338
])("array.findIndex (%p)", ({ array, searchElement }) => {
339339
util.testFunction`
340-
const array = ${util.formatCode(array)};
340+
const array: number[] = ${util.formatCode(array)};
341341
return array.findIndex((elem, index, arr) => elem === ${searchElement} && arr[index] === elem);
342342
`.expectToMatchJsResult();
343343
});
@@ -399,7 +399,7 @@ test.each([
399399

400400
test.each([
401401
// Insert
402-
{ array: [], start: 0, deleteCount: 0, newElements: [9, 10, 11] },
402+
{ array: [] as number[], start: 0, deleteCount: 0, newElements: [9, 10, 11] },
403403
{ array: [0, 1, 2, 3], start: 1, deleteCount: 0, newElements: [9, 10, 11] },
404404
{ array: [0, 1, 2, 3], start: 2, deleteCount: 2, newElements: [9, 10, 11] },
405405
{ array: [0, 1, 2, 3], start: 4, deleteCount: 1, newElements: [8, 9] },
@@ -413,17 +413,19 @@ test.each([
413413
{ array: [0, 1, 2, 3, 4, 5, 6, 7, 8], start: 5, deleteCount: null, newElements: [10, 11] },
414414

415415
// Remove
416-
{ array: [], start: 1, deleteCount: 1 },
416+
{ array: [] as number[], start: 1, deleteCount: 1 },
417417
{ array: [0, 1, 2, 3], start: 1, deleteCount: 1 },
418418
{ array: [0, 1, 2, 3], start: 10, deleteCount: 1 },
419419
{ array: [0, 1, 2, 3, 4, 5], start: 2, deleteCount: 2 },
420420
{ array: [0, 1, 2, 3, 4, 5], start: -3, deleteCount: 2 },
421421
{ array: [0, 1, 2, 3], start: 1, deleteCount: undefined },
422422
{ array: [0, 1, 2, 3], start: 1, deleteCount: null },
423423
])("array.splice (%p)", ({ array, start, deleteCount, newElements = [] }) => {
424+
const deleteCountCode = deleteCount === undefined ? "undefined as any" : deleteCount === null ? "null as any" : util.formatCode(deleteCount);
425+
const newElementsCode = newElements.length > 0 ? ", " + util.formatCode(...newElements) : "";
424426
util.testFunction`
425-
const array = ${util.formatCode(array)};
426-
array.splice(${util.formatCode(start, deleteCount, ...newElements)});
427+
const array: number[] = ${util.formatCode(array)};
428+
array.splice(${util.formatCode(start)}, ${deleteCountCode}${newElementsCode});
427429
return array;
428430
`.expectToMatchJsResult();
429431
});
@@ -511,7 +513,6 @@ test("array.join without separator argument", () => {
511513
});
512514

513515
test.each([
514-
{ array: [], args: ["test1"] },
515516
{ array: ["test1"], args: ["test1"] },
516517
{ array: ["test1", "test2"], args: ["test2"] },
517518
{ array: ["test1", "test2", "test3"], args: ["test3", 1] },
@@ -522,6 +523,10 @@ test.each([
522523
util.testExpression`${util.formatCode(array)}.indexOf(${util.formatCode(...args)})`.expectToMatchJsResult();
523524
});
524525

526+
test("array.indexOf empty array", () => {
527+
util.testExpression`([] as string[]).indexOf("test1")`.expectToMatchJsResult();
528+
});
529+
525530
test.each([
526531
{ args: "1" },
527532
{ args: "1, 2, 3" },
@@ -567,41 +572,41 @@ test.each([
567572
`.expectToEqual(expected);
568573
});
569574

570-
test.each([{ array: [1, 2, 3] }, { array: [1, 2, 3, 4] }, { array: [1] }, { array: [] }])(
575+
test.each([{ array: [1, 2, 3] }, { array: [1, 2, 3, 4] }, { array: [1] }, { array: [] as number[] }])(
571576
"array.reverse (%p)",
572577
({ array }) => {
573578
util.testFunction`
574-
const array = ${util.formatCode(array)};
579+
const array: number[] = ${util.formatCode(array)};
575580
array.reverse();
576581
return array;
577582
`.expectToMatchJsResult();
578583
}
579584
);
580585

581-
test.each([{ array: [1, 2, 3] }, { array: [1] }, { array: [] }])("array.shift (%p)", ({ array }) => {
586+
test.each([{ array: [1, 2, 3] }, { array: [1] }, { array: [] as number[] }])("array.shift (%p)", ({ array }) => {
582587
util.testFunction`
583-
const array = ${util.formatCode(array)};
588+
const array: number[] = ${util.formatCode(array)};
584589
const value = array.shift();
585590
return { array, value };
586591
`.expectToMatchJsResult();
587592
});
588593

589594
test.each([
590595
{ array: [3, 4, 5], args: [1, 2] },
591-
{ array: [], args: [] },
596+
{ array: [] as number[], args: [] },
592597
{ array: [1], args: [] },
593-
{ array: [], args: [1] },
598+
{ array: [] as number[], args: [1] },
594599
])("array.unshift (%p)", ({ array, args }) => {
595600
util.testFunction`
596-
const array = ${util.formatCode(array)};
601+
const array: number[] = ${util.formatCode(array)};
597602
const value = array.unshift(${util.formatCode(...args)});
598603
return { array, value };
599604
`.expectToMatchJsResult();
600605
});
601606

602-
test.each([{ array: [4, 5, 3, 2, 1] }, { array: [1] }, { array: [] }])("array.sort (%p)", ({ array }) => {
607+
test.each([{ array: [4, 5, 3, 2, 1] }, { array: [1] }, { array: [] as number[] }])("array.sort (%p)", ({ array }) => {
603608
util.testFunctionTemplate`
604-
const array = ${array};
609+
const array: number[] = ${array};
605610
array.sort();
606611
return array;
607612
`.expectToMatchJsResult();
@@ -659,7 +664,7 @@ describe.each(["reduce", "reduceRight"])("array.%s", reduce => {
659664
});
660665

661666
test("empty no initial", () => {
662-
util.testExpression`[].${reduce}(() => {})`.expectToMatchJsResult(true);
667+
util.testExpression`([] as any[]).${reduce}(() => {})`.expectToMatchJsResult(true);
663668
});
664669

665670
test("undefined returning callback", () => {
@@ -671,11 +676,11 @@ describe.each(["reduce", "reduceRight"])("array.%s", reduce => {
671676
});
672677
});
673678

674-
test.each([{ array: [] }, { array: ["a", "b", "c"] }, { array: [{ foo: "foo" }, { bar: "bar" }] }])(
679+
test.each([{ array: [] as any[] }, { array: ["a", "b", "c"] }, { array: [{ foo: "foo" }, { bar: "bar" }] }])(
675680
"array.entries (%p)",
676681
({ array }) => {
677682
util.testFunction`
678-
const array = ${util.formatCode(array)};
683+
const array: any[] = ${util.formatCode(array)};
679684
const result = [];
680685
for (const [i, v] of array.entries()) {
681686
result.push([i, v]);
@@ -800,7 +805,7 @@ test.each([
800805
});
801806

802807
describe("array.fill", () => {
803-
test.each(["[]", "[1]", "[1,2,3,4]"])("Fills full length of array without other parameters (%p)", arr => {
808+
test.each(["([] as number[])", "[1]", "[1,2,3,4]"])("Fills full length of array without other parameters (%p)", arr => {
804809
util.testExpression`${arr}.fill(5)`.expectToMatchJsResult();
805810
});
806811

test/unit/builtins/async-await.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ test("high amount of chained awaits doesn't cause stack overflow", () => {
3838
await delay();
3939
}
4040
result = "success";
41-
} catch (e) {
41+
} catch (e: any) {
4242
result = e;
4343
}
4444
}
@@ -51,7 +51,7 @@ test("high amount of chained awaits doesn't cause stack overflow", () => {
5151

5252
test("can await already resolved promise", () => {
5353
util.testFunction`
54-
const result = [];
54+
const result: number[] = [];
5555
async function abc() {
5656
return await Promise.resolve(30);
5757
}
@@ -63,7 +63,7 @@ test("can await already resolved promise", () => {
6363

6464
test("can await already rejected promise", () => {
6565
util.testFunction`
66-
const result = [];
66+
const result: string[] = [];
6767
async function abc() {
6868
return await Promise.reject("test rejection");
6969
}
@@ -604,7 +604,7 @@ describe("try/catch in async function", () => {
604604
() =>
605605
util.testModule`
606606
export let reason = "";
607-
let reject: (reason: string) => void;
607+
let reject: (reason: string) => void = () => {};
608608
609609
async function foo(): Promise<number> {
610610
try {
@@ -675,6 +675,7 @@ describe("try/catch in async function", () => {
675675
}
676676
catch
677677
{
678+
return "" as string;
678679
}
679680
}
680681

0 commit comments

Comments
 (0)