test.path.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. "use strict";
  2. /* ------------------------------------------------------------------------ */
  3. require ('chai').should ()
  4. /* ------------------------------------------------------------------------ */
  5. describe ('path', () => {
  6. const path = require ('../impl/path')
  7. it ('resolves', () => {
  8. path.resolve ('./foo/bar/../qux').should.equal (process.cwd () + '/foo/qux')
  9. })
  10. it ('normalizes', () => {
  11. path.normalize ('./foo/./bar/.././.././qux.map./').should.equal ('qux.map./')
  12. path.normalize ('/a/b').should.equal ('/a/b')
  13. path.normalize ('http://foo/bar').should.equal ('http://foo/bar')
  14. })
  15. it ('computes relative location', () => {
  16. path.relativeToFile ('/foo/bar.js', './qux.map')
  17. .should.equal ('/foo/qux.map')
  18. path.relativeToFile ('/foo/bar/baz.js', './../.././qux.map')
  19. .should.equal ('/qux.map')
  20. path.relativeToFile ('/foo/bar', 'webpack:something')
  21. .should.equal ('webpack:something')
  22. path.relativeToFile ('/foo/bar', 'web/pack:something')
  23. .should.equal ('/foo/web/pack:something')
  24. })
  25. it ('works with data URIs', () => {
  26. path.relativeToFile ('/foo/bar.js', 'data:application/json;charset=utf-8;base64,eyJ2ZXJza==')
  27. .should.equal ( 'data:application/json;charset=utf-8;base64,eyJ2ZXJza==')
  28. path.relativeToFile ('data:application/json;charset=utf-8;base64,eyJ2ZXJza==', 'foo.js')
  29. .should.equal ( 'foo.js')
  30. })
  31. it ('implements isURL', () => {
  32. path.isURL ('foo.js').should.equal (false)
  33. path.isURL ('/foo/bar.js').should.equal (false)
  34. path.isURL ('https://google.com').should.equal (true)
  35. })
  36. })