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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ install:
script:
- npm run build
# Testing & Coverage
- npm test
after_success:
- npm run coverage
after_success:
- codecov
deploy:
provider: npm
email: 'lorenz.junglas@student.kit.edu'
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ The real power of this transpiler is usage together with good declarations for t
- [Dota 2 Modding](https://github.com/ModDota/API/tree/master/declarations/server)
- [Defold Game Engine Scripting](https://github.com/dasannikov/DefoldTypeScript/blob/master/defold.d.ts)

## Building & Tests

`npm run build` to build the project.

`npm run test` to run tests.

`npm run test-threaded` runs test in parallel, faster but less detailed output.

`npm run coverage` or `npm run coverage-html` to generate a coverage report.

## Sublime Text integration
This compiler works great in combination with the [Sublime Text Typescript plugin](https://github.com/Microsoft/TypeScript-Sublime-Plugin) (available through the package manager as `TypeScript`).

Expand Down
51 changes: 51 additions & 0 deletions package-lock.json

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

8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"scripts": {
"build": "tsc -p tsconfig.json",
"test": "tslint -p . && ts-node ./test/runner.ts",
"coverage": "nyc npm test && nyc report --reporter=text-lcov > coverage.lcov && codecov",
"test-threaded": "tslint -p . && ts-node ./test/threaded_runner.ts",
"coverage-threaded": "nyc npm run test-threaded && nyc report --reporter=text-lcov > coverage.lcov",
"coverage": "nyc npm test && nyc report --reporter=text-lcov > coverage.lcov",
"coverage-html": "nyc npm test && nyc report --reporter=html",
"release-patch": "npm version patch",
"release-minor": "npm version minor",
Expand Down Expand Up @@ -40,13 +42,17 @@
"yargs": "^11.1.0"
},
"devDependencies": {
"@types/glob": "^5.0.35",
"@types/node": "^9.6.23",
"@types/yargs": "^11.0.0",
"alsatian": "^2.2.1",
"circular-json": "^0.5.5",
"codecov": "3.0.2",
"deep-equal": "^1.0.1",
"fengari": "^0.1.2",
"glob": "^7.1.2",
"nyc": "^11.9.0",
"threads": "^0.12.0",
"ts-node": "^7.0.0",
"tslint": "^5.10.0",
"tslint-override": "^0.1.2"
Expand Down
31 changes: 31 additions & 0 deletions test/test_thread.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { MatchError, TestRunner, TestSet, TestOutcome } from "alsatian";
import * as JSON from "circular-json";

module.exports = function(input, done) {
const testSet = TestSet.create();
testSet.addTestsFromFiles(input.files);
const testRunner = new TestRunner();

testRunner.onTestComplete((result) => {
if (result.outcome === TestOutcome.Fail) {
if (result.error instanceof MatchError) {
console.log(`Test ${result.testFixture.description}, ${result.test.key}(${JSON.stringify(result.testCase.caseArguments)}) Failed!`)
console.log(" ---\n" +
' message: "' +
result.error.message +
'"\n' +
" severity: fail\n" +
" data:\n" +
" got: " +
result.error.actual +
"\n" +
" expect: " +
result.error.expected +
"\n");
}
}
})

testRunner.run(testSet)
.then((results) => done(results, input))
};
56 changes: 56 additions & 0 deletions test/threaded_runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {MatchError} from "alsatian";
import * as glob from "glob";
import * as os from "os";
import * as path from "path";
import {config, Pool} from "threads";

config.set({
basepath: {
node: __dirname,
}
});

let cpuCount = os.cpus().length + 1;
if ("TRAVIS" in process.env && "CI" in process.env) {
// fixed thread count for CI
cpuCount = 8;
}
const testFiles: string[] = glob.sync("./test/**/*.spec.ts");
const pool = new Pool(cpuCount);
let jobCounter = 0;

const fileArrToString = (fileArr: string[]) =>
fileArr.map(val => path.basename(val).replace(".spec.ts", "")).join(", ");

console.log(
`Running tests: ${fileArrToString(testFiles)} with ${cpuCount} threads`);

const filesPerThread = Math.floor(testFiles.length / cpuCount);
const threadsWithMoreWork = testFiles.length % cpuCount;

for (let i = 1; i <= cpuCount; i++) {
let files: string[] = [];
if (i <= threadsWithMoreWork) {
files = testFiles.splice(0, filesPerThread + 1);
} else {
files = testFiles.splice(0, filesPerThread);
}
console.log(`Running tests: ${fileArrToString(files)} in thread ${i}`);

pool.run("./test_thread")
.send({files: files})
.on("done",
(results, input) => {
jobCounter++;
console.log(`Tests ${fileArrToString(files)} ${jobCounter}/${
cpuCount} done.`);
})
.on("error", error => {
console.log("Exception in test:", files, error);
});
}

pool.on("finished", () => {
console.log("Everything done, shutting down the thread pool.");
pool.killAll();
});
2 changes: 1 addition & 1 deletion test/unit/string.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class StringTests {
@TestCase([65, 66])
@TestCase([65, 66, 67])
@Test("String.fromCharCode")
public stringFromCharcode(inp: number[], expected: string) {
public stringFromCharcode(inp: number[]) {
// Transpile
const lua = util.transpileString(
`return String.fromCharCode(${inp.toString()})`
Expand Down