Skip to content

Commit 5ec9f65

Browse files
authored
refactor(eslint-plugin-fluid): Simplify test infra (#25916)
Renames test modules, test-cases directory, and removes unneeded folder hierarchy.
1 parent e3f3f20 commit 5ec9f65

29 files changed

+27
-27
lines changed

common/build/eslint-plugin-fluid/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"scripts": {
1515
"build": "npm run build:readme && npm run build:test:examples",
1616
"build:readme": "markdown-magic --files \"**/*.md\"",
17-
"build:test:examples": "tsc --project ./src/test/example/tsconfig.json",
17+
"build:test:examples": "tsc --project ./src/test/test-cases/tsconfig.json",
1818
"clean": "rimraf --glob nyc",
1919
"format": "npm run prettier:fix",
2020
"prettier": "prettier --check . --cache --ignore-path ../../../.prettierignore",

common/build/eslint-plugin-fluid/src/test/eslintConfigHelper.cjs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function createESLintConfig(config) {
3030

3131
const parser = "@typescript-eslint/parser";
3232
const parserOptions = customParserOptions || {
33-
project: path.join(__dirname, "example/tsconfig.json"),
33+
project: path.join(__dirname, "test-cases/tsconfig.json"),
3434
};
3535
const pluginName = "@fluid-internal/fluid";
3636

@@ -82,9 +82,10 @@ function createESLintConfig(config) {
8282
* @returns {ESLint} Configured ESLint instance
8383
*/
8484
function createESLintInstance(rulesOrConfig) {
85-
const config = typeof rulesOrConfig === 'object' && rulesOrConfig.rules
86-
? rulesOrConfig
87-
: { rules: rulesOrConfig };
85+
const config =
86+
typeof rulesOrConfig === "object" && rulesOrConfig.rules
87+
? rulesOrConfig
88+
: { rules: rulesOrConfig };
8889

8990
const eslintOptions = createESLintConfig({
9091
rules: config.rules,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
const assert = require("assert");
77
const path = require("path");
8-
const { createESLintConfig, eslintVersion, ESLint } = require("../eslintConfigHelper.cjs");
8+
const { createESLintConfig, eslintVersion, ESLint } = require("./eslintConfigHelper.cjs");
99

1010
describe(`Do not allow file path links in JSDoc/TSDoc comments (eslint ${eslintVersion})`, function () {
1111
async function lintFile(file) {
@@ -16,7 +16,7 @@ describe(`Do not allow file path links in JSDoc/TSDoc comments (eslint ${eslintV
1616
});
1717

1818
const eslint = new ESLint(eslintOptions);
19-
const fileToLint = path.join(__dirname, "../example/no-file-path-links-in-jsdoc", file);
19+
const fileToLint = path.join(__dirname, "./test-cases/no-file-path-links-in-jsdoc", file);
2020
const results = await eslint.lintFiles([fileToLint]);
2121
assert.equal(results.length, 1, "Expected a single result for linting a single file.");
2222
return results[0];
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
const assert = require("assert");
77
const path = require("path");
8-
const { createESLintConfig, eslintVersion, ESLint } = require("../eslintConfigHelper.cjs");
8+
const { createESLintConfig, eslintVersion, ESLint } = require("./eslintConfigHelper.cjs");
99

1010
describe(`Do not allow \`-\` following JSDoc/TSDoc tags (eslint ${eslintVersion})`, function () {
1111
/**
@@ -21,7 +21,7 @@ describe(`Do not allow \`-\` following JSDoc/TSDoc tags (eslint ${eslintVersion}
2121
});
2222

2323
const eslint = new ESLint(eslintOptions);
24-
const fileToLint = path.join(__dirname, "../example/no-hyphen-after-jsdoc-tag", file);
24+
const fileToLint = path.join(__dirname, "./test-cases/no-hyphen-after-jsdoc-tag", file);
2525
const results = await eslint.lintFiles([fileToLint]);
2626
assert.equal(results.length, 1, "Expected a single result for linting a single file.");
2727
return results[0];
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
const assert = require("assert");
77
const path = require("path");
8-
const { createESLintConfig, eslintVersion, ESLint } = require("../eslintConfigHelper.cjs");
8+
const { createESLintConfig, eslintVersion, ESLint } = require("./eslintConfigHelper.cjs");
99

1010
describe(`Do not allow Markdown links in JSDoc/TSDoc comments (eslint ${eslintVersion})`, function () {
1111
async function lintFile(file) {
@@ -16,7 +16,7 @@ describe(`Do not allow Markdown links in JSDoc/TSDoc comments (eslint ${eslintVe
1616
});
1717

1818
const eslint = new ESLint(eslintOptions);
19-
const fileToLint = path.join(__dirname, "../example/no-markdown-links-in-jsdoc", file);
19+
const fileToLint = path.join(__dirname, "./test-cases/no-markdown-links-in-jsdoc", file);
2020
const results = await eslint.lintFiles([fileToLint]);
2121
assert.equal(results.length, 1, "Expected a single result for linting a single file.");
2222
return results[0];
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
const assert = require("assert");
77
const path = require("path");
8-
const { createESLintInstance, eslintVersion } = require("../eslintConfigHelper.cjs");
8+
const { createESLintInstance, eslintVersion } = require("./eslintConfigHelper.cjs");
99

1010
describe(`Do not allow release tags on members (eslint ${eslintVersion})`, function () {
1111
const eslintRules = {
@@ -16,7 +16,7 @@ describe(`Do not allow release tags on members (eslint ${eslintVersion})`, funct
1616
const eslint = createESLintInstance(eslintRules);
1717

1818
const filesToLint = ["mockClassDeclaration.ts"].map((file) =>
19-
path.join(__dirname, "../example/no-member-release-tags", file),
19+
path.join(__dirname, "./test-cases/no-member-release-tags", file),
2020
);
2121
const results = await eslint.lintFiles(filesToLint);
2222

@@ -61,7 +61,7 @@ describe(`Do not allow release tags on members (eslint ${eslintVersion})`, funct
6161
const eslint = createESLintInstance(eslintRules);
6262

6363
const filesToLint = ["mockClassExpression.ts"].map((file) =>
64-
path.join(__dirname, "../example/no-member-release-tags", file),
64+
path.join(__dirname, "./test-cases/no-member-release-tags", file),
6565
);
6666
const results = await eslint.lintFiles(filesToLint);
6767
const result = results[0];
@@ -112,7 +112,7 @@ describe(`Do not allow release tags on members (eslint ${eslintVersion})`, funct
112112
const eslint = createESLintInstance(eslintRules);
113113

114114
const filesToLint = ["mockAbstractClass.ts"].map((file) =>
115-
path.join(__dirname, "../example/no-member-release-tags", file),
115+
path.join(__dirname, "./test-cases/no-member-release-tags", file),
116116
);
117117
const results = await eslint.lintFiles(filesToLint);
118118
const result = results[0];
@@ -131,7 +131,7 @@ describe(`Do not allow release tags on members (eslint ${eslintVersion})`, funct
131131
const eslint = createESLintInstance(eslintRules);
132132

133133
const filesToLint = ["mockInterface.ts"].map((file) =>
134-
path.join(__dirname, "../example/no-member-release-tags", file),
134+
path.join(__dirname, "./test-cases/no-member-release-tags", file),
135135
);
136136
const results = await eslint.lintFiles(filesToLint);
137137
const result = results[0];
@@ -170,7 +170,7 @@ describe(`Do not allow release tags on members (eslint ${eslintVersion})`, funct
170170
const eslint = createESLintInstance(eslintRules);
171171

172172
const filesToLint = ["mockType.ts"].map((file) =>
173-
path.join(__dirname, "../example/no-member-release-tags", file),
173+
path.join(__dirname, "./test-cases/no-member-release-tags", file),
174174
);
175175
const results = await eslint.lintFiles(filesToLint);
176176
const result = results[0];
@@ -206,7 +206,7 @@ describe(`Do not allow release tags on members (eslint ${eslintVersion})`, funct
206206
const eslint = createESLintInstance(eslintRules);
207207

208208
const filesToLint = ["mockFunction.ts"].map((file) =>
209-
path.join(__dirname, "../example/no-member-release-tags", file),
209+
path.join(__dirname, "./test-cases/no-member-release-tags", file),
210210
);
211211
const results = await eslint.lintFiles(filesToLint);
212212
const result = results[0];
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55

66
const assert = require("assert");
77
const path = require("path");
8-
const { createESLintInstance, eslintVersion } = require("../eslintConfigHelper.cjs");
8+
const { createESLintInstance, eslintVersion } = require("./eslintConfigHelper.cjs");
99

1010
describe(`ESLint Rule Tests (eslint ${eslintVersion})`, function () {
11-
1211
it("Should report an error for restricted tag imports", async function () {
1312
const eslint = createESLintInstance({
1413
rules: {
@@ -22,7 +21,7 @@ describe(`ESLint Rule Tests (eslint ${eslintVersion})`, function () {
2221
},
2322
});
2423
const filesToLint = ["fileWithImports.ts", "mockModule.ts"].map((file) =>
25-
path.join(__dirname, "../example/no-restricted-tags-imports", file),
24+
path.join(__dirname, "./test-cases/no-restricted-tags-imports", file),
2625
);
2726
const results = await eslint.lintFiles(filesToLint);
2827
const result = results[0];
@@ -52,11 +51,11 @@ describe(`ESLint Rule Tests (eslint ${eslintVersion})`, function () {
5251
],
5352
},
5453
parserOptions: {
55-
project: path.join(__dirname, "../example/tsconfig.json"),
54+
project: path.join(__dirname, "./test-cases/tsconfig.json"),
5655
},
5756
});
5857
const filesToLint = ["fileWithExceptionImports.ts", "exceptionFile.ts"].map((file) =>
59-
path.join(__dirname, "../example/no-restricted-tags-imports", file),
58+
path.join(__dirname, "./test-cases/no-restricted-tags-imports", file),
6059
);
6160
const results = await eslint.lintFiles(filesToLint);
6261
const result = results[0];
@@ -79,11 +78,11 @@ describe(`ESLint Rule Tests (eslint ${eslintVersion})`, function () {
7978
],
8079
},
8180
parserOptions: {
82-
project: path.join(__dirname, "../example/tsconfig.json"),
81+
project: path.join(__dirname, "./test-cases/tsconfig.json"),
8382
},
8483
});
8584
const filesToLint = ["fileWithImports.ts", "mockModule.ts"].map((file) =>
86-
path.join(__dirname, "../example/no-restricted-tags-imports", file),
85+
path.join(__dirname, "./test-cases/no-restricted-tags-imports", file),
8786
);
8887
const results = await eslint.lintFiles(filesToLint);
8988
const result = results[0];
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
const assert = require("assert");
77
const path = require("path");
8-
const { createESLintConfig, eslintVersion, ESLint } = require("../eslintConfigHelper.cjs");
8+
const { createESLintConfig, eslintVersion, ESLint } = require("./eslintConfigHelper.cjs");
99

1010
describe(`ESLint Rule Tests (eslint ${eslintVersion})`, function () {
1111
async function lintFile(file) {
@@ -16,7 +16,7 @@ describe(`ESLint Rule Tests (eslint ${eslintVersion})`, function () {
1616
});
1717

1818
const eslint = new ESLint(eslintOptions);
19-
const fileToLint = path.join(__dirname, "../example/no-unchecked-record-access", file);
19+
const fileToLint = path.join(__dirname, "./test-cases/no-unchecked-record-access", file);
2020
const results = await eslint.lintFiles([fileToLint]);
2121
return results[0];
2222
}

0 commit comments

Comments
 (0)