|
1 | | -import{prettyDOM,logDOM}from'../pretty-dom' |
2 | | -import {getUserCodeFrame} from '../get-user-code-frame' |
| 1 | +/* global globalThis */ |
| 2 | +import {prettyDOMasprettyDOMImpl} from '../pretty-dom' |
3 | 3 | import {render, renderIntoDocument} from './helpers/test-utils'
|
4 | 4 |
|
5 | | -jest.mock('../get-user-code-frame') |
6 | | - |
7 | | -beforeEach(() => { |
8 | | - jest.spyOn(console, 'log').mockImplementation(() => {}) |
9 | | -}) |
10 | | - |
11 | | -afterEach(() => { |
12 | | - console.log.mockRestore() |
13 | | -}) |
| 5 | +function prettyDOM(...args) { |
| 6 | + let originalProcess |
| 7 | + // this shouldn't be defined in this environment in the first place |
| 8 | + if (typeof process === 'undefined') { |
| 9 | + throw new Error('process is no longer defined. Remove this setup code.') |
| 10 | + } else { |
| 11 | + originalProcess = process |
| 12 | + delete globalThis.process |
| 13 | + } |
| 14 | + |
| 15 | + try { |
| 16 | + return prettyDOMImpl(...args) |
| 17 | + } finally { |
| 18 | + globalThis.process = originalProcess |
| 19 | + } |
| 20 | +} |
14 | 21 |
|
15 | 22 | test('prettyDOM prints out the given DOM element tree', () => {
|
16 | 23 | const {container} = render('<div>Hello World!</div>')
|
@@ -58,49 +65,6 @@ test('prettyDOM supports receiving the document element', () => {
|
58 | 65 | `)
|
59 | 66 | })
|
60 | 67 |
|
61 | | -test('logDOM logs prettyDOM to the console', () => { |
62 | | - const {container} = render('<div>Hello World!</div>') |
63 | | - logDOM(container) |
64 | | - expect(console.log).toHaveBeenCalledTimes(1) |
65 | | - expect(console.log.mock.calls[0][0]).toMatchInlineSnapshot(` |
66 | | - <div> |
67 | | - <div> |
68 | | - Hello World! |
69 | | - </div> |
70 | | - </div> |
71 | | - `) |
72 | | -}) |
73 | | - |
74 | | -test('logDOM logs prettyDOM with code frame to the console', () => { |
75 | | - getUserCodeFrame.mockImplementationOnce( |
76 | | - () => `"/home/john/projects/sample-error/error-example.js:7:14 |
77 | | - 5 | document.createTextNode('Hello World!') |
78 | | - 6 | ) |
79 | | - > 7 | screen.debug() |
80 | | - | ^ |
81 | | - " |
82 | | - `, |
83 | | - ) |
84 | | - const {container} = render('<div>Hello World!</div>') |
85 | | - logDOM(container) |
86 | | - expect(console.log).toHaveBeenCalledTimes(1) |
87 | | - expect(console.log.mock.calls[0][0]).toMatchInlineSnapshot(` |
88 | | - <div> |
89 | | - <div> |
90 | | - Hello World! |
91 | | - </div> |
92 | | - </div> |
93 | | - |
94 | | - "/home/john/projects/sample-error/error-example.js:7:14 |
95 | | - 5 | document.createTextNode('Hello World!') |
96 | | - 6 | ) |
97 | | - > 7 | screen.debug() |
98 | | - | ^ |
99 | | - " |
100 | | - |
101 | | - `) |
102 | | -}) |
103 | | - |
104 | 68 | describe('prettyDOM fails with first parameter without outerHTML field', () => {
|
105 | 69 | test('with array', () => {
|
106 | 70 | expect(() => prettyDOM(['outerHTML'])).toThrowErrorMatchingInlineSnapshot(
|
@@ -153,20 +117,6 @@ test('prettyDOM can include all elements with a custom filter', () => {
|
153 | 117 | `)
|
154 | 118 | })
|
155 | 119 |
|
156 | | -test('prettyDOM supports a COLORS environment variable', () => { |
157 | | - const {container} = render('<div>Hello World!</div>') |
158 | | - |
159 | | - const noColors = prettyDOM(container, undefined, {highlight: false}) |
160 | | - const withColors = prettyDOM(container, undefined, {highlight: true}) |
161 | | - |
162 | | - // process.env.COLORS is a string, so make sure we test it as such |
163 | | - process.env.COLORS = 'false' |
164 | | - expect(prettyDOM(container)).toEqual(noColors) |
165 | | - |
166 | | - process.env.COLORS = 'true' |
167 | | - expect(prettyDOM(container)).toEqual(withColors) |
168 | | -}) |
169 | | - |
170 | 120 | test('prettyDOM supports named custom elements', () => {
|
171 | 121 | window.customElements.define(
|
172 | 122 | 'my-element-1',
|
|
0 commit comments