Skip to content

Commit

Permalink
test: add module enable/disable tests
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
sadjow committed Nov 21, 2024
1 parent 2e46656 commit 56797df
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/fixtures/disabled/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<template>
<div>
<h1>UTM Tracker</h1>
<pre>{{ $utm }}</pre>
</div>
</template>

<script setup>
import { useNuxtApp } from "nuxt/app";
const { $utm } = useNuxtApp();
</script>
8 changes: 8 additions & 0 deletions test/fixtures/disabled/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import UtmModule from "../../../src/module";

export default defineNuxtConfig({
modules: [UtmModule],
utm: {
enabled: false,
},
});
37 changes: 37 additions & 0 deletions test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,40 @@ describe("ssr", async () => {
});
});
});

describe("Module configuration", () => {
describe("when enabled", async () => {
await setup({
rootDir: fileURLToPath(new URL("./fixtures/basic", import.meta.url)),
browser: true,
});

it("should track UTM parameters", async () => {
const page = await createPage(
"/?utm_source=test_source&utm_medium=test_medium"
);
const rawData = await page.evaluate(() =>
window.localStorage.getItem("nuxt-utm-data")
);
const entries = JSON.parse(rawData ?? "[]");
expect(entries.length).toBeGreaterThan(0);
});
});

describe("when disabled", async () => {
await setup({
rootDir: fileURLToPath(new URL("./fixtures/disabled", import.meta.url)),
browser: true,
});

it("should not track UTM parameters", async () => {
const page = await createPage(
"/?utm_source=test_source&utm_medium=test_medium"
);
const rawData = await page.evaluate(() =>
window.localStorage.getItem("nuxt-utm-data")
);
expect(rawData).toBeNull();
});
});
});

0 comments on commit 56797df

Please sign in to comment.