diff --git a/tools/eslintRunner_test.go b/tools/eslintRunner_test.go index 0b99725..4b8b392 100644 --- a/tools/eslintRunner_test.go +++ b/tools/eslintRunner_test.go @@ -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)) diff --git a/tools/testdata/repositories/test1/sarif.json b/tools/testdata/repositories/test1/expected.sarif similarity index 100% rename from tools/testdata/repositories/test1/sarif.json rename to tools/testdata/repositories/test1/expected.sarif diff --git a/tools/testdata/repositories/test1/src/testdata/repositories/test1/eslint.sarif b/tools/testdata/repositories/test1/src/testdata/repositories/test1/eslint.sarif new file mode 100644 index 0000000..2285ac0 --- /dev/null +++ b/tools/testdata/repositories/test1/src/testdata/repositories/test1/eslint.sarif @@ -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": [] + } + ] +} \ No newline at end of file diff --git a/tools/testdata/repositories/test1/src/testdata/repositories/test1/expected.sarif b/tools/testdata/repositories/test1/src/testdata/repositories/test1/expected.sarif new file mode 100644 index 0000000..2285ac0 --- /dev/null +++ b/tools/testdata/repositories/test1/src/testdata/repositories/test1/expected.sarif @@ -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": [] + } + ] +} \ No newline at end of file diff --git a/tools/testdata/repositories/test1/src/testdata/repositories/test1/sarif.json b/tools/testdata/repositories/test1/src/testdata/repositories/test1/sarif.json new file mode 100644 index 0000000..2285ac0 --- /dev/null +++ b/tools/testdata/repositories/test1/src/testdata/repositories/test1/sarif.json @@ -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": [] + } + ] +} \ No newline at end of file