Skip to content

Commit 715cdb7

Browse files
zapp-brannigan-dotalolleko
authored andcommitted
Add compiler tests (#67)
* Add compiler tests * Update readme * Fix compiler tests
1 parent e736652 commit 715cdb7

File tree

9 files changed

+110
-10
lines changed

9 files changed

+110
-10
lines changed

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ Options:
3636
--version Show version number [boolean]
3737
--lt, --luaTarget Specify Lua target version.
3838
[string] [choices: "JIT", "5.1", "5.2", "5.3"] [default: "JIT"]
39-
--lld, --luaLibDir Specify typescript_lualib.lua location relative to outDir.
40-
[string] [default: "./"]
4139
--ah, --addHeader Specify if a header will be added to compiled files.
4240
[boolean] [default: true]
4341
@@ -53,9 +51,9 @@ Examples:
5351
"noImplicitAny" : true,
5452
"noImplicitThis" : true,
5553
"alwaysStrict" : true,
56-
"strictNullChecks": true,
57-
"luaTarget": "JIT"
58-
}
54+
"strictNullChecks": true
55+
},
56+
"luaTarget": "JIT"
5957
}
6058
```
6159

package-lock.json

Lines changed: 42 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@
2222
},
2323
"dependencies": {
2424
"dedent": "^0.7.0",
25+
"fs-extra": "^5.0.0",
2526
"typescript": "^2.7.2",
2627
"yargs": "^11.0.0"
2728
},
2829
"devDependencies": {
30+
"@types/fs-extra": "^5.0.1",
31+
"@types/node": "^9.4.7",
2932
"@types/yargs": "^11.0.0",
3033
"alsatian": "^2.2.1",
3134
"codecov": "^3.0.0",

test/integration/compiler.spec.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Expect, Teardown, Test, TestCase } from "alsatian";
2+
import { execSync } from "child_process"
3+
import { existsSync, removeSync, unlink } from "fs-extra"
4+
import { resolve } from "path"
5+
6+
export class CompilerTests {
7+
8+
@TestCase('tsconfig.default.json', ['typescript_lualib.lua', 'nested/folder/file.lua'])
9+
@TestCase('tsconfig.outDir.json', ['outDir/typescript_lualib.lua', 'outDir/nested/folder/file.lua'])
10+
@TestCase('tsconfig.rootDir.json', ['nested/typescript_lualib.lua', 'nested/folder/file.lua'])
11+
@TestCase('tsconfig.bothDirOptions.json', ['outDir/typescript_lualib.lua', 'outDir/folder/file.lua'])
12+
@Test("Compile project")
13+
public compileProject(tsconfig: string, expectedFiles: string[]) {
14+
const compilerPath = resolve('dist/Compiler.js');
15+
const tsconfigPath = resolve('test/integration/project', tsconfig);
16+
17+
// Compile project
18+
execSync(`node ${compilerPath} -p ${tsconfigPath}`);
19+
20+
expectedFiles.forEach(relativePath => {
21+
const absolutePath = resolve('test/integration/project', relativePath);
22+
23+
// Assert
24+
Expect(existsSync(absolutePath)).toBe(true);
25+
26+
// Delete file
27+
unlink(absolutePath, (error) => {
28+
throw error;
29+
});
30+
});
31+
}
32+
33+
@Teardown
34+
public teardown() {
35+
// Delete outDir folder
36+
removeSync('test/integration/project/outDir');
37+
}
38+
39+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const test = true;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig.default.json",
3+
"compilerOptions": {
4+
"outDir": "../project/outDir",
5+
"rootDir": "../project/nested"
6+
}
7+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"luaTarget": "JIT"
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "./tsconfig.default.json",
3+
"compilerOptions": {
4+
"outDir": "../project/outDir"
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "./tsconfig.default.json",
3+
"compilerOptions": {
4+
"rootDir": "../project/nested"
5+
}
6+
}

0 commit comments

Comments
 (0)