Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { addTypenameToDocument } from 'apollo-utilities';
import { Router, Switch } from 'react-router-dom';
import { createMemoryHistory, MemoryHistory } from 'history';
import { JSDOM } from 'jsdom';
import { makeExecutableSchema, addMockFunctionsToSchema } from 'graphql-tools';
import { combineReducers, createStore, Store } from 'redux';
import { graphql, print, getOperationAST, DocumentNode, GraphQLSchema } from 'graphql';
import { Provider } from 'react-redux';
import { ApolloClient } from 'apollo-client';
import { render, RenderResult } from '@testing-library/react';
import { createApolloClient } from '@gqlapp/core-common';
import ClientModule from '@gqlapp/module-client-react';
if (!process.env.JEST_WORKER_ID) {
const dom = new JSDOM('<div id="root"><div>');
(global as any).document = dom.window.document;
(global as any).window = dom.window;
// Needed by Formik >= 1.x
(global as any).HTMLButtonElement = dom.window.HTMLButtonElement;
(global as any).navigator = dom.window.navigator;
process.on('uncaughtException', ex => {
console.error('Uncaught error', ex.stack);
});
}
const ref: { clientModules: ClientModule; typeDefs: DocumentNode[] } = { clientModules: null, typeDefs: null };
export const initRenderer = (graphqlTypeDefs: DocumentNode[], clientModules: ClientModule) => {
ref.clientModules = clientModules;
ref.typeDefs = graphqlTypeDefs;
};</div></div>
}
}
export function tryToReadFile(file) {
try {
return fs.readFileSync(file, 'utf-8');
} catch (err) {
if (err.code !== 'ENOENT') throw err;
return null;
}
}
const virtualConsole = new jsdom.VirtualConsole();
virtualConsole.sendTo(console);
const window = new jsdom.JSDOM('<main></main>', {virtualConsole}).window;
global.document = window.document;
global.navigator = window.navigator;
global.getComputedStyle = window.getComputedStyle;
global.requestAnimationFrame = null; // placeholder, filled in using set_raf
global.window = window;
// add missing ecmascript globals to window
for (const key of Object.getOwnPropertyNames(global)) {
window[key] = window[key] || global[key];
}
// implement mock scroll
window.scrollTo = function(pageXOffset, pageYOffset) {
window.pageXOffset = pageXOffset;
window.pageYOffset = pageYOffset;
};
function createDom({ url, content }) {
const dom = new JSDOM(content, { url });
// Force relative URL resolution
dom.window.document.body.setAttribute(null, null);
return dom;
}
// Set up chai and sinon
const chai = require('chai')
const sinon = require('sinon')
chai.use(require('chai-as-promised'))
chai.use(require('sinon-chai'))
chai.use(require('chai-enzyme')())
global.expect = chai.expect
global.sinon = sinon
// Set up jsdom
const jsdom = require('jsdom')
const document = new jsdom.JSDOM()
global.document = document
global.window = document.defaultView
global.navigator = { userAgent: 'node.js' }
// Hook for CSS Module imports enables using classes in tests
const hook = require('css-modules-require-hook')
const sass = require('node-sass')
hook({
extensions: ['.scss'],
generateScopedName: '[local]__[hash:base64:4]',
preprocessCss: (css, file) => sass.renderSync({ file }).css
})
// Load tests
socket.destroy();
}, 5000);
}
if (useBlacklist && blacklist[ip]) {
tracer.log("------------------------------> blacklist", ip);
setTimeout(function() {
tracer.log("blacklist: end");
socket.destroy();
}, 5000);
}
});
const createDOMPurify = require('dompurify');
const { JSDOM } = require('jsdom');
const window = (new JSDOM('', {
features: {
FetchExternalResources: false, // disables resource loading over HTTP / filesystem
ProcessExternalResources: false // do not execute JS within script blocks
}
})).window;
const DOMPurify = createDOMPurify(window);
const jsonpatch = require('fast-json-patch');
function bufferTag(str, sz) {
var buf = new Buffer(sz).fill(32);
buf.write(str);
return buf;
}
it('content in textarea', function () {
var html = '<textarea>Foo'
global.window = new jsdom.JSDOM(html).window
global.window.MathJax = { Hub: { Queue: sinon.fake() } }
texme.renderPage()
assert.strictEqual(global.window.document.body.innerHTML,
'<main><p>Foo</p>\n</main>')
delete global.window
})
</textarea>
it("must open a new window with the link provided by `getShareUrl`", (done) => {
const html = linkedInSharer.render("foo", "foo", "path/to/whatever");
const { window } = new JSDOM(html);
const event = new window.Event("click");
const openStub = stub(window, "open");
openStub.returns({});
const text = linkedInSharer.getText("foo");
const url = linkedInSharer.getShareUrl(text, "path/to/whatever");
linkedInSharer.action(event, window.document.body);
expect(openStub).to.have.been.calledWith(url, match.any, match.any);
done();
});
before(function(done) {
const dom = new JSDOM(`\
function setUpDomEnvironment() {
const dom = new JSDOM('', {url: 'http://localhost/'});
const { window } = dom;
global.window = window;
global.document = window.document;
global.navigator = {
userAgent: 'node.js',
};
copyProps(window, global);
}
const Enzyme = require('enzyme');
const Adapter = require('enzyme-adapter-react-16');
Enzyme.configure({ adapter: new Adapter() });
const { JSDOM } = require('jsdom');
const jsdom = new JSDOM('', {
url: 'https://example.com',
});
const { window } = jsdom;
function copyProps(src, target) {
const props = Object.getOwnPropertyNames(src)
.filter(prop => typeof target[prop] === 'undefined')
.map(prop => Object.getOwnPropertyDescriptor(src, prop));
Object.defineProperties(target, props);
}
global.window = window;
global.document = window.document;
global.navigator = {
userAgent: 'node.js',
};