From a621be6f4c12c8ce7d6f68b9376c628c3716c7e5 Mon Sep 17 00:00:00 2001 From: Kevin Barabash Date: Fri, 14 Apr 2023 15:01:26 -0400 Subject: [PATCH] Fix sync-tag eslint rule (#647) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary: The tests didn't catch this because they were mocking it. The reason why we need to bother with these util wrappers around functions is that RuleTester doesn't provide a way to mock things so I ended up having to mock things in a hacky way. I added an assert() call to the place where we do the mocking, but I think we need rethink how we write eslint tests. We should probably create our own jest-based test harness, but that'll take some doing so I'm going to punt on it for now. Issue: None ## Test plan: - yarn --cwd packages/eslint-plugin-khan test Author: kevinbarabash Reviewers: jeresig, kevinbarabash Required Reviewers: Approved By: jeresig Checks: ✅ codecov/project, ✅ Test (macos-latest, 16.x), ✅ CodeQL, ✅ Lint, typecheck, and coverage check (ubuntu-latest, 16.x), ⏭ dependabot, ✅ gerald, ✅ Prime node_modules cache for primary configuration (ubuntu-latest, 16.x), ✅ Analyze (javascript) Pull Request URL: https://github.com/Khan/wonder-stuff/pull/647 --- .changeset/eight-bats-beg.md | 5 +++++ packages/eslint-plugin-khan/lib/util.js | 3 ++- packages/eslint-plugin-khan/test/sync-tag_test.js | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .changeset/eight-bats-beg.md diff --git a/.changeset/eight-bats-beg.md b/.changeset/eight-bats-beg.md new file mode 100644 index 00000000..a35ea24a --- /dev/null +++ b/.changeset/eight-bats-beg.md @@ -0,0 +1,5 @@ +--- +"@khanacademy/eslint-plugin": patch +--- + +Ensure sync-tag rule has access to 'execSync' diff --git a/packages/eslint-plugin-khan/lib/util.js b/packages/eslint-plugin-khan/lib/util.js index 97462d59..55caefb5 100644 --- a/packages/eslint-plugin-khan/lib/util.js +++ b/packages/eslint-plugin-khan/lib/util.js @@ -1,6 +1,7 @@ -const {execFile} = require("child_process"); +const {execFile, execSync} = require("child_process"); // This is done so that we can override execSync in the tests module.exports = { execFile, + execSync, }; diff --git a/packages/eslint-plugin-khan/test/sync-tag_test.js b/packages/eslint-plugin-khan/test/sync-tag_test.js index 6125064c..a5160e00 100644 --- a/packages/eslint-plugin-khan/test/sync-tag_test.js +++ b/packages/eslint-plugin-khan/test/sync-tag_test.js @@ -1,3 +1,5 @@ +const assert = require("assert"); + const {rules} = require("../lib/index.js"); const util = require("../lib/util.js"); const RuleTester = require("eslint").RuleTester; @@ -9,6 +11,7 @@ const parserOptions = { const ruleTester = new RuleTester(parserOptions); const rule = rules["sync-tag"]; +assert(util.execSync); util.execSync = (command) => { console.log("execSync mock --------"); if (command.includes("filea")) {