This repository was archived by the owner on Jan 19, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathtsx.js
116 lines (99 loc) · 3.75 KB
/
tsx.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**
* @fileoverview Tests for TSX-specific constructs
* @author James Henry <https://github.com/JamesHenry>
* @copyright jQuery Foundation and other contributors, https://jquery.org/
* MIT License
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const
assert = require("assert"),
path = require("path"),
{ Linter } = require("eslint"),
shelljs = require("shelljs"),
parser = require("../../"),
testUtils = require("../../tools/test-utils");
//------------------------------------------------------------------------------
// Setup
//------------------------------------------------------------------------------
const TSX_FIXTURES_DIR = "./tests/fixtures/tsx";
const testFiles = shelljs.find(TSX_FIXTURES_DIR)
.filter(filename => filename.indexOf(".src.tsx") > -1)
// strip off ".src.tsx"
.map(filename => filename.substring(TSX_FIXTURES_DIR.length - 1, filename.length - 8));
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
describe("TSX", () => {
testFiles.forEach(filename => {
const code = shelljs.cat(`${path.resolve(TSX_FIXTURES_DIR, filename)}.src.tsx`);
const config = {
useJSXTextNode: true,
jsx: true
};
test(`fixtures/${filename}.src`, testUtils.createSnapshotTestBlock(code, config));
});
describe("if the filename ends with '.tsx', enable jsx option automatically.", () => {
const linter = new Linter();
linter.defineParser("typescript-eslint-parser", parser);
test("anonymous", () => {
const code = "const element = <T/>";
const config = {
parser: "typescript-eslint-parser"
};
const messages = linter.verify(code, config);
assert.deepStrictEqual(
messages,
[{
column: 18,
fatal: true,
line: 1,
message: "Parsing error: '>' expected.",
ruleId: null,
severity: 2,
source: "const element = <T/>"
}]
);
});
test("test.ts", () => {
const code = "const element = <T/>";
const config = {
parser: "typescript-eslint-parser"
};
const messages = linter.verify(code, config, { filename: "test.ts" });
assert.deepStrictEqual(
messages,
[{
column: 18,
fatal: true,
line: 1,
message: "Parsing error: '>' expected.",
ruleId: null,
severity: 2,
source: "const element = <T/>"
}]
);
});
test("test.ts with 'jsx' option", () => {
const code = "const element = <T/>";
const config = {
parser: "typescript-eslint-parser",
parserOptions: {
jsx: true
}
};
const messages = linter.verify(code, config, { filename: "test.ts" });
assert.deepStrictEqual(messages, []);
});
test("test.tsx", () => {
const code = "const element = <T/>";
const config = {
parser: "typescript-eslint-parser"
};
const messages = linter.verify(code, config, { filename: "test.tsx" });
assert.deepStrictEqual(messages, []);
});
});
});