Skip to content

Commit 052ac1f

Browse files
committed
Fix few tests
1 parent 5bcafb9 commit 052ac1f

5 files changed

Lines changed: 31 additions & 46 deletions

File tree

test/cli/errors.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import * as fs from "fs";
2-
import * as path from "path";
3-
import { runCli } from "./run";
2+
import { resolveFixture, runCli } from "./run";
43

5-
const srcFilePath = path.resolve(__dirname, "errors", "error.ts");
6-
const outFilePath = path.resolve(__dirname, "errors", "error.lua");
4+
const srcFilePath = resolveFixture("errors/error.ts");
5+
const outFilePath = resolveFixture("errors/error.lua");
76
const errorMessage = "Unable to convert function with no 'this' parameter to function with 'this'.";
87

98
afterEach(() => {

test/cli/watch.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function forkWatchProcess(args: string[]): void {
2626
}
2727

2828
const watchedFile = resolveFixture("watch/watch.ts");
29-
const watchedFileOut = watchedFile.replace(".ts", ".lua");
29+
const watchedFileOut = resolveFixture("watch/watch.lua");
3030

3131
afterEach(() => fs.removeSync(watchedFileOut));
3232

test/transpile/__snapshots__/directories.spec.ts.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,31 @@
33
exports[`should be able to resolve ({"name": "basic", "options": [Object]}) 1`] = `
44
Array [
55
"directories/basic/src/lib/file.lua",
6-
"directories/basic/src/lualib/lualib_bundle.lua",
6+
"directories/basic/src/lualib_bundle.lua",
77
"directories/basic/src/main.lua",
88
]
99
`;
1010

1111
exports[`should be able to resolve ({"name": "basic", "options": [Object]}) 2`] = `
1212
Array [
1313
"directories/basic/out/lib/file.lua",
14-
"directories/basic/out/lualib/lualib_bundle.lua",
14+
"directories/basic/out/lualib_bundle.lua",
1515
"directories/basic/out/main.lua",
1616
]
1717
`;
1818

1919
exports[`should be able to resolve ({"name": "basic", "options": [Object]}) 3`] = `
2020
Array [
2121
"directories/basic/src/lib/file.lua",
22-
"directories/basic/src/lualib/lualib_bundle.lua",
22+
"directories/basic/src/lualib_bundle.lua",
2323
"directories/basic/src/main.lua",
2424
]
2525
`;
2626

2727
exports[`should be able to resolve ({"name": "basic", "options": [Object]}) 4`] = `
2828
Array [
2929
"directories/basic/out/lib/file.lua",
30-
"directories/basic/out/lualib/lualib_bundle.lua",
30+
"directories/basic/out/lualib_bundle.lua",
3131
"directories/basic/out/main.lua",
3232
]
3333
`;

test/unit/functions/noImplicitSelfOption.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ test("generates declaration files with @noSelfInFile", () => {
3232
util.assert(fooDeclaration !== undefined);
3333

3434
util.testModule`
35-
import { bar } from "./foo.d";
36-
const test: (this: void) => void = bar;
35+
import type { bar } from "./foo";
36+
const test: (this: void) => void = undefined as typeof bar;
3737
`
3838
.addExtraFile("foo.d.ts", fooDeclaration)
3939
.expectToHaveNoDiagnostics();

test/unit/identifiers.spec.ts

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -455,18 +455,13 @@ describe("lua keyword as identifier doesn't interfere with lua's value", () => {
455455
});
456456

457457
test("variable (require)", () => {
458-
const code = `
459-
const require = "foobar";
460-
export { foo } from "someModule";
461-
export const result = require;`;
462-
463-
const lua = `
464-
package.loaded.someModule = {foo = "bar"}
465-
return (function()
466-
${util.transpileString(code, undefined, true)}
467-
end)().result`;
468-
469-
expect(util.executeLua(lua)).toBe("foobar");
458+
util.testBundle`
459+
const require = true;
460+
import "./module";
461+
export const result = require;
462+
`
463+
.addExtraFile("module.ts", "")
464+
.expectToEqual({ result: true });
470465
});
471466

472467
test("variable (tostring)", () => {
@@ -575,19 +570,14 @@ describe("lua keyword as identifier doesn't interfere with lua's value", () => {
575570
expect(util.transpileAndExecute(code)).toBe("foobar|string");
576571
});
577572

578-
test.each(["type", "type as type"])("imported variable (%p)", importName => {
579-
const luaHeader = `
580-
package.loaded.someModule = {type = "foobar"}`;
581-
582-
const code = `
583-
import {${importName}} from "someModule";
584-
export const result = typeof 7 + "|" + type;
585-
`;
586-
587-
const lua = util.transpileString(code);
588-
const result = util.executeLua(`${luaHeader} return (function() ${lua} end)().result`);
589-
590-
expect(result).toBe("number|foobar");
573+
test.each(["type", "type as type"])("imported variable (%p)", importSpecifier => {
574+
util.testBundle`
575+
import { ${importSpecifier} } from "./module";
576+
typeof 0;
577+
export const result = type;
578+
`
579+
.addExtraFile("module.ts", "export const type = true;")
580+
.expectToEqual({ result: true });
591581
});
592582

593583
test.each([
@@ -605,16 +595,12 @@ describe("lua keyword as identifier doesn't interfere with lua's value", () => {
605595
});
606596

607597
test.each(["type", "type as type"])("re-exported variable with lua keyword as name (%p)", importName => {
608-
const code = `
609-
export { ${importName} } from "someModule"`;
610-
611-
const lua = `
612-
package.loaded.someModule = {type = "foobar"}
613-
return (function()
614-
${util.transpileString(code)}
615-
end)().type`;
616-
617-
expect(util.executeLua(lua)).toBe("foobar");
598+
util.testBundle`
599+
export { ${importName} } from "./module";
600+
typeof 0;
601+
`
602+
.addExtraFile("module.ts", "export const type = true")
603+
.expectToEqual({ type: true });
618604
});
619605

620606
test("class", () => {

0 commit comments

Comments
 (0)