This repository has been archived by the owner on Mar 21, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 67
Renderer tests 2 #476
Merged
Merged
Renderer tests 2 #476
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
23f5cc5
Revert "Revert "Add framework for running electron-mocha tests and a …
jsantell 8d1ff9e
Use path module so windows does not attempt to run renderer tests wit…
jsantell 6ab41f9
Better description of error exit codes in spawning child processes.
jsantell 3fd0869
Separate out tests into webdriver, renderer, and unit, to avoid use
jsantell cfb3c4d
Wire up renderer tests to build system. CI tests working in Linux, OSX
jsantell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,92 @@ | ||
// Any copyright is dedicated to the Public Domain. | ||
// http://creativecommons.org/publicdomain/zero/1.0/ | ||
/* eslint no-console: 0 */ | ||
|
||
import childProcess from 'child_process'; | ||
import path from 'path'; | ||
import { spawn } from './utils'; | ||
import os from 'os'; | ||
import { spawn, getElectronPath, normalizeCommand } from './utils'; | ||
|
||
export default async function(args) { | ||
const command = path.join(__dirname, '..', 'node_modules', '.bin', 'mocha'); | ||
const DEFAULT_UNIT_TESTS = path.join(__dirname, '..', 'test', 'unit'); | ||
const DEFAULT_RENDERER_TESTS = path.join(__dirname, '..', 'test', 'renderer'); | ||
const DEFAULT_WEBDRIVER_TESTS = path.join(__dirname, '..', 'test', 'webdriver'); | ||
const MOCHA = path.join(__dirname, '..', 'node_modules', '.bin', 'mocha'); | ||
const ELECTRON_MOCHA = path.join(__dirname, '..', 'node_modules', '.bin', 'electron-mocha'); | ||
const PATH_TO_ELECTRON_MOCHA_OPTS = path.join(__dirname, '..', 'test', 'renderer', 'mocha.opts'); | ||
|
||
console.log(`Executing command: ${command}`); | ||
export default async function(args) { | ||
// If no arguments passed in, we must run all tests; both mocha | ||
// and electron-mocha. | ||
if (!args.length) { | ||
await runMochaTests(DEFAULT_UNIT_TESTS); | ||
await runRendererTests(DEFAULT_RENDERER_TESTS); | ||
await runMochaTests(DEFAULT_WEBDRIVER_TESTS); | ||
} else { | ||
// If we get a path passed in, crudely check if we should run | ||
// our renderer tests, or normal mocha tests. This will fail for complex | ||
// globbing, but this is more than fine for now. | ||
const pathToTests = args[0]; | ||
if (pathToTests.indexOf(path.join('test', 'renderer')) !== -1) { | ||
await runRendererTests(pathToTests); | ||
} else { | ||
await runMochaTests(pathToTests); | ||
} | ||
} | ||
} | ||
|
||
await spawn(command, args, { | ||
function runMochaTests(pathToTests) { | ||
return spawn(MOCHA, [pathToTests], { | ||
stdio: 'inherit', | ||
}); | ||
} | ||
|
||
async function runRendererTests(pathToTests) { | ||
const command = await normalizeCommand(ELECTRON_MOCHA); | ||
|
||
const child = childProcess.spawn(command, [ | ||
'--renderer', | ||
'--opts', PATH_TO_ELECTRON_MOCHA_OPTS, | ||
pathToTests, | ||
], { | ||
// Must pass in our whole environment to `electron-mocha`, as | ||
// that spawns another process which uses something in the current environment | ||
// (so `process.env`, or the `env` object we pass in here), otherwise the electron process | ||
// immediately crashes. | ||
env: Object.assign({}, process.env, { ELECTRON_PATH: getElectronPath() }), | ||
}); | ||
|
||
return new Promise((resolve, reject) => { | ||
let failedFromStdout = false; | ||
|
||
// Parse and pipe the stdout from electron-mocha | ||
// so we can observe if tests are passing, but we get an error | ||
// on shutdown, for the Windows edge case below. | ||
child.stdout.on('data', data => { | ||
if (/\s\d+ failing/.test(`${data}`.trim())) { | ||
failedFromStdout = true; | ||
} | ||
process.stdout.write(data); | ||
}); | ||
|
||
child.stderr.pipe(process.stderr); | ||
child.on('error', reject); | ||
child.on('exit', code => { | ||
if (code !== 0) { | ||
if (os.platform() === 'win32' && !failedFromStdout) { | ||
// If the exit code is not 0 and we didn't observe any | ||
// failure messages when running tests, we are running into | ||
// an issue where Electron crashes in electron-mocha when cleaning up | ||
// tests due to the main process firing a `webContents.send()` during clean up | ||
// resulting in a 'Object has been destroyed' error. Can't seem to figure out | ||
// why, but looks like a part of Electron, and burned enough time on this, | ||
// so this is good enough for now™. | ||
resolve(); | ||
} else { | ||
reject(new Error(`Child process ${command} exited with exit code ${code}`)); | ||
} | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--ui bdd | ||
--reporter spec | ||
--recursive | ||
--check-leaks | ||
--full-trace | ||
--timeout 10000 | ||
--require isomorphic-fetch | ||
--require ./lib/ui/browser/index.js | ||
--preload ./test/utils/renderer-setup.js |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Any copyright is dedicated to the Public Domain. | ||
// http://creativecommons.org/publicdomain/zero/1.0/ | ||
/* eslint prefer-arrow-callback: 0 */ | ||
/* eslint no-undef: 0 */ | ||
/* eslint-disable import/no-commonjs */ | ||
|
||
const expect = require('expect'); | ||
|
||
describe('renderer - sanity checks', function() { | ||
it('has access to expected globals', function() { | ||
expect(window).toExist(); | ||
expect(document).toExist(); | ||
|
||
// Get globals from the browser/index.jsx app | ||
expect(window.app).toExist(); | ||
expect(window.app.store).toExist(); | ||
|
||
// Gets helpers from renderer-setup.js | ||
expect($).toExist(); | ||
expect($$).toExist(); | ||
}); | ||
|
||
it('renders basic components', function() { | ||
expect($('#browser-container')).toExist(); | ||
expect($('#browser-location-title-bar').hasAttribute('hidden')).toBe(false); | ||
expect($$('#browser-tabbar .tab').length).toBe(1); | ||
expect($$('webview').length).toBeGreaterThan(0); | ||
}); | ||
}); |
File renamed without changes.
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Any copyright is dedicated to the Public Domain. | ||
// http://creativecommons.org/publicdomain/zero/1.0/ | ||
/* eslint-disable import/no-commonjs */ | ||
|
||
/** | ||
* This preload script gets injected via <script> in the renderer process | ||
* for use with tests. | ||
*/ | ||
|
||
window.$ = (selector, scope = document) => scope.querySelector(selector); | ||
window.$$ = (selector, scope = document) => scope.querySelectorAll(selector); | ||
|
||
// Create a container div that will render the entire app | ||
const container = document.createElement('div'); | ||
container.setAttribute('id', 'browser-container'); | ||
document.body.appendChild(container); | ||
|
||
// Require these so we can transpile the client code on the fly | ||
// require('babel-polyfill'); | ||
// require('babel-register')(); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing these and adding in a follow up -- was originally a source of failure, but things are working now and this will be the next step