Skip to content

Commit 6663b2f

Browse files
committed
Fix eslintRunner test
1 parent 335ece3 commit 6663b2f

File tree

5 files changed

+96
-10
lines changed

5 files changed

+96
-10
lines changed

tools/eslintRunner_test.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,25 @@ func TestRunEslintToFile(t *testing.T) {
2424
defer os.RemoveAll(tempDir)
2525

2626
repositoryToAnalyze := filepath.Join(testDirectory, "src")
27-
sarifOutputFile := filepath.Join(testDirectory, "sarif.json")
28-
eslintInstallationDirectory := filepath.Join(homeDirectory, ".cache/codacy-cli-v2/tools/eslint")
27+
expectedSarifFile := filepath.Join(testDirectory, "expected.sarif")
28+
eslintInstallationDirectory := filepath.Join(homeDirectory, ".cache/codacy/tools/eslint@9.3.0")
2929
nodeBinary := "node"
30+
obtainedSarifFile := filepath.Join(tempDir, "eslint.sarif")
3031

31-
RunEslint(repositoryToAnalyze, eslintInstallationDirectory, nodeBinary, sarifOutputFile)
32+
RunEslint(repositoryToAnalyze, eslintInstallationDirectory, nodeBinary, obtainedSarifFile)
3233

33-
expectedSarifBytes, err := os.ReadFile(sarifOutputFile)
34+
expectedSarifBytes, err := os.ReadFile(expectedSarifFile)
3435
if err != nil {
35-
log.Fatal(err.Error())
36+
log.Fatal(err)
3637
}
3738

38-
eslintOutputPath := filepath.Join(tempDir, "eslint.sarif")
39-
40-
eslintOutputBytes, err := os.ReadFile(eslintOutputPath)
39+
obtainedSarifBytes, err := os.ReadFile(obtainedSarifFile)
4140
if err != nil {
4241
log.Fatal(err.Error())
4342
}
44-
eslintOutput := string(eslintOutputBytes)
43+
obtainedSarif := string(obtainedSarifBytes)
4544
filePrefix := "file://" + currentDirectory + "/"
46-
actualSarif := strings.ReplaceAll(eslintOutput, filePrefix, "")
45+
actualSarif := strings.ReplaceAll(obtainedSarif, filePrefix, "")
4746

4847
expectedSarif := strings.TrimSpace(string(expectedSarifBytes))
4948

File renamed without changes.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"version": "2.1.0",
3+
"$schema": "http://json.schemastore.org/sarif-2.1.0-rtm.5",
4+
"runs": [
5+
{
6+
"tool": {
7+
"driver": {
8+
"name": "ESLint",
9+
"informationUri": "https://eslint.org",
10+
"rules": [],
11+
"version": "9.3.0"
12+
}
13+
},
14+
"artifacts": [
15+
{
16+
"location": {
17+
"uri": "file:///Users/lorenzo/codacy/github/codacy-cli-v2/tools/testdata/repositories/test1/src/eslint.config.mjs"
18+
}
19+
},
20+
{
21+
"location": {
22+
"uri": "file:///Users/lorenzo/codacy/github/codacy-cli-v2/tools/testdata/repositories/test1/src/test.js"
23+
}
24+
}
25+
],
26+
"results": []
27+
}
28+
]
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"version": "2.1.0",
3+
"$schema": "http://json.schemastore.org/sarif-2.1.0-rtm.5",
4+
"runs": [
5+
{
6+
"tool": {
7+
"driver": {
8+
"name": "ESLint",
9+
"informationUri": "https://eslint.org",
10+
"rules": [],
11+
"version": "9.3.0"
12+
}
13+
},
14+
"artifacts": [
15+
{
16+
"location": {
17+
"uri": "file:///Users/lorenzo/codacy/github/codacy-cli-v2/tools/testdata/repositories/test1/src/eslint.config.mjs"
18+
}
19+
},
20+
{
21+
"location": {
22+
"uri": "file:///Users/lorenzo/codacy/github/codacy-cli-v2/tools/testdata/repositories/test1/src/test.js"
23+
}
24+
}
25+
],
26+
"results": []
27+
}
28+
]
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"version": "2.1.0",
3+
"$schema": "http://json.schemastore.org/sarif-2.1.0-rtm.5",
4+
"runs": [
5+
{
6+
"tool": {
7+
"driver": {
8+
"name": "ESLint",
9+
"informationUri": "https://eslint.org",
10+
"rules": [],
11+
"version": "9.3.0"
12+
}
13+
},
14+
"artifacts": [
15+
{
16+
"location": {
17+
"uri": "file:///Users/lorenzo/codacy/github/codacy-cli-v2/tools/testdata/repositories/test1/src/eslint.config.mjs"
18+
}
19+
},
20+
{
21+
"location": {
22+
"uri": "file:///Users/lorenzo/codacy/github/codacy-cli-v2/tools/testdata/repositories/test1/src/test.js"
23+
}
24+
}
25+
],
26+
"results": []
27+
}
28+
]
29+
}

0 commit comments

Comments
 (0)