Skip to content

Commit 56797df

Browse files
committed
test: add module enable/disable tests
- Add test cases to verify UTM tracking behavior when module is enabled - Add test cases to verify UTM tracking is disabled when module is configured off - Create new test fixture for disabled module configuration This ensures the module's `enabled` configuration option works as expected.
1 parent 2e46656 commit 56797df

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

test/fixtures/disabled/app.vue

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<template>
2+
<div>
3+
<h1>UTM Tracker</h1>
4+
<pre>{{ $utm }}</pre>
5+
</div>
6+
</template>
7+
8+
<script setup>
9+
import { useNuxtApp } from "nuxt/app";
10+
11+
const { $utm } = useNuxtApp();
12+
</script>

test/fixtures/disabled/nuxt.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import UtmModule from "../../../src/module";
2+
3+
export default defineNuxtConfig({
4+
modules: [UtmModule],
5+
utm: {
6+
enabled: false,
7+
},
8+
});

test/integration.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,40 @@ describe("ssr", async () => {
113113
});
114114
});
115115
});
116+
117+
describe("Module configuration", () => {
118+
describe("when enabled", async () => {
119+
await setup({
120+
rootDir: fileURLToPath(new URL("./fixtures/basic", import.meta.url)),
121+
browser: true,
122+
});
123+
124+
it("should track UTM parameters", async () => {
125+
const page = await createPage(
126+
"/?utm_source=test_source&utm_medium=test_medium"
127+
);
128+
const rawData = await page.evaluate(() =>
129+
window.localStorage.getItem("nuxt-utm-data")
130+
);
131+
const entries = JSON.parse(rawData ?? "[]");
132+
expect(entries.length).toBeGreaterThan(0);
133+
});
134+
});
135+
136+
describe("when disabled", async () => {
137+
await setup({
138+
rootDir: fileURLToPath(new URL("./fixtures/disabled", import.meta.url)),
139+
browser: true,
140+
});
141+
142+
it("should not track UTM parameters", async () => {
143+
const page = await createPage(
144+
"/?utm_source=test_source&utm_medium=test_medium"
145+
);
146+
const rawData = await page.evaluate(() =>
147+
window.localStorage.getItem("nuxt-utm-data")
148+
);
149+
expect(rawData).toBeNull();
150+
});
151+
});
152+
});

0 commit comments

Comments
 (0)