|
| 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 | +} |
0 commit comments