no-warnings.test.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. 'use strict'
  2. const { test } = require('tap')
  3. const { spawnSync } = require('child_process')
  4. const { resolve } = require('path')
  5. const entry = resolve(__dirname, '../examples', 'example.js')
  6. test('--no-warnings is set in cli', t => {
  7. t.plan(1)
  8. const child = spawnSync(process.execPath, [
  9. '--no-warnings',
  10. entry
  11. ])
  12. const stderr = child.stderr.toString()
  13. t.equal(stderr, '')
  14. })
  15. test('--no-warnings is not set in cli', t => {
  16. t.plan(1)
  17. const child = spawnSync(process.execPath, [
  18. entry
  19. ])
  20. const stderr = child.stderr.toString()
  21. t.match(stderr, /\[CUSTDEP001\] DeprecationWarning: This is a deprecation warning/)
  22. })
  23. test('NODE_NO_WARNINGS is set to 1', t => {
  24. t.plan(1)
  25. const child = spawnSync(process.execPath, [
  26. entry
  27. ], {
  28. env: {
  29. NODE_NO_WARNINGS: '1'
  30. }
  31. })
  32. const stderr = child.stderr.toString()
  33. t.equal(stderr, '')
  34. })
  35. test('NODE_NO_WARNINGS is set to 0', t => {
  36. t.plan(1)
  37. const child = spawnSync(process.execPath, [
  38. entry
  39. ], {
  40. env: {
  41. NODE_NO_WARNINGS: '0'
  42. }
  43. })
  44. const stderr = child.stderr.toString()
  45. t.match(stderr, /\[CUSTDEP001\] DeprecationWarning: This is a deprecation warning/)
  46. })
  47. test('NODE_NO_WARNINGS is not set', t => {
  48. t.plan(1)
  49. const child = spawnSync(process.execPath, [
  50. entry
  51. ])
  52. const stderr = child.stderr.toString()
  53. t.match(stderr, /\[CUSTDEP001\] DeprecationWarning: This is a deprecation warning/)
  54. })
  55. test('NODE_Options contains --no-warnings', t => {
  56. t.plan(1)
  57. const child = spawnSync(process.execPath, [
  58. entry
  59. ], {
  60. env: {
  61. NODE_OPTIONS: '--no-warnings'
  62. }
  63. })
  64. const stderr = child.stderr.toString()
  65. t.equal(stderr, '')
  66. })