1
+ /* global require -- node */
1
2
import assert from "assert"
2
3
import fs from "fs"
4
+ import semver from "semver"
3
5
4
6
import { traverseNodes } from "../../../src/traverse"
5
7
import { parseForESLint } from "../../../src"
@@ -24,6 +26,7 @@ describe("Check for AST.", () => {
24
26
inputFileName,
25
27
outputFileName,
26
28
scopeFileName,
29
+ requirements,
27
30
} of listupFixtures ( ) ) {
28
31
describe ( inputFileName , ( ) => {
29
32
let result : any
@@ -34,11 +37,26 @@ describe("Check for AST.", () => {
34
37
const output = fs . readFileSync ( outputFileName , "utf8" )
35
38
assert . strictEqual ( astJson , output )
36
39
} )
37
- it ( "most to generate the expected scope." , ( ) => {
38
- const json = scopeToJSON ( result . scopeManager )
39
- const output = fs . readFileSync ( scopeFileName , "utf8" )
40
- assert . strictEqual ( json , output )
41
- } )
40
+ if ( canTest ( requirements , "scope" ) )
41
+ it ( "most to generate the expected scope." , ( ) => {
42
+ let json : any = scopeToJSON ( result . scopeManager )
43
+ let output : any = fs . readFileSync ( scopeFileName , "utf8" )
44
+
45
+ if (
46
+ result . services ?. program // use ts parser
47
+ ) {
48
+ // eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires -- ignore
49
+ const pkg = require ( "@typescript-eslint/parser/package.json" )
50
+ if ( ! semver . satisfies ( pkg . version , "^5.6.0" ) ) {
51
+ // adjust global scope
52
+ json = JSON . parse ( json )
53
+ output = JSON . parse ( output )
54
+ json . variables = output . variables
55
+ }
56
+ }
57
+
58
+ assert . deepStrictEqual ( json , output )
59
+ } )
42
60
43
61
it ( "location must be correct." , ( ) => {
44
62
// check tokens
@@ -58,6 +76,25 @@ describe("Check for AST.", () => {
58
76
}
59
77
} )
60
78
79
+ function canTest (
80
+ requirements : { scope ?: Record < string , string > } ,
81
+ key : "scope" ,
82
+ ) {
83
+ const obj = requirements [ key ]
84
+ if ( obj ) {
85
+ if (
86
+ Object . entries ( obj ) . some ( ( [ pkgName , pkgVersion ] ) => {
87
+ // eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires -- ignore
88
+ const pkg = require ( `${ pkgName } /package.json` )
89
+ return ! semver . satisfies ( pkg . version , pkgVersion )
90
+ } )
91
+ ) {
92
+ return false
93
+ }
94
+ }
95
+ return true
96
+ }
97
+
61
98
function checkTokens ( ast : SvelteProgram , input : string ) {
62
99
const allTokens = [ ...ast . tokens , ...ast . comments ] . sort (
63
100
( a , b ) => a . range [ 0 ] - b . range [ 0 ] ,
0 commit comments