1010import * as exports from "../../src/index.js" ;
1111import assert from "node:assert" ;
1212
13+ import path from "node:path" ;
14+ import fs from "node:fs/promises" ;
15+ import { fileURLToPath , pathToFileURL } from "node:url" ;
16+
17+ //-----------------------------------------------------------------------------
18+ // Helpers
19+ //-----------------------------------------------------------------------------
20+
21+ const filename = fileURLToPath ( import . meta. url ) ;
22+ const dirname = path . dirname ( filename ) ;
23+ const rulesDir = path . resolve ( dirname , "../../src/rules" ) ;
24+
1325//------------------------------------------------------------------------------
1426// Tests
1527//------------------------------------------------------------------------------
@@ -24,6 +36,32 @@ describe("Package exports", () => {
2436 ] ) ;
2537 } ) ;
2638
39+ it ( "has all available rules exported in the ESLint plugin" , async ( ) => {
40+ const allRules = ( await fs . readdir ( rulesDir ) )
41+ . filter ( name => name . endsWith ( ".js" ) )
42+ . map ( name => name . slice ( 0 , - ".js" . length ) )
43+ . sort ( ) ;
44+ const exportedRules = exports . default . rules ;
45+
46+ assert . deepStrictEqual (
47+ Object . keys ( exportedRules ) . sort ( ) ,
48+ allRules ,
49+ "Expected all rules to be exported in the ESLint plugin (`plugin.rules` in `src/index.js`)" ,
50+ ) ;
51+
52+ for ( const [ ruleName , rule ] of Object . entries ( exportedRules ) ) {
53+ assert . strictEqual (
54+ rule ,
55+ (
56+ await import (
57+ pathToFileURL ( path . resolve ( rulesDir , `${ ruleName } .js` ) )
58+ )
59+ ) . default ,
60+ `Expected ${ ruleName } .js to be exported under key "${ ruleName } " in the ESLint plugin (\`plugin.rules\` in \`src/index.js\`)` ,
61+ ) ;
62+ }
63+ } ) ;
64+
2765 it ( "has a CSSLanguage export" , ( ) => {
2866 assert . ok ( exports . CSSLanguage ) ;
2967 } ) ;
0 commit comments