From 724fbda9f05d4ff23a9c4606ef20c3dd04b6b130 Mon Sep 17 00:00:00 2001 From: Zapp Brannigan Date: Tue, 13 Mar 2018 05:29:39 +0100 Subject: [PATCH 1/3] Add compiler tests --- package-lock.json | 47 +++++++++++++++++-- package.json | 3 ++ test/integration/compiler.spec.ts | 36 ++++++++++++++ .../integration/project/nested/folder/file.ts | 1 + test/integration/project/tsconfig.base.json | 9 ++++ .../project/tsconfig.bothDirOptions.json | 7 +++ .../integration/project/tsconfig.default.json | 3 ++ test/integration/project/tsconfig.outDir.json | 6 +++ .../integration/project/tsconfig.rootDir.json | 6 +++ 9 files changed, 113 insertions(+), 5 deletions(-) create mode 100644 test/integration/compiler.spec.ts create mode 100644 test/integration/project/nested/folder/file.ts create mode 100644 test/integration/project/tsconfig.base.json create mode 100644 test/integration/project/tsconfig.bothDirOptions.json create mode 100644 test/integration/project/tsconfig.default.json create mode 100644 test/integration/project/tsconfig.outDir.json create mode 100644 test/integration/project/tsconfig.rootDir.json diff --git a/package-lock.json b/package-lock.json index 2bc069984..346844e01 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,10 +4,19 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@types/fs-extra": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-5.0.1.tgz", + "integrity": "sha512-h3wnflb+jMTipvbbZnClgA2BexrT4w0GcfoCz5qyxd0IRsbqhLSyesM6mqZTAnhbVmhyTm5tuxfRu9R+8l+lGw==", + "dev": true, + "requires": { + "@types/node": "9.4.7" + } + }, "@types/node": { - "version": "9.4.6", - "resolved": "https://registry.npmjs.org/@types/node/-/node-9.4.6.tgz", - "integrity": "sha512-CTUtLb6WqCCgp6P59QintjHWqzf4VL1uPA27bipLAPxFqrtK1gEYllePzTICGqQ8rYsCbpnsNypXjjDzGAAjEQ==", + "version": "9.4.7", + "resolved": "https://registry.npmjs.org/@types/node/-/node-9.4.7.tgz", + "integrity": "sha512-4Ba90mWNx8ddbafuyGGwjkZMigi+AWfYLSDCpovwsE63ia8w93r3oJ8PIAQc3y8U+XHcnMOHPIzNe3o438Ywcw==", "dev": true }, "@types/yargs": { @@ -32,7 +41,7 @@ "integrity": "sha1-B+qeiU7bnqmX7VcaZOFMyYsj0/g=", "dev": true, "requires": { - "@types/node": "9.4.6", + "@types/node": "9.4.7", "extendo-error": "1.0.1", "glob": "7.1.2", "reflect-metadata": "0.1.12", @@ -371,6 +380,16 @@ "mime-types": "2.1.18" } }, + "fs-extra": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-5.0.0.tgz", + "integrity": "sha512-66Pm4RYbjzdyeuqudYqhFiNBbCIuI9kgRqLPSHIlXHidW8NIQtVdkM1yeZ4lXwuhbTETv3EUGMNHAAw6hiundQ==", + "requires": { + "graceful-fs": "4.1.11", + "jsonfile": "4.0.0", + "universalify": "0.1.1" + } + }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -418,6 +437,11 @@ "path-is-absolute": "1.0.1" } }, + "graceful-fs": { + "version": "4.1.11", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", + "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=" + }, "har-schema": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-1.0.5.tgz", @@ -564,6 +588,14 @@ "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=", "dev": true }, + "jsonfile": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", + "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", + "requires": { + "graceful-fs": "4.1.11" + } + }, "jsonify": { "version": "0.0.0", "resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz", @@ -2571,7 +2603,7 @@ "integrity": "sha1-bAPcUWh/7Xh3+COtSx3dHvXrVnQ=", "dev": true, "requires": { - "@types/node": "9.4.6", + "@types/node": "9.4.7", "chalk": "1.1.3", "duplexer": "0.1.1", "tap-parser": "3.0.5", @@ -2629,6 +2661,11 @@ "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.7.2.tgz", "integrity": "sha512-p5TCYZDAO0m4G344hD+wx/LATebLWZNkkh2asWUFqSsD2OrDNhbAHuSjobrmsUmdzjJjEeZVU9g1h3O6vpstnw==" }, + "universalify": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.1.tgz", + "integrity": "sha1-+nG63UQ3r0wUiEHjs7Fl+enlkLc=" + }, "urlgrey": { "version": "0.4.4", "resolved": "https://registry.npmjs.org/urlgrey/-/urlgrey-0.4.4.tgz", diff --git a/package.json b/package.json index 6fb8af898..a94d7cb24 100644 --- a/package.json +++ b/package.json @@ -22,10 +22,13 @@ }, "dependencies": { "dedent": "^0.7.0", + "fs-extra": "^5.0.0", "typescript": "^2.7.2", "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", "codecov": "^3.0.0", diff --git a/test/integration/compiler.spec.ts b/test/integration/compiler.spec.ts new file mode 100644 index 000000000..db230b681 --- /dev/null +++ b/test/integration/compiler.spec.ts @@ -0,0 +1,36 @@ +import { Expect, Test, TestCase } from "alsatian"; +import { execSync } from "child_process" +import { existsSync, removeSync, unlink } from "fs-extra" +import { resolve } from "path" + +export class CompilerTests { + + @TestCase('tsconfig.default.json', ['typescript_lualib.lua', 'nested/folder/file.lua']) + @TestCase('tsconfig.outDir.json', ['outDir/typescript_lualib.lua', 'outDir/nested/folder/file.lua']) + @TestCase('tsconfig.rootDir.json', ['nested/typescript_lualib.lua', 'nested/folder/file.lua']) + @TestCase('tsconfig.bothDirOptions.json', ['outDir/typescript_lualib.lua', 'outDir/folder/file.lua']) + @Test("Compile project") + public compileProject(tsconfig: string, expectedFiles: string[]) { + const compilerPath = resolve('dist/Compiler.js'); + const tsconfigPath = resolve('test/integration/project', tsconfig); + + // Compile project + execSync(`node ${compilerPath} -p ${tsconfigPath}`); + + expectedFiles.forEach(relativePath => { + const absolutePath = resolve('test/integration/project', relativePath); + + // Assert + Expect(existsSync(absolutePath)).toBe(true); + + // Delete file + unlink(absolutePath, (error) => { + throw error; + }); + }); + + // Delete outDir folder + removeSync('test/integration/project/outDir'); + } + +} diff --git a/test/integration/project/nested/folder/file.ts b/test/integration/project/nested/folder/file.ts new file mode 100644 index 000000000..d764cbd99 --- /dev/null +++ b/test/integration/project/nested/folder/file.ts @@ -0,0 +1 @@ +const test = true; diff --git a/test/integration/project/tsconfig.base.json b/test/integration/project/tsconfig.base.json new file mode 100644 index 000000000..6898b4fce --- /dev/null +++ b/test/integration/project/tsconfig.base.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "noImplicitAny" : true, + "noImplicitThis" : true, + "alwaysStrict" : true, + "strictNullChecks": true, + "luaTarget": "JIT" + } +} diff --git a/test/integration/project/tsconfig.bothDirOptions.json b/test/integration/project/tsconfig.bothDirOptions.json new file mode 100644 index 000000000..5e0dea1da --- /dev/null +++ b/test/integration/project/tsconfig.bothDirOptions.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.base.json", + "compilerOptions": { + "outDir": "../project/outDir", + "rootDir": "../project/nested" + } +} diff --git a/test/integration/project/tsconfig.default.json b/test/integration/project/tsconfig.default.json new file mode 100644 index 000000000..3ee7a6c6e --- /dev/null +++ b/test/integration/project/tsconfig.default.json @@ -0,0 +1,3 @@ +{ + "extends": "./tsconfig.base.json" +} diff --git a/test/integration/project/tsconfig.outDir.json b/test/integration/project/tsconfig.outDir.json new file mode 100644 index 000000000..1517bb998 --- /dev/null +++ b/test/integration/project/tsconfig.outDir.json @@ -0,0 +1,6 @@ +{ + "extends": "./tsconfig.base.json", + "compilerOptions": { + "outDir": "../project/outDir" + } +} diff --git a/test/integration/project/tsconfig.rootDir.json b/test/integration/project/tsconfig.rootDir.json new file mode 100644 index 000000000..c413251d5 --- /dev/null +++ b/test/integration/project/tsconfig.rootDir.json @@ -0,0 +1,6 @@ +{ + "extends": "./tsconfig.base.json", + "compilerOptions": { + "rootDir": "../project/nested" + } +} From 406e933a7ea18f51b260dc3f5e68ea069225f191 Mon Sep 17 00:00:00 2001 From: Zapp Brannigan Date: Tue, 13 Mar 2018 05:36:20 +0100 Subject: [PATCH 2/3] Update readme --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 70b4c8c2e..443c8f7ba 100644 --- a/README.md +++ b/README.md @@ -36,8 +36,6 @@ Options: --version Show version number [boolean] --lt, --luaTarget Specify Lua target version. [string] [choices: "JIT", "5.1", "5.2", "5.3"] [default: "JIT"] - --lld, --luaLibDir Specify typescript_lualib.lua location relative to outDir. - [string] [default: "./"] --ah, --addHeader Specify if a header will be added to compiled files. [boolean] [default: true] From 83d6e6de56741c4cda4bd6c9a47daeb6c70e2d88 Mon Sep 17 00:00:00 2001 From: Zapp Brannigan Date: Tue, 13 Mar 2018 10:49:04 +0100 Subject: [PATCH 3/3] Fix compiler tests --- README.md | 6 +++--- test/integration/compiler.spec.ts | 5 ++++- test/integration/project/tsconfig.base.json | 9 --------- test/integration/project/tsconfig.bothDirOptions.json | 2 +- test/integration/project/tsconfig.default.json | 2 +- test/integration/project/tsconfig.outDir.json | 2 +- test/integration/project/tsconfig.rootDir.json | 2 +- 7 files changed, 11 insertions(+), 17 deletions(-) delete mode 100644 test/integration/project/tsconfig.base.json diff --git a/README.md b/README.md index 443c8f7ba..476c97299 100644 --- a/README.md +++ b/README.md @@ -51,9 +51,9 @@ Examples: "noImplicitAny" : true, "noImplicitThis" : true, "alwaysStrict" : true, - "strictNullChecks": true, - "luaTarget": "JIT" - } + "strictNullChecks": true + }, + "luaTarget": "JIT" } ``` diff --git a/test/integration/compiler.spec.ts b/test/integration/compiler.spec.ts index db230b681..848af7e74 100644 --- a/test/integration/compiler.spec.ts +++ b/test/integration/compiler.spec.ts @@ -1,4 +1,4 @@ -import { Expect, Test, TestCase } from "alsatian"; +import { Expect, Teardown, Test, TestCase } from "alsatian"; import { execSync } from "child_process" import { existsSync, removeSync, unlink } from "fs-extra" import { resolve } from "path" @@ -28,7 +28,10 @@ export class CompilerTests { throw error; }); }); + } + @Teardown + public teardown() { // Delete outDir folder removeSync('test/integration/project/outDir'); } diff --git a/test/integration/project/tsconfig.base.json b/test/integration/project/tsconfig.base.json deleted file mode 100644 index 6898b4fce..000000000 --- a/test/integration/project/tsconfig.base.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "compilerOptions": { - "noImplicitAny" : true, - "noImplicitThis" : true, - "alwaysStrict" : true, - "strictNullChecks": true, - "luaTarget": "JIT" - } -} diff --git a/test/integration/project/tsconfig.bothDirOptions.json b/test/integration/project/tsconfig.bothDirOptions.json index 5e0dea1da..625a88582 100644 --- a/test/integration/project/tsconfig.bothDirOptions.json +++ b/test/integration/project/tsconfig.bothDirOptions.json @@ -1,5 +1,5 @@ { - "extends": "./tsconfig.base.json", + "extends": "./tsconfig.default.json", "compilerOptions": { "outDir": "../project/outDir", "rootDir": "../project/nested" diff --git a/test/integration/project/tsconfig.default.json b/test/integration/project/tsconfig.default.json index 3ee7a6c6e..e5a835e99 100644 --- a/test/integration/project/tsconfig.default.json +++ b/test/integration/project/tsconfig.default.json @@ -1,3 +1,3 @@ { - "extends": "./tsconfig.base.json" + "luaTarget": "JIT" } diff --git a/test/integration/project/tsconfig.outDir.json b/test/integration/project/tsconfig.outDir.json index 1517bb998..81d60baff 100644 --- a/test/integration/project/tsconfig.outDir.json +++ b/test/integration/project/tsconfig.outDir.json @@ -1,5 +1,5 @@ { - "extends": "./tsconfig.base.json", + "extends": "./tsconfig.default.json", "compilerOptions": { "outDir": "../project/outDir" } diff --git a/test/integration/project/tsconfig.rootDir.json b/test/integration/project/tsconfig.rootDir.json index c413251d5..e57d98355 100644 --- a/test/integration/project/tsconfig.rootDir.json +++ b/test/integration/project/tsconfig.rootDir.json @@ -1,5 +1,5 @@ { - "extends": "./tsconfig.base.json", + "extends": "./tsconfig.default.json", "compilerOptions": { "rootDir": "../project/nested" }