debug.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.assert = assert;
  6. exports.debugAssert = debugAssert;
  7. exports.debugMode = debugMode;
  8. exports.isUnderTest = isUnderTest;
  9. exports.setUnderTest = setUnderTest;
  10. var _env = require("./env");
  11. /**
  12. * Copyright (c) Microsoft Corporation.
  13. *
  14. * Licensed under the Apache License, Version 2.0 (the "License");
  15. * you may not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at
  17. *
  18. * http://www.apache.org/licenses/LICENSE-2.0
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an "AS IS" BASIS,
  22. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. */
  26. function assert(value, message) {
  27. if (!value) throw new Error(message || 'Assertion error');
  28. }
  29. function debugAssert(value, message) {
  30. if (isUnderTest() && !value) throw new Error(message);
  31. }
  32. const debugEnv = (0, _env.getFromENV)('PWDEBUG') || '';
  33. function debugMode() {
  34. if (debugEnv === 'console') return 'console';
  35. if (debugEnv === '0' || debugEnv === 'false') return '';
  36. return debugEnv ? 'inspector' : '';
  37. }
  38. let _isUnderTest = !!process.env.PWTEST_UNDER_TEST;
  39. function setUnderTest() {
  40. _isUnderTest = true;
  41. }
  42. function isUnderTest() {
  43. return _isUnderTest;
  44. }