npm-packages-exists.test.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. const npmPackagesExists = require("./npm-packages-exists");
  2. jest.mock("./npm-exists");
  3. jest.mock("./resolve-packages");
  4. const mockResolvePackages = require("./resolve-packages").resolvePackages;
  5. describe("npmPackagesExists", () => {
  6. test("resolves packages when they are available on the local filesystem", () => {
  7. npmPackagesExists(["./testpkg"]);
  8. expect(
  9. mockResolvePackages.mock.calls[
  10. mockResolvePackages.mock.calls.length - 1
  11. ][0]
  12. ).toEqual(["./testpkg"]);
  13. });
  14. test("throws a TypeError when an npm package name doesn't include the prefix", () => {
  15. expect(() => npmPackagesExists(["my-webpack-addon"])).toThrowError(
  16. TypeError
  17. );
  18. });
  19. test("resolves packages when they are available on npm", done => {
  20. require("./npm-exists").mockImplementation(() => Promise.resolve(true));
  21. npmPackagesExists(["webpack-addons-foobar"]);
  22. setTimeout(() => {
  23. expect(
  24. mockResolvePackages.mock.calls[
  25. mockResolvePackages.mock.calls.length - 1
  26. ][0]
  27. ).toEqual(["webpack-addons-foobar"]);
  28. done();
  29. }, 10);
  30. });
  31. });