UNPKG

1.57 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var chalk_1 = require("chalk");
4var diff = require("diff");
5var path = require("path");
6var fs_helpers_1 = require("./helpers/fs.helpers");
7var tsgen_1 = require("./tsgen");
8describe('tsgen', function () {
9 fs_helpers_1.walkDirectory('./spec', function (filePath) {
10 var relativeFilePath = "." + path.sep + path.relative(process.cwd(), filePath);
11 it("should pass the '" + relativeFilePath + "' test case", function () {
12 var fileContents = fs_helpers_1.readFile(filePath);
13 var _a = fileContents.split(/~{100}\r?\n/), optionsJson = _a[0], input = _a[1], output = _a[2];
14 var expectedOutput = normalizeNewLines(output);
15 var options = optionsJson ? JSON.parse(optionsJson) : undefined;
16 var testOutput = normalizeNewLines(tsgen_1.tsgen(input, options));
17 if (testOutput !== expectedOutput) {
18 var patch = diff.createTwoFilesPatch('test-output.ts', 'expected-output.ts', testOutput, expectedOutput, '', '')
19 .split('\n')
20 .map(function (line) { return line.startsWith('-') ? chalk_1.default.red(line) : line.startsWith('+') ? chalk_1.default.green(line) : line; })
21 .join('\n');
22 fail("Failed on the '" + relativeFilePath + "' test case.\n\n" + patch);
23 }
24 });
25 });
26});
27function normalizeNewLines(value) {
28 return value ? value.replace(/\r?\n/g, '\n') : '';
29}
30//# sourceMappingURL=tsgen.spec.js.map
\No newline at end of file