Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion packages/wxt/src/core/utils/__tests__/content-scripts.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { describe, expect, it, beforeEach } from 'vitest';
import { hashContentScriptOptions } from '../content-scripts';
import {
hashContentScriptOptions,
mapWxtOptionsToRegisteredContentScript,
} from '../content-scripts';
import { setFakeWxt } from '../testing/fake-objects';

describe('Content Script Utils', () => {
Expand Down Expand Up @@ -30,4 +33,44 @@ describe('Content Script Utils', () => {
expect(hash1).toBe(hash2);
});
});

describe('mapWxtOptionsToRegisteredContentScript', () => {
it('preserves matchOriginAsFallback for dynamic registration', () => {
const contentScript = mapWxtOptionsToRegisteredContentScript(
{
matches: ['*://example.com/*'],
matchOriginAsFallback: true,
allFrames: true,
runAt: 'document_start',
world: 'MAIN',
},
['content-scripts/example.js'],
undefined,
);

expect(contentScript).toEqual({
allFrames: true,
excludeMatches: undefined,
matchOriginAsFallback: true,
matches: ['*://example.com/*'],
runAt: 'document_start',
js: ['content-scripts/example.js'],
css: undefined,
world: 'MAIN',
});
});

it('preserves false matchOriginAsFallback values', () => {
const contentScript = mapWxtOptionsToRegisteredContentScript(
{
matches: ['*://example.com/*'],
matchOriginAsFallback: false,
},
['content-scripts/example.js'],
[],
);

expect(contentScript.matchOriginAsFallback).toBe(false);
});
});
});
1 change: 1 addition & 0 deletions packages/wxt/src/core/utils/content-scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export function mapWxtOptionsToRegisteredContentScript(
return {
allFrames: options.allFrames,
excludeMatches: options.excludeMatches,
matchOriginAsFallback: options.matchOriginAsFallback,
matches: options.matches,
runAt: options.runAt,
js,
Expand Down