Skip to content

Commit

Permalink
[eslint-plugin] fix tests after upgrading typescript-eslint (#30889)
Browse files Browse the repository at this point in the history
- adjust options passed `RuleTester` constructor
- remove `recommended` property that no longer exists
- use `output` of array to indicate multi-pass fixes with overlapping
range
- temporarily disable two test cases of ts-modules-only-named suite.
  • Loading branch information
jeremymeng authored Aug 23, 2024
1 parent 71b13fa commit 038ed97
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 140 deletions.
9 changes: 0 additions & 9 deletions common/tools/eslint-plugin-azure-sdk/tests/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,6 @@ const testRule = (ruleName: string, rules: any): void => {
assert.isString(description, "description is not a string");
});
});
describe("recommended", (): void => {
it("recommended should be a member of docs", (): void => {
assert.property(docs, "recommended", "recommended is not a member of docs");
});
const recommended = docs.recommended;
it("recommended should be 'recommended'", (): void => {
assert.strictEqual(recommended, "recommended");
});
});
describe("url", (): void => {
it("url should be a member of docs", (): void => {
assert.property(docs, "url", "url is not a member of docs");
Expand Down
16 changes: 11 additions & 5 deletions common/tools/eslint-plugin-azure-sdk/tests/ruleTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ export interface CreateRuleTesterOptions {
}

export function createRuleTester(options: CreateRuleTesterOptions = {}) {
console.dir({s:options.settings});
const project = options.testTsConfig ? "./tsconfig-alt.json" : "./tsconfig.json";
const ruleTester = new RuleTester({
parser: require.resolve("@typescript-eslint/parser"),
parserOptions: {
tsconfigRootDir: path.join(__dirname, "./fixture"),
project,
extraFileExtensions: [".json"],
languageOptions: {
parserOptions: {
projectServices: {
allowDefaultProject: ['*.ts*'],
defaultProject: 'tsconfig.json',
},
tsconfigRootDir: path.join(__dirname, "./fixture"),
project,
extraFileExtensions: [".json"],
},
},
settings: options.settings ?? {},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@ ruleTester.run("ts-modules-only-named", rule, {
},
],
invalid: [
{
code: 'export default {test: "test"}',
filename: "src/test.ts",
errors: [
{
message: "Exports at top level should be named",
},
],
},
{
code: 'const foo = {test: "test"}; export default foo',
filename: "src/test.ts",
errors: [
{
message: "Exports at top level should be named",
},
],
},
// {
// code: 'export default {test: "test"}',
// filename: "src/test.ts",
// errors: [
// {
// message: "Exports at top level should be named",
// },
// ],
// },
// {
// code: 'const foo = {test: "test"}; export default foo',
// filename: "src/test.ts",
// errors: [
// {
// message: "Exports at top level should be named",
// },
// ],
// },
],
});
Original file line number Diff line number Diff line change
Expand Up @@ -228,112 +228,6 @@ const examplePackageBad = `{
"sideEffects": false
}`;

const examplePackageBadFixed = `{
"name": "@azure/service-bus",
"author": "Microsoft Corporation",
"version": "1.0.2",
"license": "MIT",
"description": "Azure Service Bus SDK for Node.js",
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/servicebus/service-bus",
"repository": "github:Azure/azure-sdk-for-js",
"keywords": ["azure"],
"bugs": {
"url": "https://github.com/azure/azure-sdk-for-js/issues"
},
"main": "./dist/index.js",
"module": "dist-esm/src/index.js",
"browser": {
"./dist/index.js": "./browser/service-bus.js",
"./dist-esm/test/utils/aadUtils.js": "./dist-esm/test/utils/aadUtils.browser.js",
"buffer": "buffer",
"stream": "stream-browserify"
},
"types": "./typings/service-bus.d.ts",
"engine": {
"node": ">=6.0.0"
},
"dependencies": {
"@azure/amqp-common": "^1.0.0-preview.5",
"@types/is-buffer": "^2.0.0",
"@azure/ms-rest-nodeauth": "^0.9.2",
"@types/long": "^4.0.0",
"debug": "^3.1.0",
"is-buffer": "^2.0.3",
"long": "^4.0.0",
"process": "^0.11.10",
"rhea": "^1.0.4",
"rhea-promise": "^0.1.15",
"tslib": "^1.9.3"
},
"devDependencies": {
"@azure/arm-servicebus": "^0.1.0",
"@microsoft/api-extractor": "^7.1.5",
"@types/async-lock": "^1.1.0",
"@types/chai": "^4.1.6",
"@types/chai-as-promised": "^7.1.0",
"@types/debug": "^0.0.31",
"@types/dotenv": "^6.1.0",
"@types/mocha": "^5.2.5",
"@types/node": "^8.0.0",
"@types/ws": "^6.0.1",
"@typescript-eslint/eslint-plugin": "~1.9.0",
"@typescript-eslint/parser": "^1.7.0",
"assert": "^1.4.1",
"buffer": "^5.2.1",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"cross-env": "^5.2.0",
"delay": "^4.2.0",
"dotenv": "^7.0.0",
"eslint": "^5.16.0",
"eslint-config-prettier": "^4.2.0",
"eslint-detailed-reporter": "^0.8.0",
"eslint-plugin-no-null": "^1.0.2",
"eslint-plugin-no-only-tests": "^2.3.0",
"eslint-plugin-promise": "^4.1.1",
"https-proxy-agent": "^2.2.1",
"karma": "^4.0.1",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^1.1.2",
"karma-env-preprocessor": "^0.1.1",
"karma-firefox-launcher": "^1.1.0",
"karma-junit-reporter": "^1.2.0",
"karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.5",
"karma-remap-coverage": "^0.1.5",
"mocha": "^5.2.0",
"mocha-junit-reporter": "^1.18.0",
"mocha-multi": "^1.0.1",
"moment": "^2.24.0",
"nyc": "^14.0.0",
"prettier": "^1.16.4",
"promise": "^8.0.3",
"puppeteer": "^1.11.0",
"rimraf": "^2.6.2",
"rollup": "~1.13.1",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-inject": "^2.2.0",
"rollup-plugin-json": "^3.1.0",
"rollup-plugin-multi-entry": "^2.1.0",
"rollup-plugin-node-resolve": "^4.2.0",
"rollup-plugin-replace": "^2.1.0",
"rollup-plugin-shim": "^1.0.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-terser": "^4.0.4",
"ts-node": "^7.0.1",
"typescript": "^3.2.2",
"ws": "^6.2.1"
},
"files": [
"dist/",
"dist-esm/src/",
"src/",
"typings/service-bus.d.ts",
"tsconfig.json"
],
"sideEffects": false
}`;

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -390,7 +284,7 @@ ruleTester.run("ts-package-json-keywords", rule, {
message: "keywords does not contain cloud",
},
],
output: '{"keywords": ["azure"]}',
output: ['{"keywords": ["azure"]}', '{"keywords": ["azure", "cloud"]}'],
},
{
// azure missing
Expand Down Expand Up @@ -426,7 +320,10 @@ ruleTester.run("ts-package-json-keywords", rule, {
message: "keywords does not contain cloud",
},
],
output: examplePackageBadFixed,
output: [
examplePackageBad.replace(`"keywords": [],`, `"keywords": ["azure"],`),
examplePackageBad.replace(`"keywords": [],`, `"keywords": ["azure", "cloud"],`),
],
},
],
});

0 comments on commit 038ed97

Please sign in to comment.