|
| 1 | +/// <reference path="..\..\..\src\harness\harness.ts" /> |
| 2 | +/// <reference path="..\..\..\src\compiler\commandLineParser.ts" /> |
| 3 | + |
| 4 | +namespace ts { |
| 5 | + describe('convertCompilerOptionsFromJson', () => { |
| 6 | + function assertCompilerOptions(json: any, expectedResult: { compilerOptions: CompilerOptions, errors: Diagnostic[] }) { |
| 7 | + const actualErrors: Diagnostic[] = []; |
| 8 | + const actualCompilerOptions = convertOptionsFromJson<CompilerOptions>(optionDeclarations, json["compilerOptions"], "/apath/", "tsconfig.json", actualErrors); |
| 9 | + |
| 10 | + const parsedCompilerOptions = JSON.stringify(actualCompilerOptions); |
| 11 | + const expectedCompilerOptions = JSON.stringify(expectedResult.compilerOptions); |
| 12 | + assert.equal(parsedCompilerOptions, expectedCompilerOptions); |
| 13 | + |
| 14 | + const expectedErrors = expectedResult.errors; |
| 15 | + assert.isTrue(expectedResult.errors.length === actualErrors.length, `Expected error: ${JSON.stringify(expectedResult.errors)}. Actual error: ${JSON.stringify(actualErrors)}.`); |
| 16 | + for (let i = 0; i < actualErrors.length; ++i) { |
| 17 | + const actualError = actualErrors[i]; |
| 18 | + const expectedError = expectedErrors[i]; |
| 19 | + assert.equal(actualError.code, expectedError.code, `Expected error-code: ${JSON.stringify(expectedError.code)}. Actual error-code: ${JSON.stringify(actualError.code)}.`); |
| 20 | + assert.equal(actualError.category, expectedError.category, `Expected error-category: ${JSON.stringify(expectedError.category)}. Actual error-category: ${JSON.stringify(actualError.category)}.`); |
| 21 | + } |
| 22 | + } |
| 23 | + |
| 24 | + const correctFormatOptions = { |
| 25 | + "compilerOptions": { |
| 26 | + "module": "commonjs", |
| 27 | + "target": "es5", |
| 28 | + "noImplicitAny": false, |
| 29 | + "sourceMap": false, |
| 30 | + "lib": ["es5", "es6.array", "es6.symbol"] |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + const incorrectLibOption = { |
| 35 | + "compilerOptions": { |
| 36 | + "module": "commonjs", |
| 37 | + "target": "es5", |
| 38 | + "noImplicitAny": false, |
| 39 | + "sourceMap": false, |
| 40 | + "lib": ["es5", "es6.array", "es8"] |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + it("Convert correctly format JSON to compiler-options ", () => { |
| 45 | + assertCompilerOptions(correctFormatOptions, { |
| 46 | + compilerOptions: <CompilerOptions>{ |
| 47 | + module: ModuleKind.CommonJS, |
| 48 | + target: ScriptTarget.ES5, |
| 49 | + noImplicitAny: false, |
| 50 | + sourceMap: false, |
| 51 | + lib: ["lib.es5.d.ts", "lib.es6.array.d.ts", "lib.es6.symbol.d.ts"] |
| 52 | + }, |
| 53 | + errors: <Diagnostic[]>[] |
| 54 | + }); |
| 55 | + }); |
| 56 | + |
| 57 | + it("Convert incorrectly option of libs to compiler-options ", () => { |
| 58 | + debugger; |
| 59 | + assertCompilerOptions(incorrectLibOption, { |
| 60 | + compilerOptions: <CompilerOptions>{ |
| 61 | + module: ModuleKind.CommonJS, |
| 62 | + target: ScriptTarget.ES5, |
| 63 | + noImplicitAny: false, |
| 64 | + sourceMap: false, |
| 65 | + lib: ["lib.es5.d.ts", "lib.es6.array.d.ts"] |
| 66 | + }, |
| 67 | + errors: [{ |
| 68 | + file: undefined, |
| 69 | + start: 0, |
| 70 | + length: 0, |
| 71 | + messageText: "", |
| 72 | + code: Diagnostics.Arguments_for_library_option_must_be_Colon_0.code, |
| 73 | + category: Diagnostics.Arguments_for_library_option_must_be_Colon_0.category |
| 74 | + }] |
| 75 | + }); |
| 76 | + }); |
| 77 | + }); |
| 78 | +} |
0 commit comments