-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch from esmock to node.js mock tracker #446
Open
albertshay888
wants to merge
10
commits into
NodeSecure:master
Choose a base branch
from
albertshay888:Switch-from-esmock-to-Node.js-MockTracker
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a361420
converted all tests using esmock to Node.js MockTracker
albertshay888 d12af0a
conversion to MockTracker, including tests in httpSever.test.js
albertshay888 e7bc79f
removed all test comments that were migrated and removed all the doub…
albertshay888 4a7f915
removed mock.module and replaced it with mock.method instead
albertshay888 464bfa2
removed all dynamic imports in scorecard.test.js and httpServer.test.…
albertshay888 b572ab9
uninstalled esmock, changed test script in package.json, removed esmo…
albertshay888 3f02591
removed unassigned value readFileSyncMock in the last test of command…
albertshay888 ef46bdf
Merge branch 'master' into Switch-from-esmock-to-Node.js-MockTracker
albertshay888 f5a9ec3
replacing mock.restoreAll with mock.restore in both files scorecard.t…
albertshay888 54e6409
reinstalled eslint-plugin-jsdoc: ^50.6.2, and added line 105
albertshay888 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,17 +1,18 @@ | ||||||||
// Import Node.js Dependencies | ||||||||
import fs from "node:fs"; | ||||||||
import { fileURLToPath } from "node:url"; | ||||||||
import path from "node:path"; | ||||||||
import { test } from "node:test"; | ||||||||
import { test, mock } from "node:test"; | ||||||||
import assert from "node:assert"; | ||||||||
|
||||||||
// Import Third-party Dependencies | ||||||||
import esmock from "esmock"; | ||||||||
import { API_URL } from "@nodesecure/ossf-scorecard-sdk"; | ||||||||
import { Ok } from "@openally/result"; | ||||||||
|
||||||||
// Import Internal Dependencies | ||||||||
import { runProcess } from "../helpers/cliCommandRunner.js"; | ||||||||
import { arrayFromAsync, getExpectedScorecardLines } from "../helpers/utils.js"; | ||||||||
import * as testingModule from "../../src/commands/scorecard.js"; | ||||||||
|
||||||||
// CONSTANTS | ||||||||
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||||||||
|
@@ -97,25 +98,22 @@ test("should not display scorecard for unknown repository", async() => { | |||||||
assert.deepEqual(givenLines, expectedLines, `lines should be ${expectedLines}`); | ||||||||
}); | ||||||||
|
||||||||
test("should retrieve repository whithin git config", async() => { | ||||||||
const testingModule = await esmock("../../src/commands/scorecard.js", { | ||||||||
fs: { | ||||||||
readFileSync: () => [ | ||||||||
"[remote \"origin\"]", | ||||||||
"\turl = [email protected]:myawesome/repository.git" | ||||||||
].join("\n") | ||||||||
} | ||||||||
}); | ||||||||
test("should retrieve repository within git config", async() => { | ||||||||
const readFileSyncMock = mock.method(fs, "readFileSync", () => [ | ||||||||
"[remote \"origin\"]", | ||||||||
"\turl = [email protected]:myawesome/repository.git" | ||||||||
].join("\n") | ||||||||
); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed in latest commit |
||||||||
|
||||||||
assert.deepEqual(testingModule.getCurrentRepository(), Ok(["myawesome/repository", "github"])); | ||||||||
assert.deepEqual( | ||||||||
testingModule.getCurrentRepository(), | ||||||||
Ok(["myawesome/repository", "github"]) | ||||||||
); | ||||||||
|
||||||||
readFileSyncMock.restore(); | ||||||||
}); | ||||||||
|
||||||||
test("should not find origin remote", async() => { | ||||||||
const testingModule = await esmock("../../src/commands/scorecard.js", { | ||||||||
fs: { | ||||||||
readFileSync: () => "just one line" | ||||||||
} | ||||||||
}); | ||||||||
const result = testingModule.getCurrentRepository(); | ||||||||
|
||||||||
assert.equal(result.err, true); | ||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This dep is needed for the eslint config, you removed it when resolving conflicts i guess (just reinstall it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reinstalled "eslint-plugin-jsdoc": "^50.6.2", in latest commit