Skip to content

feat(testing): add tests for src/browser/pages/vscode to hit 100% coverage #4055

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

Merged
merged 1 commit into from
Aug 30, 2021

Conversation

jsjoeio
Copy link
Contributor

@jsjoeio jsjoeio commented Aug 27, 2021

This PR adds full test coverage for src/browser/pages/vscode.ts

image

Fixes #4052

@codecov
Copy link

codecov bot commented Aug 27, 2021

Codecov Report

Merging #4055 (c06055c) into main (c0d62da) will not change coverage.
The diff coverage is n/a.

❗ Current head c06055c differs from pull request most recent head 79b4e47. Consider uploading reports for the commit 79b4e47 to get more accurate results
Impacted file tree graph

@@           Coverage Diff           @@
##             main    #4055   +/-   ##
=======================================
  Coverage   63.51%   63.51%           
=======================================
  Files          36       36           
  Lines        1872     1872           
  Branches      379      379           
=======================================
  Hits         1189     1189           
  Misses        580      580           
  Partials      103      103           
Impacted Files Coverage Δ
src/browser/pages/vscode.ts 83.82% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c0d62da...79b4e47. Read the comment docs.

@github-actions
Copy link

github-actions bot commented Aug 27, 2021

✨ Coder.com for PR #4055 deployed! It will be updated on every commit.

@jsjoeio jsjoeio changed the title feat: add full test coverage browser/vscode feat: add full test coverage src/browser/pages/vscode Aug 30, 2021
@jsjoeio jsjoeio force-pushed the jsjoeio-tests-vscode branch from 889d476 to 011e8bf Compare August 30, 2021 22:04
@jsjoeio jsjoeio added the testing Anything related to testing label Aug 30, 2021
@@ -24,13 +24,13 @@ type NlsConfiguration = {
* Helper function to create the path to the bundle
* for getNlsConfiguration.
*/
export function createBundlePath(_resolvedLanguagePackCoreLocation: string, bundle: string) {
export function createBundlePath(_resolvedLanguagePackCoreLocation: string | undefined, bundle: string) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 updated the signature to match the actual value passed in _resolvedLanguagePackCoreLocation's type is string | undefined

// NOTE@jsjoeio - this comment was here before me
// Refers to operating systems that use a different path separator.
// Probably just Windows but we're not sure if "/" breaks on Windows
// so we'll leave it alone for now.
// FIXME: Only works if path separators are /.
return _resolvedLanguagePackCoreLocation + "/" + bundle.replace(/\//g, "!") + ".nls.json"
return (_resolvedLanguagePackCoreLocation || "") + "/" + bundle.replace(/\//g, "!") + ".nls.json"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Originally, we were using _resolvedLanguagePackCoreLocation or passing in an empty string. We moved the logic from outside the function into the function since the caller shouldn't have to change the argument functions if the value is undefined. Instead, the function should handle this.

@@ -72,20 +72,22 @@ export function getNlsConfiguration(_document: Document, base: string) {

type LoadBundleCallback = (_: undefined, result?: string) => void

nlsConfig.loadBundle = (bundle: string, _language: string, cb: LoadBundleCallback): void => {
nlsConfig.loadBundle = async (bundle: string, _language: string, cb: LoadBundleCallback): Promise<void> => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Originally, this function was not using async/await. I then realized we had the fetch call and the .then chain. I refactored this so it was easy to test. Now it's clear to the caller this function has asynchronous logic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice 👍

if (result) {
return cb(undefined, result)
}
// FIXME: Only works if path separators are /.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Removed this comment because it's related to createBundlePath and explained in a comment near that function with more details.

@@ -87,6 +119,13 @@ describe("vscode", () => {
const actual = createBundlePath(_resolvedLangaugePackCoreLocation, bundle)
expect(actual).toBe(expected)
})
it("should return the correct path (even if _resolvedLangaugePackCoreLocation is undefined)", () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ This check was added after modifying the createBundlePath function signature.

@jsjoeio jsjoeio force-pushed the jsjoeio-tests-vscode branch from 011e8bf to f4b0ab3 Compare August 30, 2021 22:10
@jsjoeio jsjoeio force-pushed the jsjoeio-tests-vscode branch from f4b0ab3 to 79b4e47 Compare August 30, 2021 22:12
@jsjoeio jsjoeio marked this pull request as ready for review August 30, 2021 22:12
@jsjoeio jsjoeio requested a review from a team as a code owner August 30, 2021 22:12
@jsjoeio jsjoeio changed the title feat: add full test coverage src/browser/pages/vscode feat(testing): hit 100% coverage for src/browser/pages/vscode Aug 30, 2021
@jsjoeio jsjoeio changed the title feat(testing): hit 100% coverage for src/browser/pages/vscode feat(testing): add tests for src/browser/pages/vscode to hit 100% coverage Aug 30, 2021
@jsjoeio jsjoeio merged commit ed1ded5 into main Aug 30, 2021
@jsjoeio jsjoeio deleted the jsjoeio-tests-vscode branch August 30, 2021 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Anything related to testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add more tests for vscode.ts
2 participants