Skip to content
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

Add Jest tests for api #87

Closed
wants to merge 5 commits into from
Closed

Conversation

robmosca
Copy link
Contributor

@robmosca robmosca commented Jun 26, 2023

While working on the import-map-overrides project, I realized the code is not covered by unit tests. I would like to contribute Jest tests, to make sure that further modifications to the package do not introduce regressions.

Current coverage:

Screenshot 2023-07-16 at 12 44 37

@robmosca robmosca marked this pull request as draft June 26, 2023 20:35
jest.setup.js Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
nextPromise,
]).then(([originalMap, newMap]) =>
imo.mergeImportMap(originalMap, newMap)
return Promise.all([promise, nextPromise]).then(
Copy link
Member

Choose a reason for hiding this comment

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

Are these prettier changes because of your installation of VS Code? Since the version of prettier is pinned, I don't know why these changes are happening. Please add a check-format script to the package.json that runs prettier --check . What I want to avoid is a situation where a global installation of prettier that's specific to one contributor's computer is changing the format of the code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

.github/workflows/build-and-test.yml Show resolved Hide resolved
@robmosca
Copy link
Contributor Author

robmosca commented Jul 1, 2023

Addressed the initial comments. I will continue working on adding tests.

@@ -0,0 +1 @@
require("jest-fetch-mock").enableMocks();
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 is needed in order to safely mock fetch (for testing external maps)

Comment on lines +212 to +216
parsedContent = JSON.parse(scriptEl.textContent);
} catch (e) {
parsedContent = createEmptyImportMap();
}
nextPromise = Promise.resolve(parsedContent);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

While testing I realized this function bombs when the import map is empty or is malformed. To prevent a malformed import map from breaking the plugin, I modified this code to instead return an empty map.

@robmosca robmosca changed the title WIP: [Proposal] Add Jest tests [Proposal] Add Jest tests - Part 1 Jul 9, 2023
@robmosca robmosca marked this pull request as ready for review July 9, 2023 14:41
@robmosca robmosca requested a review from joeldenning July 9, 2023 14:41
@robmosca robmosca changed the title [Proposal] Add Jest tests - Part 1 [Proposal] Add Jest tests for api Jul 16, 2023
(externalOverrideMapPromises[importMapUrl] =
fetchExternalMap(importMapUrl));
return promise.then(
() => !includes(imo.invalidExternalMaps, importMapUrl)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe this was a bug. I found it out when writing a test for this function. The map is valid if it IS NOT included in the invalidExternalMaps array.

@robmosca
Copy link
Contributor Author

These changes are included in #89 and #94.
If you prefer reviewing the most comprehensive PR (#94) we can close this one.

@robmosca robmosca changed the title [Proposal] Add Jest tests for api Add Jest tests for api Sep 11, 2023
@robmosca
Copy link
Contributor Author

Closed in favour of #96

@robmosca robmosca closed this Sep 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants