script.test.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import test from 'tape';
  2. import { compareVersion, parseMeta } from '#/background/utils/script';
  3. test('compareVersion', t => {
  4. t.equal(compareVersion('1.2.3', '1.2.3'), 0);
  5. t.equal(compareVersion('1.2.3', '1.2.0'), 1);
  6. t.equal(compareVersion('1.2.3', '1.2.4'), -1);
  7. t.equal(compareVersion('1.2.0', '1.2'), 0);
  8. t.equal(compareVersion('1.2.1', '1.2'), 1);
  9. t.equal(compareVersion('1.1.9', '1.2'), -1);
  10. t.equal(compareVersion('1.10', '1.9'), 1);
  11. t.end();
  12. });
  13. const baseMeta = {
  14. include: [],
  15. exclude: [],
  16. match: [],
  17. excludeMatch: [],
  18. require: [],
  19. grant: [],
  20. resources: {},
  21. noframes: false,
  22. };
  23. test('parseMeta', t => {
  24. t.deepEqual(parseMeta(`\
  25. // ==UserScript==
  26. // @name New Script
  27. // @namespace Violentmonkey Scripts
  28. // @description This is a script
  29. // @version 1.0
  30. // @match *://*/*
  31. // @grant none
  32. // ==/UserScript==
  33. `), Object.assign({}, baseMeta, {
  34. name: 'New Script',
  35. namespace: 'Violentmonkey Scripts',
  36. description: 'This is a script',
  37. version: '1.0',
  38. match: ['*://*/*'],
  39. grant: ['none'],
  40. }));
  41. t.deepEqual(parseMeta(`\
  42. // ==UserScript==
  43. // @name New Script
  44. // @namespace Violentmonkey Scripts
  45. // @match *://*/*
  46. // @noframes
  47. // ==/UserScript==
  48. `), Object.assign({}, baseMeta, {
  49. name: 'New Script',
  50. namespace: 'Violentmonkey Scripts',
  51. match: ['*://*/*'],
  52. noframes: true,
  53. }));
  54. t.end();
  55. });