Skip to content

Commit

Permalink
refactor: Restructure rules tests to use a common execution
Browse files Browse the repository at this point in the history
  • Loading branch information
d3xter666 committed Apr 19, 2024
1 parent ac48438 commit 474e419
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 21 deletions.
9 changes: 9 additions & 0 deletions test/lib/linter/_linterHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import anyTest, {ExecutionContext, TestFn} from "ava";
import sinonGlobal, {SinonStub} from "sinon";
import util from "util";
import {readdirSync} from "node:fs";
import path from "node:path";
import esmock from "esmock";
import SourceFileLinter from "../../../src/linter/ui5Types/SourceFileLinter.js";
import {SourceFile, TypeChecker} from "typescript";
Expand Down Expand Up @@ -125,3 +126,11 @@ export function preprocessLintResultsForSnapshot(res: LintResult[]) {
});
return res;
}

export function runLintRulesTests(filePath: string) {
const __dirname = path.dirname(filePath);
const fileName = path.basename(filePath, ".ts");
const fixturesPath = path.join(__dirname, "..", "..", "..", "fixtures", "linter", "rules", fileName);

createTestsForFixtures(fixturesPath);
}
5 changes: 5 additions & 0 deletions test/lib/linter/rules/BestPractices.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {fileURLToPath} from "node:url";
import {runLintRulesTests} from "../_linterHelper.js";

const filePath = fileURLToPath(import.meta.url);
runLintRulesTests(filePath);
9 changes: 2 additions & 7 deletions test/lib/linter/rules/CSPCompliance.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import path from "node:path";
import {fileURLToPath} from "node:url";
import {createTestsForFixtures} from "../_linterHelper.js";
import {runLintRulesTests} from "../_linterHelper.js";

const filePath = fileURLToPath(import.meta.url);
const __dirname = path.dirname(filePath);
const fileName = path.basename(filePath, ".ts");
const fixturesPath = path.join(__dirname, "..", "..", "..", "fixtures", "linter", "rules", fileName);

createTestsForFixtures(fixturesPath);
runLintRulesTests(filePath);
9 changes: 2 additions & 7 deletions test/lib/linter/rules/NoGlobals.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import path from "node:path";
import {fileURLToPath} from "node:url";
import {createTestsForFixtures} from "../_linterHelper.js";
import {runLintRulesTests} from "../_linterHelper.js";

const filePath = fileURLToPath(import.meta.url);
const __dirname = path.dirname(filePath);
const fileName = path.basename(filePath, ".ts");
const fixturesPath = path.join(__dirname, "..", "..", "..", "fixtures", "linter", "rules", fileName);

createTestsForFixtures(fixturesPath);
runLintRulesTests(filePath);
9 changes: 2 additions & 7 deletions test/lib/linter/rules/NoPseudoModules.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import path from "node:path";
import {fileURLToPath} from "node:url";
import {createTestsForFixtures} from "../_linterHelper.js";
import {runLintRulesTests} from "../_linterHelper.js";

const filePath = fileURLToPath(import.meta.url);
const __dirname = path.dirname(filePath);
const fileName = path.basename(filePath, ".ts");
const fixturesPath = path.join(__dirname, "..", "..", "..", "fixtures", "linter", "rules", fileName);

createTestsForFixtures(fixturesPath);
runLintRulesTests(filePath);
42 changes: 42 additions & 0 deletions test/lib/linter/rules/snapshots/BestPractices.ts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Snapshot report for `test/lib/linter/rules/BestPractices.ts`

The actual snapshot is saved in `BestPractices.ts.snap`.

Generated by [AVA](https://avajs.dev).

## General: Component.js

> Snapshot 1
[
{
coverageInfo: [],
errorCount: 0,
fatalErrorCount: 0,
filePath: 'Component.js',
messages: [],
warningCount: 0,
},
]

## General: manifest.json

> Snapshot 1
[
{
coverageInfo: [],
errorCount: 1,
fatalErrorCount: 1,
filePath: 'manifest.json',
messages: [
{
fatal: true,
message: 'Unexpected end of JSON input',
ruleId: 'ui5-linter-parsing-error',
severity: 2,
},
],
warningCount: 0,
},
]
Binary file not shown.

0 comments on commit 474e419

Please sign in to comment.