jsdom

Setting global variables in a script loaded by jsdom

…衆ロ難τιáo~ 提交于 2021-02-19 05:35:08
问题 I'm trying to run some browser code in Node.js in order to simplify testing (deasync is the reason). Currently, I use jsdom to parse the only html file. At first, I was trying to make it also load the scripts, which are linked in <script> tags. But due to some stupid issues with relative file paths I have switched to passing a list of absolute paths to the script files as a parameter to jsdom.env function. Now I'm pretty sure that jsdom finds my scripts properly, but I cannot set any global

How to access DOM using Node.js?

◇◆丶佛笑我妖孽 提交于 2021-02-18 00:57:26
问题 I have an editor.html that contains generatePNG function: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Diagram</title> <script type="text/javascript" src="lib/jquery-1.8.1.js"></script> // <!-- I use many resources --> <script></script> <script> function generatePNG (oViewer) { var oImageOptions = { includeDecoratorLayers: false, replaceImageURL: true }; var d = new Date(); var h = d.getHours(); var m = d.getMinutes(); var s = d.getSeconds(); var sFileName = "diagram" + h

How to access DOM using Node.js?

谁说胖子不能爱 提交于 2021-02-18 00:55:36
问题 I have an editor.html that contains generatePNG function: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Diagram</title> <script type="text/javascript" src="lib/jquery-1.8.1.js"></script> // <!-- I use many resources --> <script></script> <script> function generatePNG (oViewer) { var oImageOptions = { includeDecoratorLayers: false, replaceImageURL: true }; var d = new Date(); var h = d.getHours(); var m = d.getMinutes(); var s = d.getSeconds(); var sFileName = "diagram" + h

how to use jsdom to test functions with 'document'

会有一股神秘感。 提交于 2021-02-11 15:43:59
问题 I have a small question.. I am trying to test some functions I created (written in Typescript), and I am using mocha/chai/jsdom. Now, I get an error while testing functions with 'document' inside the document.. I get the message 'ReferenceError: document is not defined'. How can I still test these functions with 'document' in it? For example: [prompt.spec.ts] import { expect } from 'chai' import { JSDOM } from 'jsdom' import { functionX } from './functions' describe('Functions', () => { it(

Webpack 构建优化总结

ⅰ亾dé卋堺 提交于 2021-02-07 09:33:25
初级分析:使用webpack内置的stats stats:构建统计信息 package.json中使用stats "scripts": { "build:stats":"webpack --env production --json > stats.json" } 复制代码 指定输出的json对象,输出一个json文件 Node.js 中使用 const webpack = require('webpack') const config = require('./webpack.config.js')('production') webacpk(config, (err, stats) => { if(err) { return console.error(err); } if(stats.hasErrors()) { return console.log(stats.toString("errors-only")) } console.log(stats); }) 复制代码 缺点:颗粒度太粗,看不出问题所在。 速度分析:使用speed-measure-webpack-plugin const SpeedMeasureWebpackPlugin = require('speed-measure-webpack-plugin') const smp = new

Get all IDL attributes for an HTML Element

北慕城南 提交于 2021-01-29 17:21:44
问题 I know it's possible to get all content attributes on a a standard HTMLElement like this: <input type="text" value="John" /> const input = document.querySelector("input"); const attrs = Array.from(input.attributes); console.log(attrs.map(a => a.name + ': ' a.value)); // [ "type: text", "value: John" ] I'm working in a world (Salesforce Lightning Web Components) where IDL attributes (i.e. those you can access via dot notation) aren't always exposed as content attributes at runtime. For example

Create a user programatically using Firebase Auth emulator

纵饮孤独 提交于 2021-01-29 10:23:05
问题 I am trying to write jest tests using the Firebase Auth emulator and continue to receive the following CORS error. console.error Error: Headers X-Client-Version forbidden at dispatchError (/Users/me/my-project/node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:62:19) at validCORSPreflightHeaders (/Users/me/my-project/node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:99:5) at Request.<anonymous> (/Users/me/my-project/node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:367:12) at Request

unit test raises error because of .getContext() is not implemented

人盡茶涼 提交于 2021-01-20 18:59:47
问题 I am writing tests using Jest for components that use canvas elements. I keep getting an error when I run my tests that looks like this. Error: Not implemented: HTMLCanvasElement.prototype.getContext (without installing the canvas npm package) From my understanding Jest uses jsdom for its testing and that jsdom is compatible with canvas if you install the canvas or canvas-prebuilt packages. I have tried installing each of these packages and neither of them have resolved the error. The only

unit test raises error because of .getContext() is not implemented

梦想的初衷 提交于 2021-01-20 18:50:27
问题 I am writing tests using Jest for components that use canvas elements. I keep getting an error when I run my tests that looks like this. Error: Not implemented: HTMLCanvasElement.prototype.getContext (without installing the canvas npm package) From my understanding Jest uses jsdom for its testing and that jsdom is compatible with canvas if you install the canvas or canvas-prebuilt packages. I have tried installing each of these packages and neither of them have resolved the error. The only

npm install使用淘宝源报错

痴心易碎 提交于 2020-08-15 12:33:02
在node:12.18.2-buster容器里使用淘宝源npm install时一堆报错: npm install --registry= https://registry.npm.taobao.org npm WARN tarball tarball data for react-dev-utils@5.0.3 (sha512-d2FbKvYe4XAQx5gjHBoWG+ADqC3fGZzjb7i9vxd/Y5xfLkBGtQyX7aOb8lBRQPYUhjngiD3d49LevjY1stUR0Q==) seems to be corrupted. Trying one more time. npm WARN tarball tarball data for react-dev-utils@5.0.3 (sha512-d2FbKvYe4XAQx5gjHBoWG+ADqC3fGZzjb7i9vxd/Y5xfLkBGtQyX7aOb8lBRQPYUhjngiD3d49LevjY1stUR0Q==) seems to be corrupted. Trying one more time. npm WARN tar ENOENT: no such file or directory, open '/home/jenkins/agent/workspace/polling-app