From 4863efee788bee679a16268876aacca021bd728f Mon Sep 17 00:00:00 2001 From: littlefairy <2195134613@qq.com> Date: Mon, 18 Mar 2024 21:10:19 +0800 Subject: [PATCH] update test.js --- test.js | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 test.js diff --git a/test.js b/test.js new file mode 100644 index 0000000..9ee09b8 --- /dev/null +++ b/test.js @@ -0,0 +1,64 @@ +const { JSDOM } = require('jsdom'); +const jsdom=require('jsdom'); +const fs = require('fs'); +const path = require('path'); + +async function test(str){ + const localStorageMock = { + setItem: function (key, value) { + this[key] = value; + }, + getItem: function (key) { + return this[key] || null; + }, + removeItem: function (key) { + delete this[key]; + }, + clear: function () { + for (const key in this) { + if (this.hasOwnProperty(key) && key !== 'setItem' && key !== 'getItem' && key !== 'removeItem' && key !== 'clear') { + delete this[key]; + } + } + } + }; + // 在你的 JSDOM 初始化代码之前 + let resolvePromise; + + // 创建一个 Promise,它会在 window.resolve 被调用时解决 + const resolver = new Promise(resolve => { + resolvePromise = resolve; + }); + const virtualConsole = new jsdom.VirtualConsole(); + const dom = new JSDOM(fs.readFileSync(path.join(__dirname, 'static/md5.html'), 'utf-8'), { + url: 'file://' + path.join(__dirname, 'static/'), + console:virtualConsole, + runScripts: 'dangerously', + resources: 'usable', + beforeParse(window) { + window.FakelocalStorage = localStorageMock; + window.config =[{"count":10000}]; + window.name_input = str; + window.stage = 0; + window.skillData = []; + window.resolve = (...args) => { + //console.log(args); + resolvePromise(...args); + window.close(); + } + } + }); + + virtualConsole.on('log', (message) => { + console.log('From the page:', message); + }); + + const result = await resolver + //console.log(result) +} + + +//str="!test!\n!\n\n11@qwerb\n\n1233"; +str="!test!\n!\n\n11@qwerb\n1233"; +test(str) +