Last active
September 6, 2017 20:46
-
-
Save nhunzaker/5fc6f3ea153319e3140275914773d5bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('Jest Electron Runner', function() { | |
it('has access to the window', function() { | |
expect(window).toEqual(global) | |
}) | |
it('has access to the document', function() { | |
expect(document).toEqual(global.document) | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const FakeTimers = require('jest-util').FakeTimers | |
const installCommonGlobals = require('jest-util').installCommonGlobals | |
const ModuleMocker = require('jest-mock') | |
class ElectronEnvironment { | |
constructor(config) { | |
const global = this.global = window | |
installCommonGlobals(global, config.globals) | |
this.moduleMocker = new ModuleMocker(global) | |
this.fakeTimers = new FakeTimers(global, this.moduleMocker, config) | |
} | |
dispose() { | |
if (this.fakeTimers) { | |
this.fakeTimers.dispose() | |
} | |
this.fakeTimers = null | |
} | |
runScript(script) { | |
return script.runInThisContext() | |
} | |
} | |
module.exports = ElectronEnvironment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const { app, BrowserWindow } = require('electron') | |
const qs = require('querystring') | |
const args = process.argv.slice(2) | |
const debug = args.indexOf('--debug') >= 0 | |
function run () { | |
let runner = new BrowserWindow({ | |
title: "Jest", | |
show: debug, | |
contextIsolation: true | |
}) | |
require('jest') | |
let options = { | |
moduleDirectories: ["<rootDir>/tests"], | |
env: './src/jest-environment-electron' | |
} | |
runner.loadURL(`file://${__dirname}/runner.html?` + qs.stringify(options)) | |
if (debug) { | |
runner.toggleDevTools() | |
} | |
runner.on('close', function () { | |
runner = null | |
}) | |
} | |
app.on('ready', run) | |
app.on('window-all-closed', function () { | |
app.quit() | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "jest-electron", | |
"version": "1.0.0", | |
"description": "Executing jest with Electron", | |
"main": "main.js", | |
"scripts": { | |
"test": "electron ." | |
}, | |
"keywords": ["jest", "electron"], | |
"author": "Nate Hunzaker <[email protected]", | |
"license": "MIT", | |
"dependencies": { | |
"jest": "^17.0.3", | |
"electron": "^1.4.1" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Jest</title> | |
</head> | |
<body> | |
<h2>Executing tests...</h2> | |
<p>Please reference the console for output.</p> | |
<script> | |
var jest = require('jest') | |
var qs = require('querystring') | |
var options = qs.parse(window.location.search) | |
jest.runCLI(options, __dirname, (content) => { | |
window.close() | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment