jsflags.spec.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* eslint-env mocha */
  2. var expect = require('chai').expect
  3. var sinon = require('sinon')
  4. var launcher = require('../index')
  5. describe('isJSFlags()', function () {
  6. var isJSFlags = launcher.test.isJSFlags
  7. it('should return true if flag begins with --js-flags=', function () {
  8. expect(isJSFlags('--js-flags=--expose-gc')).to.be.eql(true)
  9. expect(isJSFlags('--js-flags="--expose-gc"')).to.be.eql(true)
  10. expect(isJSFlags("--js-flags='--expose-gc'")).to.be.eql(true)
  11. })
  12. it('should return false if flag does not begin with --js-flags=', function () {
  13. expect(isJSFlags(' --js-flags=--expose-gc')).to.be.eql(false)
  14. expect(isJSFlags('--js-flags"--expose-gc"')).to.be.eql(false)
  15. expect(isJSFlags('--jsflags="--expose-gc"')).to.be.eql(false)
  16. })
  17. })
  18. describe('sanitizeJSFlags()', function () {
  19. var sanitizeJSFlags = launcher.test.sanitizeJSFlags
  20. it('should do nothing if flags are not contained in quotes', function () {
  21. expect(sanitizeJSFlags('--js-flags=--expose-gc')).to.be.eql('--js-flags=--expose-gc')
  22. })
  23. it('should symmetrically remove single or double quote if wraps all flags', function () {
  24. expect(sanitizeJSFlags("--js-flags='--expose-gc'")).to.be.eql('--js-flags=--expose-gc')
  25. expect(sanitizeJSFlags('--js-flags="--expose-gc"')).to.be.eql('--js-flags=--expose-gc')
  26. })
  27. it('should NOT remove anything if the flags are not contained within quote', function () {
  28. expect(sanitizeJSFlags('--js-flags=--expose-gc="true"')).to.be.eql('--js-flags=--expose-gc="true"')
  29. expect(sanitizeJSFlags("--js-flags=--expose-gc='true'")).to.be.eql("--js-flags=--expose-gc='true'")
  30. })
  31. })
  32. describe('canaryGetOptions', function () {
  33. var canaryGetOptions = launcher.test.canaryGetOptions
  34. it('should return a merged version of --js-flags', function () {
  35. var parent = sinon.stub().returns(['-incognito'])
  36. var context = {}
  37. var url = 'http://localhost:9876'
  38. var args = { flags: ['--js-flags="--expose-gc"'] }
  39. expect(canaryGetOptions.call(context, url, args, parent)).to.be.eql([
  40. '-incognito',
  41. '--js-flags=--expose-gc --nocrankshaft --noopt'
  42. ])
  43. })
  44. })
  45. describe('headlessGetOptions', function () {
  46. var headlessGetOptions = launcher.test.headlessGetOptions
  47. it('should return the headless flags', function () {
  48. var parent = sinon.stub().returns(['-incognito'])
  49. var context = {}
  50. var url = 'http://localhost:9876'
  51. var args = {}
  52. expect(headlessGetOptions.call(context, url, args, parent)).to.be.eql([
  53. '-incognito',
  54. '--headless',
  55. '--disable-gpu',
  56. '--disable-dev-shm-usage',
  57. '--remote-debugging-port=9222'
  58. ])
  59. })
  60. it('should not overwrite custom remote-debugging-port', function () {
  61. var parent = sinon.stub().returns(
  62. ['-incognito', '--remote-debugging-port=9333']
  63. )
  64. var context = {}
  65. var url = 'http://localhost:9876'
  66. var args = {}
  67. expect(headlessGetOptions.call(context, url, args, parent)).to.be.eql([
  68. '-incognito',
  69. '--remote-debugging-port=9333',
  70. '--headless',
  71. '--disable-gpu',
  72. '--disable-dev-shm-usage'
  73. ])
  74. })
  75. })