Skip to content

Commit 17401aa

Browse files
committed
Cast enabled option to a string
1 parent f9ba071 commit 17401aa

File tree

3 files changed

+99
-2
lines changed

3 files changed

+99
-2
lines changed

src/mixins/componentDebug.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
export function createComponentDebugMixin(options = {}) {
22
const { enabled = process.env.NODE_ENV === 'development' } = options;
33

4+
// Handle string values from environment variables
5+
const isEnabled = typeof enabled === 'string' ? enabled.toLowerCase() === 'true' : Boolean(enabled);
6+
47
return {
58
mounted() {
6-
if (!enabled) {
9+
if (!isEnabled) {
710
return;
811
}
912

@@ -16,7 +19,7 @@ export function createComponentDebugMixin(options = {}) {
1619
this.$el.parentNode?.insertBefore(endComment, this.$el.nextSibling);
1720
},
1821
beforeUnmount() {
19-
if (!enabled) {
22+
if (!isEnabled) {
2023
return;
2124
}
2225

tests/debugMixin.test.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,4 +299,50 @@ describe('createComponentDebugMixin', () => {
299299

300300
wrapper.unmount();
301301
});
302+
303+
it('handles string "false" as disabled', () => {
304+
process.env.NODE_ENV = 'development';
305+
306+
const TestComponent = {
307+
name: 'TestComponent',
308+
__file: 'src/components/TestComponent.vue',
309+
mixins: [createComponentDebugMixin({ enabled: 'false' })],
310+
template: '<div>Test Content</div>',
311+
};
312+
313+
const wrapper = mount(TestComponent, {
314+
attachTo: document.body,
315+
});
316+
317+
const element = wrapper.element;
318+
319+
// Should not have comment siblings when disabled via string "false"
320+
expect(element.previousSibling).toBeNull();
321+
expect(element.nextSibling).toBeNull();
322+
323+
wrapper.unmount();
324+
});
325+
326+
it('handles string "true" as enabled', () => {
327+
process.env.NODE_ENV = 'production';
328+
329+
const TestComponent = {
330+
name: 'TestComponent',
331+
__file: 'src/components/TestComponent.vue',
332+
mixins: [createComponentDebugMixin({ enabled: 'true' })],
333+
template: '<div>Test Content</div>',
334+
};
335+
336+
const wrapper = mount(TestComponent, {
337+
attachTo: document.body,
338+
});
339+
340+
const element = wrapper.element;
341+
342+
// Should have comments even in production when explicitly enabled via string "true"
343+
expect(element.previousSibling?.nodeType).toBe(Node.COMMENT_NODE);
344+
expect(element.nextSibling?.nodeType).toBe(Node.COMMENT_NODE);
345+
346+
wrapper.unmount();
347+
});
302348
});

tests/plugin.test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,52 @@ describe('VueComponentDebug Plugin', () => {
234234

235235
wrapper.unmount();
236236
});
237+
238+
it('handles string "false" from environment variables', () => {
239+
process.env.NODE_ENV = 'development';
240+
241+
const TestComponent = {
242+
name: 'TestComponent',
243+
template: '<div>Test</div>',
244+
};
245+
246+
const wrapper = mount(TestComponent, {
247+
attachTo: document.body,
248+
global: {
249+
plugins: [[VueComponentDebug, { enabled: 'false' }]],
250+
},
251+
});
252+
253+
const element = wrapper.element;
254+
255+
// Should not have comments when disabled via string "false"
256+
expect(element.previousSibling).toBeNull();
257+
expect(element.nextSibling).toBeNull();
258+
259+
wrapper.unmount();
260+
});
261+
262+
it('handles string "true" from environment variables', () => {
263+
process.env.NODE_ENV = 'production';
264+
265+
const TestComponent = {
266+
name: 'TestComponent',
267+
template: '<div>Test</div>',
268+
};
269+
270+
const wrapper = mount(TestComponent, {
271+
attachTo: document.body,
272+
global: {
273+
plugins: [[VueComponentDebug, { enabled: 'true' }]],
274+
},
275+
});
276+
277+
const element = wrapper.element;
278+
279+
// Should have comments when enabled via string "true"
280+
expect(element.previousSibling?.nodeType).toBe(Node.COMMENT_NODE);
281+
expect(element.nextSibling?.nodeType).toBe(Node.COMMENT_NODE);
282+
283+
wrapper.unmount();
284+
});
237285
});

0 commit comments

Comments
 (0)