Skip to content

Instantly share code, notes, and snippets.

@ndugger
Created July 11, 2017 17:39
Show Gist options
  • Save ndugger/2d9853436e8d3bf40860686a6addf410 to your computer and use it in GitHub Desktop.
Save ndugger/2d9853436e8d3bf40860686a6addf410 to your computer and use it in GitHub Desktop.
import { execFileSync } from 'child_process';
import { JSDOM } from 'jsdom';
const { Promise } = global;
const options = { resources: 'usable', runScripts: 'dangerously' };
const server = execFileSync('node', [ './dist/server/index.js' ], { cwd: process.cwd() });
const browser = { };
beforeAll(async () => {
await new Promise(resolve => setTimeout(resolve, 2000));
const dom = await JSDOM.fromURL('http://localhost:8080', options);
const { window } = dom;
Object.assign(browser, { window });
await new Promise(resolve => window.addEventListener('load', resolve));
});
afterAll(() => {
server.kill();
});
describe('...', () => {
test('...', () => {
console.log(browser.window.document.body.outerHTML);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment