strict.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. var test = require("tap").test
  2. var normalize = require("../")
  3. test("strict", function(t) {
  4. var threw
  5. try {
  6. threw = false
  7. normalize({name: "X"}, true)
  8. } catch (er) {
  9. threw = true
  10. t.equal(er.message, 'Invalid name: "X"')
  11. } finally {
  12. t.equal(threw, true)
  13. }
  14. try {
  15. threw = false
  16. normalize({name:" x "}, true)
  17. } catch (er) {
  18. threw = true
  19. t.equal(er.message, 'Invalid name: " x "')
  20. } finally {
  21. t.equal(threw, true)
  22. }
  23. try {
  24. threw = false
  25. normalize({name:"x",version:"01.02.03"}, true)
  26. } catch (er) {
  27. threw = true
  28. t.equal(er.message, 'Invalid version: "01.02.03"')
  29. } finally {
  30. t.equal(threw, true)
  31. }
  32. // these should not throw
  33. var slob = {name:" X ",version:"01.02.03",dependencies:{
  34. y:">01.02.03",
  35. z:"! 99 $$ASFJ(Aawenf90awenf as;naw.3j3qnraw || an elephant"
  36. }}
  37. normalize(slob, false)
  38. t.same(slob,
  39. { name: 'X',
  40. version: '1.2.3',
  41. dependencies:
  42. { y: '>01.02.03',
  43. z: '! 99 $$ASFJ(Aawenf90awenf as;naw.3j3qnraw || an elephant' },
  44. readme: 'ERROR: No README data found!',
  45. _id: 'X@1.2.3' })
  46. t.end()
  47. })