Преглед изворни кода

chore(test): 初始化测试环境并重构测试页面

- 新增测试依赖及配置,包含vue和axios等相关包
- 添加package.json及pnpm-lock.yaml以支持依赖管理
- 完善.gitignore忽略无关文件和目录,保持工作区整洁
- 重构index.html,替换为简化的Vue应用入口
- 删除旧版监控SDK测试代码,改用模块化入口加载方式
- 设置页面语言为英文,调整标题为“test”
- 增加favicon图标引用,提升页面表现与体验
xbx пре 1 месец
родитељ
комит
83bdc2bf58

+ 24 - 0
test/.gitignore

@@ -0,0 +1,24 @@
+# Logs
+logs
+*.log
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*
+pnpm-debug.log*
+lerna-debug.log*
+
+node_modules
+dist
+dist-ssr
+*.local
+
+# Editor directories and files
+.vscode/*
+!.vscode/extensions.json
+.idea
+.DS_Store
+*.suo
+*.ntvs*
+*.njsproj
+*.sln
+*.sw?

+ 5 - 0
test/README.md

@@ -0,0 +1,5 @@
+# Vue 3 + Vite
+
+This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
+
+Learn more about IDE Support for Vue in the [Vue Docs Scaling up Guide](https://vuejs.org/guide/scaling-up/tooling.html#ide-support).

+ 5 - 105
test/index.html

@@ -1,113 +1,13 @@
 <!doctype html>
-<html lang="zh-CN">
+<html lang="en">
   <head>
     <meta charset="UTF-8" />
+    <link rel="icon" type="image/svg+xml" href="/vite.svg" />
     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
-    <title>Monitor SDK 测试页面</title>
+    <title>test</title>
   </head>
   <body>
-    <h1>监控SDK测试页面</h1>
-    <p>此页面用于测试打包后的监控SDK是否正常工作。</p>
-
-    <!-- 引入打包后的测试函数 -->
-    <script src="../dist/bundle-iife.js"></script>
-
-    <div id="test-container">
-      <button id="trigger-error">触发JavaScript错误</button>
-      <button id="trigger-promise-error">触发Promise错误</button>
-      <button id="simulate-performance-event">模拟性能事件</button>
-      <button id="send-custom-data">发送自定义数据</button>
-      <button id="test-functions">测试函数(test)</button>
-    </div>
-
-    <div id="result">
-      <h3>控制台输出:</h3>
-      <p>请打开开发者工具查看监控SDK的输出信息</p>
-    </div>
-
-    <script>
-      // 页面加载完成后执行测试
-      document.addEventListener("DOMContentLoaded", function () {
-        console.log("页面已加载,监控SDK应该已经初始化");
-
-        // 检查监控SDK是否已正确加载
-        if (window.MonitorSDK && window.monitorInstance) {
-          console.log("监控SDK已成功加载");
-          console.log("SDK实例:", window.monitorInstance);
-        } else {
-          console.error("监控SDK未正确加载");
-        }
-
-        // 测试全局函数是否存在
-        if (window.test && window.testExport) {
-          console.log("✅ 全局函数已成功加载");
-
-          // 测试函数功能
-          console.log("test(5) =", window.test(5));
-          console.log("testExport(5) =", window.testExport(5));
-        } else {
-          console.error("❌ 全局函数未找到");
-        }
-
-        // 绑定按钮事件
-        document.getElementById("test-functions").addEventListener("click", function () {
-          console.log("测试全局函数");
-
-          if (window.test && window.testExport) {
-            const result1 = window.test(10);
-            const result2 = window.testExport(10);
-
-            console.log("window.test(10) =", result1);
-            console.log("window.testExport(10) =", result2);
-
-            alert(`函数调用结果:\ntest(10) = ${result1}\ntestExport(10) = ${result2}`);
-          } else {
-            console.error("函数未定义");
-            alert("函数未定义");
-          }
-        });
-
-        document.getElementById("trigger-error").addEventListener("click", function () {
-          console.log("触发JavaScript错误测试");
-          // 触发一个JavaScript错误
-          throw new Error("这是测试错误");
-        });
-
-        document.getElementById("trigger-promise-error").addEventListener("click", function () {
-          console.log("触发Promise错误测试");
-          // 触发一个Promise错误
-          Promise.reject(new Error("这是测试Promise错误"));
-        });
-
-        document
-          .getElementById("simulate-performance-event")
-          .addEventListener("click", function () {
-            console.log("模拟性能事件");
-            // 这会触发性能监控
-            const start = performance.now();
-            // 模拟一些计算
-            for (let i = 0; i < 1000000; i++) {}
-            const end = performance.now();
-            console.log(`模拟计算耗时: ${end - start} ms`);
-          });
-
-        document.getElementById("send-custom-data").addEventListener("click", function () {
-          console.log("发送自定义数据");
-          // 使用监控实例发送自定义数据
-          if (window.monitorInstance) {
-            window.monitorInstance.reportData({
-              type: "custom_event",
-              message: "自定义事件测试",
-              timestamp: Date.now(),
-            });
-          }
-        });
-      });
-
-      // 页面可见性变化事件(用于测试页面停留时间监控)
-      document.addEventListener("visibilitychange", function () {
-        console.log("页面可见性变化:", document.visibilityState);
-      });
-    </script>
+    <div id="app"></div>
+    <script type="module" src="/src/main.js"></script>
   </body>
 </html>

+ 19 - 0
test/package.json

@@ -0,0 +1,19 @@
+{
+  "name": "test",
+  "private": true,
+  "version": "0.0.0",
+  "type": "module",
+  "scripts": {
+    "dev": "vite",
+    "build": "vite build",
+    "preview": "vite preview"
+  },
+  "dependencies": {
+    "axios": "^1.13.2",
+    "vue": "^3.5.24"
+  },
+  "devDependencies": {
+    "@vitejs/plugin-vue": "^6.0.1",
+    "vite": "^7.2.4"
+  }
+}

Разлика између датотеке није приказан због своје велике величине
+ 1026 - 0
test/pnpm-lock.yaml


Разлика између датотеке није приказан због своје велике величине
+ 1 - 0
test/public/vite.svg


+ 10 - 0
test/src/App.vue

@@ -0,0 +1,10 @@
+<script setup>
+import ErrorTest from './components/ErrorTest.vue'
+</script>
+
+<template>
+  <ErrorTest />
+</template>
+
+<style scoped>
+</style>

+ 33 - 0
test/src/api/request.js

@@ -0,0 +1,33 @@
+import axios from 'axios';
+
+// 创建 axios 实例
+const request = axios.create({
+  baseURL: '/api',
+  timeout: 5000,
+});
+
+// 请求拦截器
+request.interceptors.request.use(
+  (config) => {
+    console.log('[Request]', config.method?.toUpperCase(), config.url);
+    return config;
+  },
+  (error) => {
+    console.error('[Request Error]', error);
+    return Promise.reject(error);
+  }
+);
+
+// 响应拦截器
+request.interceptors.response.use(
+  (response) => {
+    console.log('[Response]', response.status, response.config.url);
+    return response.data;
+  },
+  (error) => {
+    console.error('[Response Error]', error.message);
+    return Promise.reject(error);
+  }
+);
+
+export default request;

+ 1 - 0
test/src/assets/vue.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="37.07" height="36" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 198"><path fill="#41B883" d="M204.8 0H256L128 220.8L0 0h97.92L128 51.2L157.44 0h47.36Z"></path><path fill="#41B883" d="m0 0l128 220.8L256 0h-51.2L128 132.48L50.56 0H0Z"></path><path fill="#35495E" d="M50.56 0L128 133.12L204.8 0h-47.36L128 51.2L97.92 0H50.56Z"></path></svg>

+ 275 - 0
test/src/components/ErrorTest.vue

@@ -0,0 +1,275 @@
+<template>
+  <div class="error-test">
+    <h1>错误监控测试页面</h1>
+    <p>点击下方按钮触发各种错误,用于测试监控 SDK</p>
+
+    <section>
+      <h2>JavaScript 错误</h2>
+      <div class="button-group">
+        <button @click="triggerTypeError">触发 TypeError</button>
+        <button @click="triggerReferenceError">触发 ReferenceError</button>
+        <button @click="triggerSyntaxError">触发 eval SyntaxError</button>
+        <button @click="triggerRangeError">触发 RangeError</button>
+        <button @click="triggerCustomError">触发自定义 Error</button>
+      </div>
+    </section>
+
+    <section>
+      <h2>Promise 错误</h2>
+      <div class="button-group">
+        <button @click="triggerUnhandledRejection">未处理的 Promise 拒绝</button>
+        <button @click="triggerAsyncError">Async/Await 错误</button>
+      </div>
+    </section>
+
+    <section>
+      <h2>Axios 请求错误</h2>
+      <div class="button-group">
+        <button @click="triggerAxios404">404 Not Found</button>
+        <button @click="triggerAxios500">500 Server Error</button>
+        <button @click="triggerAxiosTimeout">请求超时</button>
+        <button @click="triggerAxiosNetworkError">网络错误</button>
+      </div>
+    </section>
+
+    <section>
+      <h2>正常请求(Mock)</h2>
+      <div class="button-group">
+        <button @click="fetchUser">获取用户信息</button>
+        <button @click="fetchList">获取列表数据</button>
+      </div>
+    </section>
+
+    <section v-if="result">
+      <h2>请求结果</h2>
+      <pre>{{ result }}</pre>
+    </section>
+
+    <section v-if="errorLog.length">
+      <h2>错误日志</h2>
+      <ul class="error-log">
+        <li v-for="(err, index) in errorLog" :key="index" class="error-item">
+          <span class="error-type">{{ err.type }}</span>
+          <span class="error-message">{{ err.message }}</span>
+        </li>
+      </ul>
+    </section>
+  </div>
+</template>
+
+<script setup>
+import { ref } from 'vue';
+import request from '../api/request';
+
+const result = ref(null);
+const errorLog = ref([]);
+
+// 记录错误
+function logError(type, message) {
+  errorLog.value.unshift({ type, message, time: new Date().toLocaleTimeString() });
+  if (errorLog.value.length > 10) {
+    errorLog.value.pop();
+  }
+}
+
+// ============ JavaScript 错误 ============
+
+function triggerTypeError() {
+  try {
+    const obj = null;
+    obj.someMethod(); // TypeError: Cannot read properties of null
+  } catch (e) {
+    logError('TypeError', e.message);
+    throw e; // 重新抛出让监控 SDK 捕获
+  }
+}
+
+function triggerReferenceError() {
+  try {
+    // eslint-disable-next-line no-undef
+    console.log(undefinedVariable); // ReferenceError
+  } catch (e) {
+    logError('ReferenceError', e.message);
+    throw e;
+  }
+}
+
+function triggerSyntaxError() {
+  try {
+    eval('const a = {'); // SyntaxError
+  } catch (e) {
+    logError('SyntaxError', e.message);
+    throw e;
+  }
+}
+
+function triggerRangeError() {
+  try {
+    const arr = new Array(-1); // RangeError: Invalid array length
+    console.log(arr);
+  } catch (e) {
+    logError('RangeError', e.message);
+    throw e;
+  }
+}
+
+function triggerCustomError() {
+  const error = new Error('这是一个自定义错误消息');
+  logError('CustomError', error.message);
+  throw error;
+}
+
+// ============ Promise 错误 ============
+
+function triggerUnhandledRejection() {
+  // 未处理的 Promise 拒绝
+  Promise.reject(new Error('未处理的 Promise 拒绝错误'));
+  logError('UnhandledRejection', '已触发未处理的 Promise 拒绝');
+}
+
+async function triggerAsyncError() {
+  try {
+    await Promise.reject(new Error('Async/Await 中的错误'));
+  } catch (e) {
+    logError('AsyncError', e.message);
+    throw e;
+  }
+}
+
+// ============ Axios 请求错误 ============
+
+async function triggerAxios404() {
+  try {
+    await request.get('/not-found');
+  } catch (e) {
+    logError('Axios 404', e.message);
+  }
+}
+
+async function triggerAxios500() {
+  try {
+    await request.get('/server-error');
+  } catch (e) {
+    logError('Axios 500', e.message);
+  }
+}
+
+async function triggerAxiosTimeout() {
+  try {
+    await request.get('/timeout');
+  } catch (e) {
+    logError('Axios Timeout', e.message);
+  }
+}
+
+async function triggerAxiosNetworkError() {
+  try {
+    await request.get('/network-error');
+  } catch (e) {
+    logError('Axios Network', e.message);
+  }
+}
+
+// ============ 正常请求 ============
+
+async function fetchUser() {
+  try {
+    const data = await request.get('/user');
+    result.value = JSON.stringify(data, null, 2);
+  } catch (e) {
+    logError('FetchUser', e.message);
+  }
+}
+
+async function fetchList() {
+  try {
+    const data = await request.get('/list');
+    result.value = JSON.stringify(data, null, 2);
+  } catch (e) {
+    logError('FetchList', e.message);
+  }
+}
+</script>
+
+<style scoped>
+.error-test {
+  max-width: 800px;
+  margin: 0 auto;
+  padding: 20px;
+  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
+}
+
+h1 {
+  color: #333;
+  border-bottom: 2px solid #42b883;
+  padding-bottom: 10px;
+}
+
+h2 {
+  color: #666;
+  font-size: 1.2em;
+  margin-top: 24px;
+}
+
+section {
+  margin-bottom: 24px;
+  padding: 16px;
+  background: #f9f9f9;
+  border-radius: 8px;
+}
+
+.button-group {
+  display: flex;
+  flex-wrap: wrap;
+  gap: 10px;
+}
+
+button {
+  padding: 10px 16px;
+  border: none;
+  border-radius: 6px;
+  background: #42b883;
+  color: white;
+  cursor: pointer;
+  font-size: 14px;
+  transition: background 0.2s;
+}
+
+button:hover {
+  background: #369970;
+}
+
+pre {
+  background: #282c34;
+  color: #abb2bf;
+  padding: 16px;
+  border-radius: 6px;
+  overflow-x: auto;
+}
+
+.error-log {
+  list-style: none;
+  padding: 0;
+  margin: 0;
+}
+
+.error-item {
+  display: flex;
+  gap: 12px;
+  padding: 8px 12px;
+  background: #fff;
+  border-left: 4px solid #e74c3c;
+  margin-bottom: 8px;
+  border-radius: 0 4px 4px 0;
+}
+
+.error-type {
+  font-weight: bold;
+  color: #e74c3c;
+  min-width: 120px;
+}
+
+.error-message {
+  color: #666;
+}
+</style>

+ 43 - 0
test/src/components/HelloWorld.vue

@@ -0,0 +1,43 @@
+<script setup>
+import { ref } from 'vue'
+
+defineProps({
+  msg: String,
+})
+
+const count = ref(0)
+</script>
+
+<template>
+  <h1>{{ msg }}</h1>
+
+  <div class="card">
+    <button type="button" @click="count++">count is {{ count }}</button>
+    <p>
+      Edit
+      <code>components/HelloWorld.vue</code> to test HMR
+    </p>
+  </div>
+
+  <p>
+    Check out
+    <a href="https://vuejs.org/guide/quick-start.html#local" target="_blank"
+      >create-vue</a
+    >, the official Vue + Vite starter
+  </p>
+  <p>
+    Learn more about IDE Support for Vue in the
+    <a
+      href="https://vuejs.org/guide/scaling-up/tooling.html#ide-support"
+      target="_blank"
+      >Vue Docs Scaling up Guide</a
+    >.
+  </p>
+  <p class="read-the-docs">Click on the Vite and Vue logos to learn more</p>
+</template>
+
+<style scoped>
+.read-the-docs {
+  color: #888;
+}
+</style>

+ 9 - 0
test/src/main.js

@@ -0,0 +1,9 @@
+import { createApp } from 'vue'
+import './style.css'
+import App from './App.vue'
+import { setupMock } from './mock'
+
+// 启用 Mock 拦截器
+setupMock()
+
+createApp(App).mount('#app')

+ 68 - 0
test/src/mock/index.js

@@ -0,0 +1,68 @@
+import axios from 'axios';
+
+// 简单的 Mock 拦截器
+const mockData = {
+  '/api/user': { id: 1, name: '测试用户', email: 'test@example.com' },
+  '/api/list': [{ id: 1, title: '项目1' }, { id: 2, title: '项目2' }],
+};
+
+// 模拟延迟
+const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
+
+// 设置 Mock 拦截器
+export function setupMock() {
+  axios.interceptors.request.use(async (config) => {
+    const url = config.baseURL + config.url;
+
+    // 模拟 404 错误
+    if (config.url?.includes('/not-found')) {
+      await delay(300);
+      const error = new Error('Request failed with status code 404');
+      error.response = { status: 404, data: { message: 'Not Found' } };
+      error.config = config;
+      return Promise.reject(error);
+    }
+
+    // 模拟 500 服务器错误
+    if (config.url?.includes('/server-error')) {
+      await delay(300);
+      const error = new Error('Request failed with status code 500');
+      error.response = { status: 500, data: { message: 'Internal Server Error' } };
+      error.config = config;
+      return Promise.reject(error);
+    }
+
+    // 模拟超时错误
+    if (config.url?.includes('/timeout')) {
+      await delay(6000); // 超过 timeout 设置
+      return config;
+    }
+
+    // 模拟网络错误
+    if (config.url?.includes('/network-error')) {
+      await delay(300);
+      const error = new Error('Network Error');
+      error.config = config;
+      return Promise.reject(error);
+    }
+
+    // 正常 Mock 响应
+    const mockKey = Object.keys(mockData).find((key) => url.includes(key));
+    if (mockKey) {
+      await delay(300);
+      config.adapter = () => {
+        return Promise.resolve({
+          data: mockData[mockKey],
+          status: 200,
+          statusText: 'OK',
+          headers: {},
+          config,
+        });
+      };
+    }
+
+    return config;
+  });
+
+  console.log('[Mock] Mock 拦截器已启用');
+}

+ 79 - 0
test/src/style.css

@@ -0,0 +1,79 @@
+:root {
+  font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
+  line-height: 1.5;
+  font-weight: 400;
+
+  color-scheme: light dark;
+  color: rgba(255, 255, 255, 0.87);
+  background-color: #242424;
+
+  font-synthesis: none;
+  text-rendering: optimizeLegibility;
+  -webkit-font-smoothing: antialiased;
+  -moz-osx-font-smoothing: grayscale;
+}
+
+a {
+  font-weight: 500;
+  color: #646cff;
+  text-decoration: inherit;
+}
+a:hover {
+  color: #535bf2;
+}
+
+body {
+  margin: 0;
+  display: flex;
+  place-items: center;
+  min-width: 320px;
+  min-height: 100vh;
+}
+
+h1 {
+  font-size: 3.2em;
+  line-height: 1.1;
+}
+
+button {
+  border-radius: 8px;
+  border: 1px solid transparent;
+  padding: 0.6em 1.2em;
+  font-size: 1em;
+  font-weight: 500;
+  font-family: inherit;
+  background-color: #1a1a1a;
+  cursor: pointer;
+  transition: border-color 0.25s;
+}
+button:hover {
+  border-color: #646cff;
+}
+button:focus,
+button:focus-visible {
+  outline: 4px auto -webkit-focus-ring-color;
+}
+
+.card {
+  padding: 2em;
+}
+
+#app {
+  max-width: 1280px;
+  margin: 0 auto;
+  padding: 2rem;
+  text-align: center;
+}
+
+@media (prefers-color-scheme: light) {
+  :root {
+    color: #213547;
+    background-color: #ffffff;
+  }
+  a:hover {
+    color: #747bff;
+  }
+  button {
+    background-color: #f9f9f9;
+  }
+}

+ 0 - 130
test/test-cjs.js

@@ -1,130 +0,0 @@
-/**
- * 测试CommonJS格式的监控SDK bundle
- */
-
-// 在Node.js环境中测试CJS格式的bundle
-console.log("开始测试CommonJS格式的监控SDK");
-
-try {
-  // 动态引入CJS格式的bundle
-  const MonitorSDK = require("../dist/bundle-cjs.js");
-
-  console.log("CommonJS格式的监控SDK已加载");
-  console.log("MonitorSDK类型:", typeof MonitorSDK);
-
-  // 注意:由于Node.js环境缺少浏览器API(如window、document、performance等)
-  // 直接初始化可能会出错,所以我们只测试基本导入功能
-
-  // 检查MonitorSDK构造函数是否存在
-  if (typeof MonitorSDK === "function") {
-    console.log("✅ MonitorSDK构造函数存在");
-  } else {
-    console.log("❌ MonitorSDK不是函数");
-  }
-
-  console.log("\n注意:由于Node.js环境缺少浏览器API,完整的SDK功能无法在此环境中测试。");
-  console.log("完整的功能测试需要在浏览器环境中进行。");
-} catch (error) {
-  console.error("❌ 加载CommonJS格式的bundle时出错:", error.message);
-}
-
-// 模拟浏览器环境的部分功能以测试SDK
-console.log("\n--- 模拟浏览器环境测试 ---");
-
-// 为Node.js环境模拟必要的浏览器API
-global.window = global;
-global.document = {
-  addEventListener: function (event, handler) {
-    console.log(`模拟添加${event}事件监听器`);
-  },
-};
-global.performance = {
-  timing: {
-    navigationStart: Date.now(),
-    domainLookupStart: Date.now(),
-    domainLookupEnd: Date.now() + 1,
-    connectStart: Date.now() + 1,
-    connectEnd: Date.now() + 2,
-    requestStart: Date.now() + 2,
-    responseStart: Date.now() + 3,
-    responseEnd: Date.now() + 4,
-    domLoading: Date.now() + 5,
-    domContentLoadedEventStart: Date.now() + 6,
-    domContentLoadedEventEnd: Date.now() + 7,
-    loadEventStart: Date.now() + 8,
-    loadEventEnd: Date.now() + 9,
-  },
-  getEntriesByType: function (type) {
-    console.log(`模拟获取${type}类型的性能条目`);
-    return [];
-  },
-};
-global.navigator = {
-  userAgent: "Test Node Environment",
-  sendBeacon: function (url, data) {
-    console.log("模拟sendBeacon调用:", url, data);
-    return true;
-  },
-};
-global.fetch = function (url, options) {
-  console.log("模拟fetch调用:", url, options);
-  return Promise.resolve({
-    ok: true,
-    json: () => Promise.resolve({}),
-  });
-};
-
-// 现在尝试动态加载并初始化SDK
-setTimeout(() => {
-  try {
-    // 重新require以确保使用新的全局变量
-    delete require.cache[require.resolve("../dist/bundle-cjs.js")];
-    const MonitorSDK = require("../dist/bundle-cjs.js");
-
-    // 创建实例
-    const monitor = new MonitorSDK({
-      appId: "test-app",
-      apiUrl: "http://localhost:3000/api/monitor",
-      enableErrorTracking: true,
-      enablePerformanceTracking: true,
-      enableUserBehaviorTracking: false, // 避免在Node.js中使用document
-      enableResourceTracking: true,
-      sampleRate: 1.0,
-    });
-
-    console.log("✅ 成功创建MonitorSDK实例");
-
-    // 测试错误上报功能
-    if (monitor && typeof monitor.reportError === "function") {
-      console.log("✅ reportError方法存在");
-
-      monitor.reportError({
-        type: "test_error",
-        message: "测试错误",
-        timestamp: Date.now(),
-      });
-
-      console.log("✅ 成功调用reportError方法");
-    } else {
-      console.log("❌ reportError方法不存在");
-    }
-
-    // 测试数据上报功能
-    if (monitor && typeof monitor.reportData === "function") {
-      console.log("✅ reportData方法存在");
-
-      monitor.reportData({
-        type: "test_data",
-        message: "测试数据",
-        timestamp: Date.now(),
-      });
-
-      console.log("✅ 成功调用reportData方法");
-    } else {
-      console.log("❌ reportData方法不存在");
-    }
-  } catch (error) {
-    console.error("❌ 在模拟环境中初始化SDK时出错:", error.message);
-    console.error("堆栈:", error.stack);
-  }
-}, 100);

+ 0 - 88
test/test-esm.html

@@ -1,88 +0,0 @@
-<!doctype html>
-<html lang="zh-CN">
-  <head>
-    <meta charset="UTF-8" />
-    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
-    <title>ESM格式监控SDK测试</title>
-  </head>
-  <body>
-    <h1>ESM格式监控SDK测试页面</h1>
-    <p>此页面用于测试ES模块格式的监控SDK是否正常工作。</p>
-
-    <div id="test-container">
-      <button id="test-esm-sdk">测试ESM格式SDK</button>
-      <button id="test-esm-functionality">测试ESM功能</button>
-    </div>
-
-    <div id="result">
-      <h3>控制台输出:</h3>
-      <p>请打开开发者工具查看监控SDK的输出信息</p>
-    </div>
-
-    <!-- 使用ES模块语法导入SDK -->
-    <script type="module">
-      // 从ESM格式的bundle中导入
-      // 注意:由于我们的bundle没有导出默认对象,我们需要使用动态导入
-      console.log("开始测试ESM格式的监控SDK");
-
-      // 动态导入ESM格式的bundle
-      import("../dist/bundle-esm.js")
-        .then((module) => {
-          console.log("ESM格式的监控SDK已加载");
-          console.log("模块内容:", module);
-
-          // 检查全局对象是否可用(我们的代码会在全局作用域创建实例)
-          if (window.MonitorSDK && window.monitorInstance) {
-            console.log("✅ ESM格式SDK成功初始化全局对象");
-
-            // 绑定按钮事件
-            document.getElementById("test-esm-sdk").addEventListener("click", function () {
-              console.log("测试ESM格式SDK功能");
-
-              // 测试SDK实例
-              if (window.monitorInstance) {
-                console.log("SDK实例存在,版本信息:", window.monitorInstance.config);
-
-                // 测试数据上报
-                window.monitorInstance.reportData({
-                  type: "esm_test_event",
-                  message: "ESM格式SDK测试事件",
-                  timestamp: Date.now(),
-                });
-              }
-            });
-
-            document
-              .getElementById("test-esm-functionality")
-              .addEventListener("click", function () {
-                console.log("测试ESM格式SDK各项功能");
-
-                // 测试错误上报
-                try {
-                  throw new Error("ESM格式SDK测试错误");
-                } catch (e) {
-                  window.monitorInstance.reportError({
-                    type: "esm_test_error",
-                    message: e.message,
-                    stack: e.stack,
-                    timestamp: Date.now(),
-                  });
-                }
-
-                // 测试性能数据
-                window.monitorInstance.reportData({
-                  type: "esm_performance_test",
-                  loadTime: 100,
-                  timestamp: Date.now(),
-                });
-              });
-          } else {
-            console.error("❌ ESM格式SDK未正确初始化全局对象");
-          }
-        })
-        .catch((error) => {
-          console.error("❌ 加载ESM格式的bundle时出错:", error);
-        });
-    </script>
-  </body>
-</html>

+ 7 - 0
test/vite.config.js

@@ -0,0 +1,7 @@
+import { defineConfig } from 'vite'
+import vue from '@vitejs/plugin-vue'
+
+// https://vite.dev/config/
+export default defineConfig({
+  plugins: [vue()],
+})