Skip to content

Commit 0c1ebc8

Browse files
committed
test: eslint 6 and 7 integ tests
1 parent e87a5af commit 0c1ebc8

7 files changed

Lines changed: 208 additions & 13 deletions

File tree

src/brackets.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ define(function (require, exports, module) {
273273
Menus: require("command/Menus"),
274274
MultiRangeInlineEditor: require("editor/MultiRangeInlineEditor").MultiRangeInlineEditor,
275275
NativeApp: require("utils/NativeApp"),
276+
NodeUtils: require("utils/NodeUtils"),
276277
PerfUtils: require("utils/PerfUtils"),
277278
PreferencesManager: require("preferences/PreferencesManager"),
278279
ProjectManager: require("project/ProjectManager"),

src/extensions/default/JSLint/ESLint.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ define(function (require, exports, module) {
6464
let errorMessage = Strings.DESCRIPTION_ESLINT_FAILED;
6565
switch (errorCode) {
6666
case ESLINT_ERROR_LINT_FAILED:
67-
errorMessage = StringUtils.format(Strings.DESCRIPTION_ESLINT_FAILED, message? message : "Unknown"); break;
67+
errorMessage = StringUtils.format(Strings.DESCRIPTION_ESLINT_FAILED, message || "Unknown"); break;
6868
case ESLINT_ONLY_IN_NATIVE_APP:
6969
errorMessage = Strings.DESCRIPTION_ESLINT_USE_NATIVE_APP; break;
7070
case ESLINT_ERROR_MODULE_NOT_FOUND:
@@ -179,7 +179,7 @@ define(function (require, exports, module) {
179179

180180
function _reloadOptions() {
181181
esLintServiceFailed = false;
182-
_isESLintProject(ProjectManager.getProjectRoot().fullPath).then((shouldESLintEnable)=>{
182+
_isESLintProject().then((shouldESLintEnable)=>{
183183
useESLintFromProject = shouldESLintEnable;
184184
CodeInspection.requestRun(Strings.ESLINT_NAME);
185185
}).catch(()=>{
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*global module */
2+
3+
module.exports = {
4+
"rules": {
5+
// the rules below should be sorted in a same way they are sorted on http://eslint.org/docs/rules page
6+
// http://eslint.org/docs/rules/#possible-errors
7+
"no-caller": 2,
8+
"no-control-regex": 2,
9+
"no-empty": 1,
10+
"no-invalid-regexp": 2,
11+
"no-regex-spaces": 2,
12+
"no-unsafe-negation": 1,
13+
"valid-jsdoc": 0,
14+
"valid-typeof": 2,
15+
// http://eslint.org/docs/rules/#best-practices
16+
"curly": 2,
17+
"eqeqeq": [2, "smart"],
18+
"guard-for-in": 0,
19+
"no-else-return": 1,
20+
"no-fallthrough": 2,
21+
"no-invalid-this": 1,
22+
"no-iterator": 2,
23+
"no-loop-func": 2,
24+
"no-multi-str": 2,
25+
"no-new-func": 2,
26+
"no-new-wrappers": 2,
27+
"no-new": 2,
28+
"no-proto": 2,
29+
"no-redeclare": 1,
30+
"no-script-url": 2,
31+
"wrap-iife": [2, "outside"],
32+
// http://eslint.org/docs/rules/#strict-mode
33+
"strict": 2,
34+
// http://eslint.org/docs/rules/#variables
35+
"no-shadow-restricted-names": 2,
36+
"no-shadow": 1,
37+
"no-undef": 2,
38+
"no-unused-vars": [1, {"vars": "all", "args": "none"}],
39+
"no-use-before-define": 0,
40+
// http://eslint.org/docs/rules/#nodejs-and-commonjs
41+
"no-new-require": 2,
42+
// http://eslint.org/docs/rules/#stylistic-issues
43+
"block-spacing": 1,
44+
"brace-style": [1, "1tbs", { allowSingleLine: true }],
45+
"camelcase": 1,
46+
"comma-dangle": 2,
47+
"comma-spacing": 1,
48+
"comma-style": [1, "last"],
49+
"computed-property-spacing": 1,
50+
"eol-last": 1,
51+
"func-call-spacing": 1,
52+
"indent": [1, 4],
53+
"key-spacing": [1, { beforeColon: false, afterColon: true }],
54+
"max-len": [1, 120],
55+
"new-cap": [0, {
56+
"capIsNewExceptions": [
57+
"$.Deferred",
58+
"$.Event",
59+
"CodeMirror.Pos",
60+
"Immutable.Map",
61+
"Immutable.List",
62+
"JSLINT"
63+
]
64+
}],
65+
"new-parens": 2,
66+
"no-bitwise": 2,
67+
"no-new-object": 2,
68+
"no-trailing-spaces": 1,
69+
"semi-spacing": 1,
70+
"semi": 2,
71+
"no-async-promise-executor": 2
72+
},
73+
"globals": {
74+
"$": false,
75+
"deferredToPromise": false,
76+
"brackets": false,
77+
"Phoenix": false,
78+
"PhStore": false,
79+
"iconv": false,
80+
"Buffer": true,
81+
"clearTimeout": false,
82+
"console": false,
83+
"define": false,
84+
"require": false,
85+
"setTimeout": false,
86+
"window": false,
87+
"ArrayBuffer": false,
88+
"Uint32Array": false,
89+
"WebSocket": false,
90+
"XMLHttpRequest": false,
91+
"quiet": true
92+
},
93+
"env": {
94+
"browser": true,
95+
"commonjs": true,
96+
"es6": true,
97+
"worker": true
98+
},
99+
"parserOptions": {
100+
"ecmaVersion": 2020,
101+
"sourceType": "module",
102+
"ecmaFeatures": {
103+
"arrowFunctions": true,
104+
"binaryLiterals": true,
105+
"blockBindings": true,
106+
"classes": true
107+
}
108+
}
109+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"undef": true,
3+
"unused": true,
4+
"globals": {
5+
"MY_GLOBAL": true
6+
}
7+
}

test/spec/ESLintExtensionTest-files/ESLint_JSHint/error.js renamed to test/spec/ESLintExtensionTest-files/es7_JSHint/error.js

File renamed without changes.

test/spec/ESLintExtensionTest-files/ESLint_JSHint/package.json renamed to test/spec/ESLintExtensionTest-files/es7_JSHint/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
"version": "1.0.0",
44
"description": "",
55
"main": "index.js",
6-
"type": "module",
76
"scripts": {},
87
"author": "",
98
"license": "ISC",
109
"dependencies": {
11-
"eslint": "6.0.0"
10+
"eslint": "7.0.0"
1211
}
1312
}

test/spec/Extn-ESLint-integ-test.js

Lines changed: 88 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,20 @@ define(function (require, exports, module) {
2727
var SpecRunnerUtils = require("spec/SpecRunnerUtils");
2828

2929
describe("integration:ESLint", function () {
30-
let testProjectsFolder = SpecRunnerUtils.getTestPath("/spec/ESLintExtensionTest-files/"),
30+
const testRootSpec = "/spec/ESLintExtensionTest-files/";
31+
let testProjectsFolder = SpecRunnerUtils.getTestPath(testRootSpec),
3132
Strings = require("strings"),
3233
testWindow,
3334
$,
34-
CodeInspection;
35+
CodeInspection,
36+
NodeUtils;
3537

3638
beforeAll(async function () {
3739
testWindow = await SpecRunnerUtils.createTestWindowAndRun();
3840
// Load module instances from brackets.test
3941
$ = testWindow.$;
4042
CodeInspection = testWindow.brackets.test.CodeInspection;
43+
NodeUtils = testWindow.brackets.test.NodeUtils;
4144
CodeInspection.toggleEnabled(true);
4245
await awaitsFor(()=>testWindow._JsHintExtensionReadyToIntegTest,
4346
"JsHint extension to be loaded", 10000);
@@ -46,15 +49,27 @@ define(function (require, exports, module) {
4649
afterAll(async function () {
4750
testWindow = null;
4851
$ = null;
52+
NodeUtils = null;
53+
CodeInspection = null;
4954
await SpecRunnerUtils.closeTestWindow();
5055
}, 30000);
5156

52-
const JSHintErrorES6Errir_js = "Missing semicolon. jshint (W033)";
57+
const JSHintErrorES6Error_js = "Missing semicolon. jshint (W033)",
58+
ESLintErrorES7Error_js = "Parsing error: Unexpected token ; ESLint (null)";
59+
60+
async function _createTempProject(esLintSpecSubFolder) {
61+
return await SpecRunnerUtils.getTempTestDirectory(testRootSpec + esLintSpecSubFolder);
62+
}
5363

5464
async function _openProjectFile(fileName) {
5565
await awaitsForDone(SpecRunnerUtils.openProjectFiles([fileName]), "opening "+ fileName);
5666
}
5767

68+
async function _npmInstallInFolder(folder) {
69+
const npmInstallPlatformPath = Phoenix.fs.getTauriPlatformPath(folder);
70+
await NodeUtils._npmInstallInFolder(npmInstallPlatformPath);
71+
}
72+
5873
async function _waitForProblemsPanelVisible(visible) {
5974
await awaitsFor(()=>{
6075
return $("#problems-panel").is(":visible") === visible;
@@ -80,8 +95,8 @@ define(function (require, exports, module) {
8095
await _openSimpleES6Project();
8196

8297
await awaitsFor(()=>{
83-
return $("#problems-panel").text().includes(JSHintErrorES6Errir_js);
84-
}, JSHintErrorES6Errir_js);
98+
return $("#problems-panel").text().includes(JSHintErrorES6Error_js);
99+
}, JSHintErrorES6Error_js);
85100
});
86101
return;
87102
}
@@ -92,10 +107,9 @@ define(function (require, exports, module) {
92107
await awaitsFor(()=>{
93108
return $("#problems-panel").text().includes(Strings.DESCRIPTION_ESLINT_DO_NPM_INSTALL);
94109
}, Strings.DESCRIPTION_ESLINT_DO_NPM_INSTALL);
95-
});
110+
}, 5000);
96111

97-
it("should show JSHint in desktop app if ESLint load failed for project", async function () {
98-
await _openSimpleES6Project();
112+
async function _fileSwitcherroForESLintFailDetection() {
99113
// at this point, ESLint will try to load and fail to load. During first load only ESLint results will
100114
// be shown. But upon detecting ESLint load failure, the next JSHint will be shown too to help the user.
101115
// so we switch to another file and switch back to show jshint.
@@ -104,13 +118,78 @@ define(function (require, exports, module) {
104118
await _waitForProblemsPanelVisible(false);
105119
await _openProjectFile("error.js");
106120
await _waitForProblemsPanelVisible(true);
121+
}
107122

123+
it("should show JSHint in desktop app if ESLint load failed for project", async function () {
124+
await _openSimpleES6Project();
125+
await _fileSwitcherroForESLintFailDetection();
108126
await awaitsFor(()=>{
109127
return $("#problems-panel").text().includes(Strings.DESCRIPTION_ESLINT_DO_NPM_INSTALL);
110128
}, "ESLint error to be shown");
111129
await awaitsFor(()=>{
112-
return $("#problems-panel").text().includes(JSHintErrorES6Errir_js);
130+
return $("#problems-panel").text().includes(JSHintErrorES6Error_js);
113131
}, "JShint error to be shown");
132+
}, 5000);
133+
134+
describe("ES6 project", function () {
135+
let es6ProjectPath;
136+
137+
beforeAll(async function () {
138+
es6ProjectPath = await _createTempProject("es6");
139+
await _npmInstallInFolder(es6ProjectPath);
140+
await SpecRunnerUtils.loadProjectInTestWindow(es6ProjectPath);
141+
}, 30000);
142+
143+
async function _loadAndValidateES6Project() {
144+
await _openProjectFile("error.js");
145+
await _waitForProblemsPanelVisible(true);
146+
await awaitsFor(()=>{
147+
return $("#problems-panel").text().includes(Strings.DESCRIPTION_ESLINT_LOAD_FAILED);
148+
}, "ESLint v6 not supported error to be shown");
149+
}
150+
151+
it("should ESLint v6 show unsupported version error", async function () {
152+
await _loadAndValidateES6Project();
153+
}, 5000);
154+
155+
it("should show ESLint and JSHint in desktop app for es6 project or below", async function () {
156+
await _loadAndValidateES6Project();
157+
await _fileSwitcherroForESLintFailDetection();
158+
await awaitsFor(()=>{
159+
return $("#problems-panel").text().includes(JSHintErrorES6Error_js);
160+
}, "JShint error to be shown");
161+
}, 5000);
162+
});
163+
164+
describe("ES7 and JSHint project", function () {
165+
let es7ProjectPath;
166+
167+
beforeAll(async function () {
168+
es7ProjectPath = await _createTempProject("es7_JSHint");
169+
await _npmInstallInFolder(es7ProjectPath);
170+
await SpecRunnerUtils.loadProjectInTestWindow(es7ProjectPath);
171+
}, 30000);
172+
173+
async function _loadAndValidateES7Project() {
174+
await _openProjectFile("error.js");
175+
await _waitForProblemsPanelVisible(true);
176+
await awaitsFor(()=>{
177+
return $("#problems-panel").text().includes(ESLintErrorES7Error_js);
178+
}, "ESLint v7 error to be shown");
179+
}
180+
181+
it("should ESLint v7 work as expected", async function () {
182+
await _loadAndValidateES7Project();
183+
}, 5000);
184+
185+
it("should show ESLint and JSHint in desktop app if .jshintrc Present", async function () {
186+
await _loadAndValidateES7Project();
187+
await awaitsFor(()=>{
188+
return $("#problems-panel").text().includes(JSHintErrorES6Error_js);
189+
}, "JShint error to be shown");
190+
}, 5000);
191+
192+
// todo eslint module test
114193
});
115194
});
116195
});

0 commit comments

Comments
 (0)