Skip to content

Commit e87a5af

Browse files
committed
test: integ tests for ESLint initial
1 parent 429afed commit e87a5af

9 files changed

Lines changed: 279 additions & 124 deletions

File tree

src/extensions/default/JSLint/ESLint.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ define(function (require, exports, module) {
5151

5252
const PREFS_ESLINT_DISABLED = "disabled";
5353

54+
// this is set to true if the service itself is not active/failed to start.
55+
let esLintServiceFailed = false;
56+
5457
prefs.definePreference(PREFS_ESLINT_DISABLED, "boolean", false, {
5558
description: Strings.DESCRIPTION_ESLINT_DISABLE
5659
}).on("change", function () {
@@ -123,10 +126,13 @@ define(function (require, exports, module) {
123126
}
124127
NodeUtils.ESLintFile(text, fullPath, ProjectManager.getProjectRoot().fullPath).then(esLintResult =>{
125128
if (esLintResult.result && esLintResult.result.messages && esLintResult.result.messages.length) {
129+
esLintServiceFailed = false;
126130
resolve({ errors: _getErrors(esLintResult.result.messages) });
127131
} else if(esLintResult.isError) {
132+
esLintServiceFailed = true;
128133
resolve({ errors: _getLintError(esLintResult.errorCode, esLintResult.errorMessage) });
129134
} else {
135+
esLintServiceFailed = false;
130136
if(!esLintResult.result){
131137
console.error("ESLint Unknown result", esLintResult);
132138
}
@@ -172,6 +178,7 @@ define(function (require, exports, module) {
172178
}
173179

174180
function _reloadOptions() {
181+
esLintServiceFailed = false;
175182
_isESLintProject(ProjectManager.getProjectRoot().fullPath).then((shouldESLintEnable)=>{
176183
useESLintFromProject = shouldESLintEnable;
177184
CodeInspection.requestRun(Strings.ESLINT_NAME);
@@ -227,7 +234,7 @@ define(function (require, exports, module) {
227234
});
228235

229236
function isESLintActive() {
230-
return useESLintFromProject && Phoenix.isNativeApp;
237+
return useESLintFromProject && Phoenix.isNativeApp && !esLintServiceFailed;
231238
}
232239

233240
exports.isESLintActive = isESLintActive;
Lines changed: 0 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +0,0 @@
1-
/*
2-
* GNU AGPL-3.0 License
3-
*
4-
* Copyright (c) 2021 - present core.ai . All rights reserved.
5-
* Original work Copyright (c) 2013 - 2021 Adobe Systems Incorporated. All rights reserved.
6-
*
7-
* This program is free software: you can redistribute it and/or modify it
8-
* under the terms of the GNU Affero General Public License as published by
9-
* the Free Software Foundation, either version 3 of the License, or
10-
* (at your option) any later version.
11-
*
12-
* This program is distributed in the hope that it will be useful, but WITHOUT
13-
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14-
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
15-
* for more details.
16-
*
17-
* You should have received a copy of the GNU Affero General Public License
18-
* along with this program. If not, see https://opensource.org/licenses/AGPL-3.0.
19-
*
20-
*/
21-
22-
/*global describe, it, expect, beforeAll, afterAll, awaitsForDone, awaits, awaitsFor */
23-
24-
define(function (require, exports, module) {
25-
26-
27-
var SpecRunnerUtils = brackets.getModule("spec/SpecRunnerUtils");
28-
29-
describe("integration:JSHint", function () {
30-
let testProjectsFolder = SpecRunnerUtils.getTestPath("/spec/JSHintExtensionTest-files/"),
31-
testWindow,
32-
$,
33-
CodeInspection;
34-
35-
var toggleJSLintResults = function () {
36-
$("#status-inspection").triggerHandler("click");
37-
};
38-
39-
beforeAll(async function () {
40-
testWindow = await SpecRunnerUtils.createTestWindowAndRun();
41-
// Load module instances from brackets.test
42-
$ = testWindow.$;
43-
CodeInspection = testWindow.brackets.test.CodeInspection;
44-
CodeInspection.toggleEnabled(true);
45-
await awaitsFor(()=>testWindow._JsHintExtensionReadyToIntegTest,
46-
"JsHint extension to be loaded", 10000);
47-
}, 30000);
48-
49-
afterAll(async function () {
50-
testWindow = null;
51-
$ = null;
52-
await SpecRunnerUtils.closeTestWindow();
53-
}, 30000);
54-
55-
it("status icon should toggle Errors panel when errors present", async function () {
56-
await SpecRunnerUtils.loadProjectInTestWindow(testProjectsFolder + "valid-config-error");
57-
await awaitsForDone(SpecRunnerUtils.openProjectFiles(["es8.js"]), "open test file with error");
58-
await awaitsFor(()=>{
59-
return $("#problems-panel").is(":visible");
60-
}, "Problems panel to be visible");
61-
62-
toggleJSLintResults();
63-
await awaitsFor(()=>{
64-
return !$("#problems-panel").is(":visible");
65-
}, "Problems panel to be hidden");
66-
67-
toggleJSLintResults();
68-
await awaitsFor(()=>{
69-
return $("#problems-panel").is(":visible");
70-
}, "Problems panel to be visible");
71-
});
72-
73-
it("should show errors if invalid .jshintrc detected", async function () {
74-
await SpecRunnerUtils.loadProjectInTestWindow(testProjectsFolder + "invalid-config");
75-
await awaitsForDone(SpecRunnerUtils.openProjectFiles(["no-errors.js"]), "open test file");
76-
await awaitsFor(()=>{
77-
return $("#problems-panel").is(":visible");
78-
}, "Problems panel to be visible");
79-
});
80-
81-
it("should load valid es6 .jshintrc in project", async function () {
82-
await SpecRunnerUtils.loadProjectInTestWindow(testProjectsFolder + "valid-config-es6");
83-
// es6 file should have no errors in problems panel
84-
await awaitsForDone(SpecRunnerUtils.openProjectFiles(["es6.js"]), "open test file es6.js");
85-
86-
await awaits(100);
87-
await awaitsFor(()=>{
88-
return !$("#problems-panel").is(":visible");
89-
}, "Problems panel to be hidden");
90-
91-
// using es8 async feature in es6 jshint mode should have errors in problems panel
92-
await awaitsForDone(SpecRunnerUtils.openProjectFiles(["es8.js"]), "open test file es8.js");
93-
await awaitsFor(()=>{
94-
return $("#problems-panel").is(":visible");
95-
}, "Problems panel to be visible");
96-
});
97-
98-
it("should extend valid es6 .jshintrc in project", async function () {
99-
await SpecRunnerUtils.loadProjectInTestWindow(testProjectsFolder + "valid-config-es6-extend");
100-
// es6 file should have no errors in problems panel
101-
await awaitsForDone(SpecRunnerUtils.openProjectFiles(["es6.js"]), "open test file es6.js");
102-
103-
await awaits(100);
104-
await awaitsFor(()=>{
105-
return !$("#problems-panel").is(":visible");
106-
}, "Problems panel to be hidden");
107-
108-
// using es8 async feature in es6 jshint mode should have errors in problems panel
109-
await awaitsForDone(SpecRunnerUtils.openProjectFiles(["es8.js"]), "open test file es8.js");
110-
await awaitsFor(()=>{
111-
return $("#problems-panel").is(":visible");
112-
}, "Problems panel to be visible");
113-
});
114-
115-
it("should show errors if invalid .jshintrc extend file detected", async function () {
116-
await SpecRunnerUtils.loadProjectInTestWindow(testProjectsFolder + "invalid-config-extend");
117-
await awaitsForDone(SpecRunnerUtils.openProjectFiles(["no-errors.js"]), "open test file");
118-
await awaitsFor(()=>{
119-
return $("#problems-panel").is(":visible");
120-
}, "Problems panel to be visible");
121-
});
122-
});
123-
});

test/UnitTestSuite.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ define(function (require, exports, module) {
120120
require("spec/Extn-RemoteFileAdapter-integ-test");
121121
require("spec/Extn-NavigationAndHistory-integ-test");
122122
require("spec/Extn-RecentProjects-integ-test");
123+
require("spec/Extn-JSHint-integ-test");
124+
require("spec/Extn-ESLint-integ-test");
123125
// extension integration tests
124126
require("spec/Extn-CSSCodeHints-integ-test");
125127
// Node Tests
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
console.log("hello")
2+
const x;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "misc",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"type": "module",
7+
"scripts": {},
8+
"author": "",
9+
"license": "ISC",
10+
"dependencies": {
11+
"eslint": "6.0.0"
12+
}
13+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
console.log("hello")
2+
const x;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "misc",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"type": "module",
7+
"scripts": {},
8+
"author": "",
9+
"license": "ISC",
10+
"dependencies": {
11+
"eslint": "6.0.0"
12+
}
13+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* GNU AGPL-3.0 License
3+
*
4+
* Copyright (c) 2021 - present core.ai . All rights reserved.
5+
* Original work Copyright (c) 2013 - 2021 Adobe Systems Incorporated. All rights reserved.
6+
*
7+
* This program is free software: you can redistribute it and/or modify it
8+
* under the terms of the GNU Affero General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful, but WITHOUT
13+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
15+
* for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
* along with this program. If not, see https://opensource.org/licenses/AGPL-3.0.
19+
*
20+
*/
21+
22+
/*global describe, it, expect, beforeAll, afterAll, awaitsForDone, awaits, awaitsFor */
23+
24+
define(function (require, exports, module) {
25+
26+
27+
var SpecRunnerUtils = require("spec/SpecRunnerUtils");
28+
29+
describe("integration:ESLint", function () {
30+
let testProjectsFolder = SpecRunnerUtils.getTestPath("/spec/ESLintExtensionTest-files/"),
31+
Strings = require("strings"),
32+
testWindow,
33+
$,
34+
CodeInspection;
35+
36+
beforeAll(async function () {
37+
testWindow = await SpecRunnerUtils.createTestWindowAndRun();
38+
// Load module instances from brackets.test
39+
$ = testWindow.$;
40+
CodeInspection = testWindow.brackets.test.CodeInspection;
41+
CodeInspection.toggleEnabled(true);
42+
await awaitsFor(()=>testWindow._JsHintExtensionReadyToIntegTest,
43+
"JsHint extension to be loaded", 10000);
44+
}, 30000);
45+
46+
afterAll(async function () {
47+
testWindow = null;
48+
$ = null;
49+
await SpecRunnerUtils.closeTestWindow();
50+
}, 30000);
51+
52+
const JSHintErrorES6Errir_js = "Missing semicolon. jshint (W033)";
53+
54+
async function _openProjectFile(fileName) {
55+
await awaitsForDone(SpecRunnerUtils.openProjectFiles([fileName]), "opening "+ fileName);
56+
}
57+
58+
async function _waitForProblemsPanelVisible(visible) {
59+
await awaitsFor(()=>{
60+
return $("#problems-panel").is(":visible") === visible;
61+
}, "Problems panel to be visible");
62+
}
63+
64+
async function _openSimpleES6Project() {
65+
await SpecRunnerUtils.loadProjectInTestWindow(testProjectsFolder + "es6");
66+
await _openProjectFile("error.js");
67+
await _waitForProblemsPanelVisible(true);
68+
}
69+
70+
if(!Phoenix.isNativeApp) {
71+
it("should show download desktop app in browser for eslint project", async function () {
72+
await _openSimpleES6Project();
73+
74+
await awaitsFor(()=>{
75+
return $("#problems-panel").text().includes("ESLint is only available in the Desktop app");
76+
}, "ESLint is only available in Desktop app");
77+
});
78+
79+
it("should show JSHint in browser even for ESLint project with no JSHint config", async function () {
80+
await _openSimpleES6Project();
81+
82+
await awaitsFor(()=>{
83+
return $("#problems-panel").text().includes(JSHintErrorES6Errir_js);
84+
}, JSHintErrorES6Errir_js);
85+
});
86+
return;
87+
}
88+
89+
it("should show npm install message if eslint node module not found", async function () {
90+
await _openSimpleES6Project();
91+
92+
await awaitsFor(()=>{
93+
return $("#problems-panel").text().includes(Strings.DESCRIPTION_ESLINT_DO_NPM_INSTALL);
94+
}, Strings.DESCRIPTION_ESLINT_DO_NPM_INSTALL);
95+
});
96+
97+
it("should show JSHint in desktop app if ESLint load failed for project", async function () {
98+
await _openSimpleES6Project();
99+
// at this point, ESLint will try to load and fail to load. During first load only ESLint results will
100+
// be shown. But upon detecting ESLint load failure, the next JSHint will be shown too to help the user.
101+
// so we switch to another file and switch back to show jshint.
102+
103+
await _openProjectFile("package.json");
104+
await _waitForProblemsPanelVisible(false);
105+
await _openProjectFile("error.js");
106+
await _waitForProblemsPanelVisible(true);
107+
108+
await awaitsFor(()=>{
109+
return $("#problems-panel").text().includes(Strings.DESCRIPTION_ESLINT_DO_NPM_INSTALL);
110+
}, "ESLint error to be shown");
111+
await awaitsFor(()=>{
112+
return $("#problems-panel").text().includes(JSHintErrorES6Errir_js);
113+
}, "JShint error to be shown");
114+
});
115+
});
116+
});

0 commit comments

Comments
 (0)