@@ -11,6 +11,12 @@ import * as fs from 'fs';
11
11
import { getFilename } from '../utils' ;
12
12
import { test as testUnambiguous } from 'eslint-module-utils/unambiguous' ;
13
13
14
+ const doesBabelHaveVisitorKeys = ( ) => {
15
+ const babelPath = require . resolve ( 'babel-eslint' ) ;
16
+ const hypotheticalLocation = babelPath . replace ( 'index.js' , 'visitor-keys.js' ) ;
17
+ return fs . existsSync ( hypotheticalLocation ) ;
18
+ } ;
19
+
14
20
describe ( 'ExportMap' , function ( ) {
15
21
const fakeContext = Object . assign (
16
22
semver . satisfies ( eslintPkg . version , '>= 7.28' ) ? {
@@ -21,10 +27,12 @@ describe('ExportMap', function () {
21
27
} ,
22
28
{
23
29
settings : { } ,
24
- parserPath : 'babel-eslint' ,
30
+ parserPath : require . resolve ( 'babel-eslint' ) ,
25
31
} ,
26
32
) ;
27
33
34
+ const isVisitorKeysSupported = doesBabelHaveVisitorKeys ( ) ;
35
+
28
36
it ( 'handles ExportAllDeclaration' , function ( ) {
29
37
let imports ;
30
38
expect ( function ( ) {
@@ -36,11 +44,20 @@ describe('ExportMap', function () {
36
44
37
45
} ) ;
38
46
39
- it ( 'returns a cached copy on subsequent requests' , function ( ) {
47
+ isVisitorKeysSupported && it ( 'returns a cached copy on subsequent requests' , function ( ) {
40
48
expect ( ExportMapBuilder . get ( './named-exports' , fakeContext ) )
41
49
. to . exist . and . equal ( ExportMapBuilder . get ( './named-exports' , fakeContext ) ) ;
42
50
} ) ;
43
51
52
+ it ( 'does not return a cached copy if the parse does not yield a visitor keys' , function ( ) {
53
+ const mockContext = {
54
+ ...fakeContext ,
55
+ parserPath : 'not-real' ,
56
+ } ;
57
+ expect ( ExportMapBuilder . get ( './named-exports' , mockContext ) )
58
+ . to . exist . and . not . equal ( ExportMapBuilder . get ( './named-exports' , mockContext ) ) ;
59
+ } ) ;
60
+
44
61
it ( 'does not return a cached copy after modification' , ( done ) => {
45
62
const firstAccess = ExportMapBuilder . get ( './mutator' , fakeContext ) ;
46
63
expect ( firstAccess ) . to . exist ;
0 commit comments