Skip to content

Commit

Permalink
Fix eslintRunner test
Browse files Browse the repository at this point in the history
  • Loading branch information
lolgab committed May 22, 2024
1 parent 335ece3 commit 6663b2f
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 10 deletions.
19 changes: 9 additions & 10 deletions tools/eslintRunner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,25 @@ func TestRunEslintToFile(t *testing.T) {
defer os.RemoveAll(tempDir)

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

RunEslint(repositoryToAnalyze, eslintInstallationDirectory, nodeBinary, sarifOutputFile)
RunEslint(repositoryToAnalyze, eslintInstallationDirectory, nodeBinary, obtainedSarifFile)

expectedSarifBytes, err := os.ReadFile(sarifOutputFile)
expectedSarifBytes, err := os.ReadFile(expectedSarifFile)
if err != nil {
log.Fatal(err.Error())
log.Fatal(err)
}

eslintOutputPath := filepath.Join(tempDir, "eslint.sarif")

eslintOutputBytes, err := os.ReadFile(eslintOutputPath)
obtainedSarifBytes, err := os.ReadFile(obtainedSarifFile)
if err != nil {
log.Fatal(err.Error())
}
eslintOutput := string(eslintOutputBytes)
obtainedSarif := string(obtainedSarifBytes)
filePrefix := "file://" + currentDirectory + "/"
actualSarif := strings.ReplaceAll(eslintOutput, filePrefix, "")
actualSarif := strings.ReplaceAll(obtainedSarif, filePrefix, "")

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"version": "2.1.0",
"$schema": "http://json.schemastore.org/sarif-2.1.0-rtm.5",
"runs": [
{
"tool": {
"driver": {
"name": "ESLint",
"informationUri": "https://eslint.org",
"rules": [],
"version": "9.3.0"
}
},
"artifacts": [
{
"location": {
"uri": "file:///Users/lorenzo/codacy/github/codacy-cli-v2/tools/testdata/repositories/test1/src/eslint.config.mjs"
}
},
{
"location": {
"uri": "file:///Users/lorenzo/codacy/github/codacy-cli-v2/tools/testdata/repositories/test1/src/test.js"
}
}
],
"results": []
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"version": "2.1.0",
"$schema": "http://json.schemastore.org/sarif-2.1.0-rtm.5",
"runs": [
{
"tool": {
"driver": {
"name": "ESLint",
"informationUri": "https://eslint.org",
"rules": [],
"version": "9.3.0"
}
},
"artifacts": [
{
"location": {
"uri": "file:///Users/lorenzo/codacy/github/codacy-cli-v2/tools/testdata/repositories/test1/src/eslint.config.mjs"
}
},
{
"location": {
"uri": "file:///Users/lorenzo/codacy/github/codacy-cli-v2/tools/testdata/repositories/test1/src/test.js"
}
}
],
"results": []
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"version": "2.1.0",
"$schema": "http://json.schemastore.org/sarif-2.1.0-rtm.5",
"runs": [
{
"tool": {
"driver": {
"name": "ESLint",
"informationUri": "https://eslint.org",
"rules": [],
"version": "9.3.0"
}
},
"artifacts": [
{
"location": {
"uri": "file:///Users/lorenzo/codacy/github/codacy-cli-v2/tools/testdata/repositories/test1/src/eslint.config.mjs"
}
},
{
"location": {
"uri": "file:///Users/lorenzo/codacy/github/codacy-cli-v2/tools/testdata/repositories/test1/src/test.js"
}
}
],
"results": []
}
]
}

0 comments on commit 6663b2f

Please sign in to comment.