1919 *
2020 */
2121
22- /*global describe, it, expect, beforeAll, afterAll, awaitsForDone, awaits, awaitsFor */
22+ /*global describe, it, expect, beforeAll, afterAll, awaitsForDone, awaits, awaitsFor, path, jsPromise */
2323
2424define ( function ( require , exports , module ) {
2525
@@ -33,14 +33,16 @@ define(function (require, exports, module) {
3333 testWindow ,
3434 $ ,
3535 CodeInspection ,
36- NodeUtils ;
36+ NodeUtils ,
37+ FileSystem ;
3738
3839 beforeAll ( async function ( ) {
3940 testWindow = await SpecRunnerUtils . createTestWindowAndRun ( ) ;
4041 // Load module instances from brackets.test
4142 $ = testWindow . $ ;
4243 CodeInspection = testWindow . brackets . test . CodeInspection ;
4344 NodeUtils = testWindow . brackets . test . NodeUtils ;
45+ FileSystem = testWindow . brackets . test . FileSystem ;
4446 CodeInspection . toggleEnabled ( true ) ;
4547 await awaitsFor ( ( ) => testWindow . _JsHintExtensionReadyToIntegTest ,
4648 "JsHint extension to be loaded" , 10000 ) ;
@@ -51,6 +53,7 @@ define(function (require, exports, module) {
5153 $ = null ;
5254 NodeUtils = null ;
5355 CodeInspection = null ;
56+ FileSystem = null ;
5457 await SpecRunnerUtils . closeTestWindow ( ) ;
5558 } , 30000 ) ;
5659
@@ -220,6 +223,94 @@ define(function (require, exports, module) {
220223 } , 5000 ) ;
221224 } ) ;
222225
226+ describe ( "ES Latest module project" , function ( ) {
227+ let esLatestProjectPath , configPath ;
228+ const CONFIG_FILE_NAME = "eslint.config.js" ;
229+ const MODULE_CONFIG_TEXT = `export default [
230+ {
231+ rules: {
232+ semi: "error",
233+ "prefer-const": "error"
234+ }
235+ }
236+ ];` , MODULE_CONFIG_TEXT_EQ_RULE = `export default [
237+ {
238+ rules: {
239+ semi: "error",
240+ "prefer-const": "error",
241+ "eqeqeq": "warn"
242+ }
243+ }
244+ ];` , COMMON_JS_CONFIG_TEXT = `// eslint.config.js
245+ module.exports = [
246+ {
247+ rules: {
248+ semi: "error",
249+ "prefer-const": "error"
250+ }
251+ }
252+ ];` ;
253+
254+ beforeAll ( async function ( ) {
255+ esLatestProjectPath = await _createTempProject ( "es_latest_no_config" ) ;
256+ configPath = path . join ( esLatestProjectPath , CONFIG_FILE_NAME ) ;
257+ await _npmInstallInFolder ( esLatestProjectPath ) ;
258+ await SpecRunnerUtils . loadProjectInTestWindow ( esLatestProjectPath ) ;
259+ } , 30000 ) ;
260+
261+ let initDone = false ;
262+ async function _loadAndValidateESLatestProject ( ) {
263+ if ( initDone ) {
264+ return ;
265+ }
266+ await _openProjectFile ( "error.js" ) ;
267+ await _waitForProblemsPanelVisible ( true ) ;
268+ await awaitsFor ( ( ) => {
269+ return $ ( "#problems-panel" ) . text ( ) . includes (
270+ "ESLint Failed (Could not find config file.). Make sure the project contains valid"
271+ ) ;
272+ } , "ESLint v8 error to be shown" ) ;
273+
274+ // this Project is of type="module", so loading a common js eslint config should show an error
275+ await jsPromise ( SpecRunnerUtils . createTextFile ( configPath , COMMON_JS_CONFIG_TEXT , FileSystem ) ) ;
276+ await _openProjectFile ( CONFIG_FILE_NAME ) ;
277+ await _openProjectFile ( "error.js" ) ;
278+ await awaitsFor ( ( ) => {
279+ return $ ( "#problems-panel" ) . text ( ) . includes (
280+ "eslint.config.js: module is not defined in ES module scope"
281+ ) ;
282+ } , "using a requirejs config in es-module error" ) ;
283+
284+ // now write the es module config and eslint should now work
285+ await jsPromise ( SpecRunnerUtils . createTextFile ( configPath , MODULE_CONFIG_TEXT , FileSystem ) ) ;
286+ await _openProjectFile ( CONFIG_FILE_NAME ) ;
287+ await _openProjectFile ( "error.js" ) ;
288+ await awaitsFor ( ( ) => {
289+ return $ ( "#problems-panel" ) . text ( ) . includes (
290+ "Missing semicolon. ESLint (semi)"
291+ ) ;
292+ } , "eslint valid errors to be shown" ) ;
293+ initDone = true ;
294+ }
295+
296+ it ( "should ESLint Latest work as expected" , async function ( ) {
297+ await _loadAndValidateESLatestProject ( ) ;
298+ } , 5000 ) ;
299+
300+ it ( "should be able to change eslint rules config file after its loaded" , async function ( ) {
301+ await _loadAndValidateESLatestProject ( ) ;
302+ // now change the current es module config and eslint should load the new rules
303+ await jsPromise ( SpecRunnerUtils . createTextFile ( configPath , MODULE_CONFIG_TEXT_EQ_RULE , FileSystem ) ) ;
304+ await _openProjectFile ( CONFIG_FILE_NAME ) ;
305+ await _openProjectFile ( "error.js" ) ;
306+ await awaitsFor ( ( ) => {
307+ return $ ( "#problems-panel" ) . text ( ) . includes (
308+ "Expected '===' and instead saw '=='. ESLint (eqeqeq)"
309+ ) ;
310+ } , "eslint new eq rule added to be honored in lint" ) ;
311+ } , 5000 ) ;
312+ } ) ;
313+
223314 // todo eslint module test for es9
224315 } ) ;
225316} ) ;
0 commit comments