Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 0 additions & 42 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@
"node": ">=8.5.0"
},
"dependencies": {
"dedent": "^0.7.0",
"fs-extra": "^5.0.0",
"yargs": "^11.0.0"
},
"devDependencies": {
"@types/fs-extra": "^5.0.1",
"@types/node": "^9.4.7",
"@types/yargs": "^11.0.0",
"alsatian": "^2.2.1",
Expand Down
3 changes: 0 additions & 3 deletions src/CommandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import * as path from "path";
import * as ts from "typescript";
import * as yargs from "yargs";

// ES6 syntax broken
import dedent = require("dedent");

export interface CompilerOptions extends ts.CompilerOptions {
addHeader?: boolean;
luaTarget?: string;
Expand Down
74 changes: 74 additions & 0 deletions test/compiler/compiler.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { Expect, Setup, Teardown, Test, TestCase } from "alsatian";
import * as fs from "fs";
import * as path from "path";
import { execCommandLine } from "../../src/Compiler";

/**
* Find all files inside a dir, recursively.
*/
function getAllFiles(dir: string): string[] {
return fs.readdirSync(dir).reduce(
(files, file) => {
const name = path.join(dir, file);
const isDirectory = fs.statSync(name).isDirectory();
return isDirectory ? [...files, ...getAllFiles(name)] : [...files, name];
},
[]
);
}

export class CompilerTests {

private existingFiles: string[];
private filesAfterCompile: string[];

@Setup
public setup() {
this.existingFiles = getAllFiles(path.resolve(__dirname, "./project"));
this.filesAfterCompile = [];
}

@TestCase("tsconfig.default.json",
"typescript_lualib.lua",
"test_src/test_lib/file.lua",
"test_src/main.lua")
@TestCase("tsconfig.outDir.json",
"out_dir/typescript_lualib.lua",
"out_dir/test_src/test_lib/file.lua",
"out_dir/test_src/main.lua")
@TestCase("tsconfig.rootDir.json",
"test_src/typescript_lualib.lua",
"test_src/test_lib/file.lua",
"test_src/main.lua")
@TestCase("tsconfig.bothDirOptions.json",
"out_dir/typescript_lualib.lua",
"out_dir/test_lib/file.lua",
"out_dir/main.lua")
@Test("Compile project")
public compileProject(tsconfig: string, ...expectedFiles: string[]) {
const tsconfigPath = path.resolve(__dirname, "project", tsconfig);

// Compile project
execCommandLine(["-p", tsconfigPath]);

this.filesAfterCompile = getAllFiles(path.resolve(__dirname, "project"));
expectedFiles = expectedFiles.map((relPath) => path.resolve(__dirname, "project", relPath));
expectedFiles.push(...this.existingFiles);

for (const existingFile of this.filesAfterCompile) {
Expect(expectedFiles).toContain(existingFile);
}
}

@Teardown
public teardown() {
// Remove files taht were created by the test
const createdFiles = this.filesAfterCompile.filter((v) => this.existingFiles.indexOf(v) < 0);
for (const file of createdFiles) {
fs.unlinkSync(file);
}
this.existingFiles = [];
this.filesAfterCompile = [];
}

}
3 changes: 3 additions & 0 deletions test/compiler/project/test_src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function main() {
const main = 10;
}
1 change: 1 addition & 0 deletions test/compiler/project/test_src/test_lib/file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const test = true;
7 changes: 7 additions & 0 deletions test/compiler/project/tsconfig.bothDirOptions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.default.json",
"compilerOptions": {
"outDir": "out_dir",
"rootDir": "test_src"
}
}
3 changes: 3 additions & 0 deletions test/compiler/project/tsconfig.default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"luaTarget": "JIT"
}
6 changes: 6 additions & 0 deletions test/compiler/project/tsconfig.outDir.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig.default.json",
"compilerOptions": {
"outDir": "out_dir"
}
}
6 changes: 6 additions & 0 deletions test/compiler/project/tsconfig.rootDir.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig.default.json",
"compilerOptions": {
"rootDir": "test_src"
}
}
6 changes: 3 additions & 3 deletions test/runner.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TestSet, TestRunner } from "alsatian";
import { TestRunner, TestSet } from "alsatian";
import { TapBark } from "tap-bark";

// create test set
Expand All @@ -21,6 +21,6 @@ testRunner.outputStream
// run the test set
testRunner.run(testSet);
// this will be called after all tests have been run
//.then((results) => done())
// .then((results) => done())
// this will be called if there was a problem
//.catch((error) => doSomethingWith(error));
// .catch((error) => doSomethingWith(error));
1 change: 1 addition & 0 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
},
"exclude": [
"translation/ts/*",
"compiler/project/*"
]
}
10 changes: 4 additions & 6 deletions test/unit/modules.spec.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import { Expect, Test, TestCase } from "alsatian";
import * as util from "../src/util"

const dedent = require('dedent')
import * as util from "../src/util";

export class LuaModuleTests {

@Test("defaultImport")
public defaultImport() {
Expect(() => {
let lua = util.transpileString(`import TestClass from "test"`);
const lua = util.transpileString(`import TestClass from "test"`);
}).toThrowError(Error, "Default Imports are not supported, please use named imports instead!");
}

@Test("lualibRequire")
public lualibRequire() {
// Transpile
let lua = util.transpileString(``, {dontRequireLuaLib: false, luaTarget: "JIT"});
const lua = util.transpileString(``, {dontRequireLuaLib: false, luaTarget: "JIT"});

// Assert
Expect(dedent(lua)).toBe(`require("typescript_lualib")`);
Expect(lua).toBe(`require("typescript_lualib")`);
}
}