Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2e140ff
Migrate tests to Jest
ark120202 Mar 24, 2019
21d6af4
Fix formatting of some code literals
ark120202 Mar 24, 2019
e77fbf5
Update contributing docs
ark120202 Mar 24, 2019
cc07dce
Load ts-node in the fork call in watchmode test
ark120202 Mar 24, 2019
7fe1921
Change test directory in configs
ark120202 Mar 24, 2019
628069c
Revisit toThrowExactError matcher
ark120202 Mar 24, 2019
2a8ff2f
Use toThrowExactError on TSTLErrors in tests
ark120202 Mar 24, 2019
2294863
Increase timeout for watchmode test since it may fail sometimes
ark120202 Mar 24, 2019
033873e
Execute TypeScript's Opganize Imports command
ark120202 Mar 24, 2019
56f6a17
Split assignments tests to improve parallel testing performance
ark120202 Mar 24, 2019
500f082
Add skipLibCheck flag to tests
ark120202 Mar 24, 2019
ca38b95
Inline lualib by default in tests
ark120202 Mar 24, 2019
637534f
Remove test-fast script
ark120202 Mar 24, 2019
082cba3
Remove ignoreDiagnostics option from transpileAndExecute
ark120202 Mar 24, 2019
0c330c5
Remove @ts-check from jest config file
ark120202 Mar 24, 2019
ba7419a
Add (%p) to set size test name
ark120202 Mar 24, 2019
1a3a650
Format some code literals
ark120202 Mar 25, 2019
7ce2e8f
Revert formatting changes in characterEscapeSequence translation test
ark120202 Mar 25, 2019
c0e8be0
Add pretest script to build lualib
ark120202 Mar 25, 2019
77b02d3
Improve performance of build_lualib script
ark120202 Mar 25, 2019
23acd2e
Re-enable type checking for build-lualib script
ark120202 Mar 26, 2019
757f3d2
Merge remote-tracking branch 'upstream/master' into jest
ark120202 Mar 26, 2019
af1d0ad
Use jest's snapshot testing for translation tests
ark120202 Mar 26, 2019
8c86106
Use regular --watch flag instead of --watchAll in contributing docs
ark120202 Mar 26, 2019
e5fa49a
Sort transformation test fixture names
ark120202 Mar 26, 2019
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
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.yml]
[*.{yml,md}]
indent_size = 2
22 changes: 6 additions & 16 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
*.js
node_modules/
yarn.lock

.vscode/
/node_modules
/dist
/coverage

coverage/
.nyc*
*.js.map
yarn.lock
.vscode
.idea

# Release
*.tgz

# OSX
.DS_Store
*.lcov

# IDEA IDEs
.idea/

typescript_lualib.lua
lualib_bundle.lua

dist/*
7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/dist
/coverage
/test/compiler/testfiles/invalid_syntax.ts
/test/translation/transformation/characterEscapeSequence.ts

/src
*.md
14 changes: 7 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
language: node_js
node_js:
- stable
install:
- npm install
- stable

script:
- npm run build
- npm run coverage
after_success:
- codecov
- npm run lint
- npm run build
- npm test -- --coverage
after_success: npx codecov

deploy:
provider: npm
email: lorenz.junglas@student.kit.edu
Expand Down
55 changes: 17 additions & 38 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,67 +14,46 @@ To get familiar with the project structure, here is a short overview of each dir
* `src/targets/`
- Version-specific transpiler overrides for the different Lua targets. The main transpiler transpiles Lua 5.0, each target-specific transpiler extends the transpiler of the version before it, so the 5.3 inherits 5.2 which inherits 5.1 which inherits 5.0. LuaJIT is based on 5.2 so inherits from the 5.2 transpiler.
* *Compiler.ts* - Main entry point of the transpiler, this is what interfaces with the TypeScript compiler API.
* *Transpiler.ts* - Main transpiler code, transforms a TypeScript AST to a Lua string.
* *LuaTransformer.ts* - Main transpiler code, transforms a TypeScript AST to a Lua AST.
* *LuaPrinter.ts* - Transforms a Lua AST to a string.
* *TSHelper.ts* - Helper methods used during the transpilation process.
- `test/`
* This directory contains all testing code for the transpiler.
* `test/src/`
- Contains all extra source and utility used to run tests.
* `test/unit/`
- Unit/Functional tests for the transpiler. Tests in here are grouped by functionality they are testing. Generally each of these tests uses the transpiler to transpile some TypeScript to Lua, then executes it using the Fengari Lua VM. Assertion is done on the result of the lua code.
* `test/translation/`
- **[Obsolete]** Contains tests that only check the transpiled Lua String. We prefer adding unit/functional tests over translation tests. This directory will probably be removed at some point.

## Running Tests
The tests for this project can be executed using the standard `npm test`. This runs all tests (can take a while!).
The tests for this project can be executed using the standard `npm test`. This runs all tests.

### Testing while developing
Due to the time required to run all tests, it is impractical to run every test while developing part of the transpiler. To speed up the test run you can import `FocusTest` or `FocusTests` from Alsatian. If a class is decorated with `@FocusTests`, all other test classes will be ignored. Similarly, if any test method is decorated with `@FocusTest`, only `@FocusTest` methods will be run during `npm test`.
Due to the time required to run all tests, it is impractical to run every test while developing part of the transpiler. To speed up the test run you can:

For example:
```ts
import { Expect, FocusTests, Test, TestCase } from "alsatian";
- Use `npm test name` to run tests that match a file name pattern

@FocusTests
export class FunctionTests {
// All tests in here will be executed.
}
- Use `npm test -- --watch [name]` to start tests and rerun them on change

// All other tests will be ignored.
```
- Check out `Watch Usage` in the watching interface to get information about filtering tests without restarting CLI

Or
- Use `.only` and `.skip` to filter executed tests in the file

```ts
import { Expect, FocusTest, Test, TestCase } from "alsatian";

export class FunctionTests {
@FocusTest
@Test("Example test 1")
public test1(): void { // Will be executed
}

@FocusTest
@Test("Example test 2")
public test2(): void { // Will also be executed
}

@Test("Example test 3")
public test3(): void { // Will be ignored
}
}

// All other tests will be ignored.
```
```ts
// Skipped
test("test", () => {});

// Executed
test.only("test", () => {});
```

## Testing Guidelines
When submitting a pull request with new functionality, we require some functional (transpile and execute Lua) to be added, to ensure the new functionality works as expected, and will continue to work that way.

Translation tests are discouraged as in most cases as we do not really care about the exact Lua output, as long as executing it results in the correct result (which is tested by functional tests).

## Coding Conventions
Most coding conventions are enforced by the ts-lint configuration. The test process will fail if code does not pass the linter. Some extra conventions worth mentioning:
Most coding conventions are enforced by the TSLint and Prettier. You can check your code locally by running `npm run lint`. The CI build will fail if your code does not pass the linter. For better experience, you can install extensions for your code editor for [TSLint](https://palantir.github.io/tslint/usage/third-party-tools/) and [Prettier](https://prettier.io/docs/en/editors.html).

Some extra conventions worth mentioning:
* Do not abbreviate variable names. The exception here are inline lambda arguments, if it is obvious what the argument is you can abbreviate to the first letter, e.g: `statements.filter(s => ts.VariableStatement(s))`
* Readability of code is more important than the amount of space it takes. If extra line breaks make your code more readable, add them.
* Functional style is encouraged!
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ install:
# Get the latest stable version of Node.js or io.js
- ps: Install-Product node $env:nodejs_version
# install modules
- npm install
- npm ci

# Post-install test scripts.
test_script:
Expand Down
7 changes: 5 additions & 2 deletions build_lualib.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import * as fs from "fs";
import * as glob from "glob";
import {compile} from "./src/Compiler";
import {LuaLib as luaLib, LuaLibFeature} from "./src/LuaLib";
import { compile } from "./src/Compiler";
import { LuaLib as luaLib, LuaLibFeature } from "./src/LuaLib";

const bundlePath = "./dist/lualib/lualib_bundle.lua";

compile([
"--skipLibCheck",
"--types",
"node",
"--luaLibImport",
"none",
"--luaTarget",
Expand Down
18 changes: 18 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const isCI = require("is-ci");

/** @type {Partial<import('@jest/types').Config.DefaultOptions>} */
module.exports = {
testMatch: ["**/test/**/*.spec.ts"],
collectCoverageFrom: ["<rootDir>/src/**/*", "!<rootDir>/src/lualib/**/*"],
watchPathIgnorePatterns: ["/watch\\.ts$"],

testEnvironment: "node",
testRunner: "jest-circus/runner",
preset: "ts-jest",
globals: {
"ts-jest": {
tsConfig: "<rootDir>/test/tsconfig.json",
diagnostics: { warnOnly: !isCI },
},
},
};
Loading