storage.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. /**
  4. * In this file we define a factory which can be used to create the commands for either
  5. * sessionStorage or localStorage
  6. */
  7. const selenium_mock_1 = require("selenium-mock");
  8. function storageFactory(type) {
  9. let storageCmds = {};
  10. function cmdFactory(method, relPath, fun) {
  11. return new selenium_mock_1.Command(method, type + '_storage' + relPath, (session, params) => {
  12. return fun(session[type + '_storage'], params['key'], params['value']);
  13. });
  14. }
  15. storageCmds.getKeys = cmdFactory('GET', '', (store) => {
  16. return Object.keys(store);
  17. });
  18. storageCmds.getValue = cmdFactory('GET', '/key/:key', (store, key) => {
  19. return store[key];
  20. });
  21. storageCmds.setValue = cmdFactory('POST', '', (store, key, value) => {
  22. store[key] = value;
  23. });
  24. storageCmds.deleteEntry = cmdFactory('DELETE', '/key/:key', (store, key) => {
  25. delete store[key];
  26. });
  27. storageCmds.deleteAll = cmdFactory('DELETE', '', (store) => {
  28. for (var key in store) {
  29. delete store[key];
  30. }
  31. });
  32. storageCmds.getSize = cmdFactory('GET', '/size', (store) => {
  33. return Object.keys(store).length;
  34. });
  35. return storageCmds;
  36. }
  37. exports.storageFactory = storageFactory;
  38. ;
  39. //# sourceMappingURL=storage.js.map